From b9f3aa49bd8a68406b6db8bc26f31fed6748e488 Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Fri, 29 Sep 2023 15:27:34 +0000 Subject: [PATCH] test(service): enable-disable return values --- .../services/test_service/__init__.py | 12 +-- tests/test_graphql/test_services.py | 81 +++++++++++++++++++ 2 files changed, 87 insertions(+), 6 deletions(-) diff --git a/selfprivacy_api/services/test_service/__init__.py b/selfprivacy_api/services/test_service/__init__.py index 3baf193..60aea3b 100644 --- a/selfprivacy_api/services/test_service/__init__.py +++ b/selfprivacy_api/services/test_service/__init__.py @@ -74,9 +74,9 @@ class DummyService(Service): def get_backup_description() -> str: return "How did we get here?" - @staticmethod - def is_enabled() -> bool: - return True + @classmethod + def is_enabled(cls) -> bool: + return cls.get_enabled() @classmethod def status_file(cls) -> str: @@ -144,11 +144,11 @@ class DummyService(Service): @classmethod def enable(cls): - pass + cls.set_enabled(True) @classmethod - def disable(cls, delay): - pass + def disable(cls): + cls.set_enabled(False) @classmethod def set_delay(cls, new_delay): diff --git a/tests/test_graphql/test_services.py b/tests/test_graphql/test_services.py index c9b909b..bc9eab0 100644 --- a/tests/test_graphql/test_services.py +++ b/tests/test_graphql/test_services.py @@ -37,6 +37,37 @@ mutation TestStartService($service_id: String!) { } """ +API_ENABLE_MUTATION = """ +mutation TestStartService($service_id: String!) { + services { + enableService(serviceId: $service_id) { + success + message + code + service { + id + isEnabled + } + } + } +} +""" +API_DISABLE_MUTATION = """ +mutation TestStartService($service_id: String!) { + services { + disableService(serviceId: $service_id) { + success + message + code + service { + id + isEnabled + } + } + } +} +""" + API_STOP_MUTATION = """ mutation TestStopService($service_id: String!) { services { @@ -62,6 +93,36 @@ allServices { """ +def api_enable(client, service: Service) -> dict: + return api_enable_by_name(client, service.get_id()) + + +def api_enable_by_name(client, service_id: str) -> dict: + response = client.post( + "/graphql", + json={ + "query": API_ENABLE_MUTATION, + "variables": {"service_id": service_id}, + }, + ) + return response + + +def api_disable(client, service: Service) -> dict: + return api_disable_by_name(client, service.get_id()) + + +def api_disable_by_name(client, service_id: str) -> dict: + response = client.post( + "/graphql", + json={ + "query": API_DISABLE_MUTATION, + "variables": {"service_id": service_id}, + }, + ) + return response + + def api_start(client, service: Service) -> dict: return api_start_by_name(client, service.get_id()) @@ -120,6 +181,26 @@ def test_get_services(authorized_client, only_dummy_service): assert api_dummy_service["isEnabled"] is True +def test_enable_return_value(authorized_client, only_dummy_service): + dummy_service = only_dummy_service + mutation_response = api_enable(authorized_client, dummy_service) + data = get_data(mutation_response)["services"]["enableService"] + assert_ok(data) + service = data["service"] + assert service["id"] == dummy_service.get_id() + assert service["isEnabled"] == True + + +def test_disable_return_value(authorized_client, only_dummy_service): + dummy_service = only_dummy_service + mutation_response = api_disable(authorized_client, dummy_service) + data = get_data(mutation_response)["services"]["disableService"] + assert_ok(data) + service = data["service"] + assert service["id"] == dummy_service.get_id() + assert service["isEnabled"] == False + + def test_start_return_value(authorized_client, only_dummy_service): dummy_service = only_dummy_service mutation_response = api_start(authorized_client, dummy_service)