test(service): enabled status get

This commit is contained in:
Houkime 2023-09-29 12:52:13 +00:00
parent 728ea44823
commit 92612906ef
2 changed files with 25 additions and 2 deletions

View file

@ -30,9 +30,10 @@ class DummyService(Service):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
status_file = self.status_file() with open(self.status_file(), "w") as file:
with open(status_file, "w") as file:
file.write(ServiceStatus.ACTIVE.value) file.write(ServiceStatus.ACTIVE.value)
with open(self.enabled_file(), "w") as file:
file.write("True")
@staticmethod @staticmethod
def get_id() -> str: def get_id() -> str:
@ -83,6 +84,26 @@ class DummyService(Service):
# we do not REALLY want to store our state in our declared folders # we do not REALLY want to store our state in our declared folders
return path.join(dir, "..", "service_status") return path.join(dir, "..", "service_status")
@classmethod
def enabled_file(cls) -> str:
dir = cls.folders[0]
return path.join(dir, "..", "service_enabled")
@classmethod
def get_enabled(cls) -> bool:
with open(cls.enabled_file(), "r") as file:
string = file.read().strip()
if "True" in string:
return True
if "False" in string:
return False
raise ValueError("test service enabled/disabled status file got corrupted")
@classmethod
def set_enabled(cls, enabled: bool):
with open(cls.enabled_file(), "w") as file:
status_string = file.write(str(enabled))
@classmethod @classmethod
def set_status(cls, status: ServiceStatus): def set_status(cls, status: ServiceStatus):
with open(cls.status_file(), "w") as file: with open(cls.status_file(), "w") as file:

View file

@ -57,6 +57,7 @@ API_SERVICES_QUERY = """
allServices { allServices {
id id
status status
isEnabled
} }
""" """
@ -108,6 +109,7 @@ def test_get_services(authorized_client, only_dummy_service):
api_dummy_service = services[0] api_dummy_service = services[0]
assert api_dummy_service["id"] == "testservice" assert api_dummy_service["id"] == "testservice"
assert api_dummy_service["status"] == ServiceStatus.ACTIVE.value assert api_dummy_service["status"] == ServiceStatus.ACTIVE.value
assert api_dummy_service["isEnabled"] is True
def test_stop_start(authorized_client, only_dummy_service): def test_stop_start(authorized_client, only_dummy_service):