mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-01-23 17:26:46 +00:00
test(services): missing info on service enabled status returns False
This commit is contained in:
parent
bcf57ea738
commit
9d3fd45c2c
|
@ -128,7 +128,12 @@ class Service(ABC):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def is_enabled(cls) -> bool:
|
def is_enabled(cls) -> bool:
|
||||||
"""`True` if the service is enabled."""
|
"""
|
||||||
|
`True` if the service is enabled.
|
||||||
|
`False` if it is not enabled or not defined in file
|
||||||
|
If there is nothing in the file, this is equivalent to False
|
||||||
|
because NixOS won't enable it then.
|
||||||
|
"""
|
||||||
name = cls.get_id()
|
name = cls.get_id()
|
||||||
with ReadUserData() as user_data:
|
with ReadUserData() as user_data:
|
||||||
return user_data.get(name, {}).get("enable", False)
|
return user_data.get(name, {}).get("enable", False)
|
||||||
|
|
|
@ -557,6 +557,25 @@ def possibly_dubiously_enabled_service(
|
||||||
return dummy_service
|
return dummy_service
|
||||||
|
|
||||||
|
|
||||||
|
# Yeah, idk yet how to dry it.
|
||||||
|
@pytest.fixture(params=["deleted_attribute", "service_not_in_json"])
|
||||||
|
def undefined_enabledness_service(dummy_service: DummyService, request) -> DummyService:
|
||||||
|
if request.param == "deleted_attribute":
|
||||||
|
with WriteUserData() as data:
|
||||||
|
del data[dummy_service.get_id()]["enable"]
|
||||||
|
if request.param == "service_not_in_json":
|
||||||
|
with WriteUserData() as data:
|
||||||
|
del data[dummy_service.get_id()]
|
||||||
|
return dummy_service
|
||||||
|
|
||||||
|
|
||||||
|
def test_undefined_enabledness_in_json_means_False(
|
||||||
|
undefined_enabledness_service: DummyService,
|
||||||
|
):
|
||||||
|
dummy_service = undefined_enabledness_service
|
||||||
|
assert dummy_service.is_enabled() is False
|
||||||
|
|
||||||
|
|
||||||
def test_enabling_disabling_writes_json(
|
def test_enabling_disabling_writes_json(
|
||||||
possibly_dubiously_enabled_service: DummyService,
|
possibly_dubiously_enabled_service: DummyService,
|
||||||
):
|
):
|
||||||
|
|
Loading…
Reference in a new issue