mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-17 16:09:14 +00:00
test(services): use actual json enabling and disabling
This commit is contained in:
parent
5c1dd93931
commit
ffc60fc8b4
|
@ -37,8 +37,6 @@ class DummyService(Service):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
with open(self.status_file(), "w") as file:
|
with open(self.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:
|
||||||
|
@ -79,36 +77,12 @@ class DummyService(Service):
|
||||||
def get_backup_description() -> str:
|
def get_backup_description() -> str:
|
||||||
return "How did we get here?"
|
return "How did we get here?"
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def is_enabled(cls) -> bool:
|
|
||||||
return cls.get_enabled()
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def status_file(cls) -> str:
|
def status_file(cls) -> str:
|
||||||
dir = cls.folders[0]
|
dir = cls.folders[0]
|
||||||
# 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:
|
||||||
|
@ -153,14 +127,6 @@ class DummyService(Service):
|
||||||
"""`True` if the service can be backed up."""
|
"""`True` if the service can be backed up."""
|
||||||
return cls.backuppable
|
return cls.backuppable
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def enable(cls):
|
|
||||||
cls.set_enabled(True)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def disable(cls):
|
|
||||||
cls.set_enabled(False)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def set_delay(cls, new_delay_sec: float) -> None:
|
def set_delay(cls, new_delay_sec: float) -> None:
|
||||||
cls.startstop_delay = new_delay_sec
|
cls.startstop_delay = new_delay_sec
|
||||||
|
|
|
@ -48,7 +48,9 @@ def raw_dummy_service(tmpdir):
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@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
|
service = raw_dummy_service
|
||||||
|
|
||||||
# register our 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 huey.immediate is True
|
||||||
|
|
||||||
assert get_service_by_id(service.get_id()) is not None
|
assert get_service_by_id(service.get_id()) is not None
|
||||||
|
service.enable()
|
||||||
yield service
|
yield service
|
||||||
|
|
||||||
# cleanup because apparently it matters wrt tasks
|
# cleanup because apparently it matters wrt tasks
|
||||||
|
|
Loading…
Reference in a new issue