From ffc60fc8b4863bf9704e7965311dd683fceb018e Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Wed, 22 Nov 2023 15:26:21 +0000 Subject: [PATCH] test(services): use actual json enabling and disabling --- .../services/test_service/__init__.py | 34 ------------------- tests/test_common.py | 5 ++- 2 files changed, 4 insertions(+), 35 deletions(-) diff --git a/selfprivacy_api/services/test_service/__init__.py b/selfprivacy_api/services/test_service/__init__.py index c75fc07..1e315f5 100644 --- a/selfprivacy_api/services/test_service/__init__.py +++ b/selfprivacy_api/services/test_service/__init__.py @@ -37,8 +37,6 @@ class DummyService(Service): super().__init__() with open(self.status_file(), "w") as file: file.write(ServiceStatus.ACTIVE.value) - with open(self.enabled_file(), "w") as file: - file.write("True") @staticmethod def get_id() -> str: @@ -79,36 +77,12 @@ class DummyService(Service): def get_backup_description() -> str: return "How did we get here?" - @classmethod - def is_enabled(cls) -> bool: - return cls.get_enabled() - @classmethod def status_file(cls) -> str: dir = cls.folders[0] # we do not REALLY want to store our state in our declared folders 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 def set_status(cls, status: ServiceStatus): with open(cls.status_file(), "w") as file: @@ -153,14 +127,6 @@ class DummyService(Service): """`True` if the service can be backed up.""" return cls.backuppable - @classmethod - def enable(cls): - cls.set_enabled(True) - - @classmethod - def disable(cls): - cls.set_enabled(False) - @classmethod def set_delay(cls, new_delay_sec: float) -> None: cls.startstop_delay = new_delay_sec diff --git a/tests/test_common.py b/tests/test_common.py index 5da43e9..5c433a0 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -48,7 +48,9 @@ def raw_dummy_service(tmpdir): @pytest.fixture() -def dummy_service(tmpdir, raw_dummy_service) -> Generator[Service, None, None]: +def dummy_service( + tmpdir, raw_dummy_service, generic_userdata +) -> Generator[Service, None, None]: service = raw_dummy_service # register our service @@ -58,6 +60,7 @@ def dummy_service(tmpdir, raw_dummy_service) -> Generator[Service, None, None]: assert huey.immediate is True assert get_service_by_id(service.get_id()) is not None + service.enable() yield service # cleanup because apparently it matters wrt tasks