mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-25 13:31:27 +00:00
test(service): enable-disable return values
This commit is contained in:
parent
bd43bdb335
commit
b9f3aa49bd
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue