test(service): enable-disable return values

This commit is contained in:
Houkime 2023-09-29 15:27:34 +00:00
parent bd43bdb335
commit b9f3aa49bd
2 changed files with 87 additions and 6 deletions

View file

@ -74,9 +74,9 @@ 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?"
@staticmethod @classmethod
def is_enabled() -> bool: def is_enabled(cls) -> bool:
return True return cls.get_enabled()
@classmethod @classmethod
def status_file(cls) -> str: def status_file(cls) -> str:
@ -144,11 +144,11 @@ class DummyService(Service):
@classmethod @classmethod
def enable(cls): def enable(cls):
pass cls.set_enabled(True)
@classmethod @classmethod
def disable(cls, delay): def disable(cls):
pass cls.set_enabled(False)
@classmethod @classmethod
def set_delay(cls, new_delay): def set_delay(cls, new_delay):

View file

@ -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 = """ API_STOP_MUTATION = """
mutation TestStopService($service_id: String!) { mutation TestStopService($service_id: String!) {
services { 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: def api_start(client, service: Service) -> dict:
return api_start_by_name(client, service.get_id()) 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 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): def test_start_return_value(authorized_client, only_dummy_service):
dummy_service = only_dummy_service dummy_service = only_dummy_service
mutation_response = api_start(authorized_client, dummy_service) mutation_response = api_start(authorized_client, dummy_service)