selfprivacy-rest-api/tests/test_system.py

42 lines
1.3 KiB
Python
Raw Normal View History

2023-12-29 13:12:32 +00:00
import pytest
2024-08-28 15:18:10 +00:00
from selfprivacy_api.utils import ReadUserData, UserDataFiles
2023-12-29 13:12:32 +00:00
from selfprivacy_api.actions.system import run_blocking, ShellException
2024-08-28 15:18:10 +00:00
from selfprivacy_api.actions.system import set_dns_provider
from selfprivacy_api.graphql.queries.providers import DnsProvider
2023-12-29 13:12:32 +00:00
2024-08-28 16:29:26 +00:00
def assert_provider(provider_str: str, key: str):
with ReadUserData() as user_data:
assert user_data["dns"]["provider"] == provider_str
with ReadUserData(file_type=UserDataFiles.SECRETS) as secrets:
assert secrets["dns"]["apiKey"] == key
2024-08-28 15:18:10 +00:00
def test_set_dns(generic_userdata):
token = "testytesty"
provider = DnsProvider.DESEC
set_dns_provider(provider, token)
2023-12-29 13:12:32 +00:00
2024-08-28 16:29:26 +00:00
assert_provider(provider.value, token)
2024-08-28 15:18:10 +00:00
# uname is just an arbitrary command expected to be everywhere we care
2023-12-29 13:12:32 +00:00
def test_uname():
output = run_blocking(["uname"])
assert output is not None
def test_uname_new_session():
output = run_blocking(["uname"], new_session=True)
assert output is not None
def test_uname_nonexistent_args():
with pytest.raises(ShellException) as exception_info:
# uname: extra operand sldfkjsljf
# Try 'uname --help' for more information
run_blocking(["uname", "isdyfhishfaisljhkeysmash"], new_session=True)
assert "extra operand" in exception_info.value.args[0]