mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-18 08:29:14 +00:00
test(service): moving errors
This commit is contained in:
parent
1e77129f4f
commit
9a3800ac7b
|
@ -247,6 +247,8 @@ class Service(ABC):
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def move_to_volume(self, volume: BlockDevice) -> Job:
|
def move_to_volume(self, volume: BlockDevice) -> Job:
|
||||||
|
"""Cannot raise errors.
|
||||||
|
Returns errors as an errored out Job instead."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -24,6 +24,7 @@ class DummyService(Service):
|
||||||
folders: List[str] = []
|
folders: List[str] = []
|
||||||
startstop_delay = 0.0
|
startstop_delay = 0.0
|
||||||
backuppable = True
|
backuppable = True
|
||||||
|
movable = True
|
||||||
|
|
||||||
def __init_subclass__(cls, folders: List[str]):
|
def __init_subclass__(cls, folders: List[str]):
|
||||||
cls.folders = folders
|
cls.folders = folders
|
||||||
|
@ -62,9 +63,9 @@ class DummyService(Service):
|
||||||
domain = "test.com"
|
domain = "test.com"
|
||||||
return f"https://password.{domain}"
|
return f"https://password.{domain}"
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def is_movable() -> bool:
|
def is_movable(cls) -> bool:
|
||||||
return True
|
return cls.movable
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_required() -> bool:
|
def is_required() -> bool:
|
||||||
|
@ -137,6 +138,12 @@ class DummyService(Service):
|
||||||
we can only set it up dynamically for tests via a classmethod"""
|
we can only set it up dynamically for tests via a classmethod"""
|
||||||
cls.backuppable = new_value
|
cls.backuppable = new_value
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def set_movable(cls, new_value: bool) -> None:
|
||||||
|
"""For tests: because is_movale is static,
|
||||||
|
we can only set it up dynamically for tests via a classmethod"""
|
||||||
|
cls.movable = new_value
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def can_be_backed_up(cls) -> bool:
|
def can_be_backed_up(cls) -> bool:
|
||||||
"""`True` if the service can be backed up."""
|
"""`True` if the service can be backed up."""
|
||||||
|
|
|
@ -110,6 +110,26 @@ allServices {
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
API_MOVE_MUTATION = """
|
||||||
|
mutation TestMoveService($input: MoveServiceInput!) {
|
||||||
|
services {
|
||||||
|
moveService(input: $input) {
|
||||||
|
success
|
||||||
|
message
|
||||||
|
code
|
||||||
|
job {
|
||||||
|
uid
|
||||||
|
status
|
||||||
|
}
|
||||||
|
service {
|
||||||
|
id
|
||||||
|
status
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
def assert_notfound(data):
|
def assert_notfound(data):
|
||||||
assert_errorcode(data, 404)
|
assert_errorcode(data, 404)
|
||||||
|
@ -166,6 +186,26 @@ def api_start_by_name(client, service_id: str) -> dict:
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
def api_move(client, service: Service, location: str) -> dict:
|
||||||
|
return api_move_by_name(client, service.get_id(), location)
|
||||||
|
|
||||||
|
|
||||||
|
def api_move_by_name(client, service_id: str, location: str) -> dict:
|
||||||
|
response = client.post(
|
||||||
|
"/graphql",
|
||||||
|
json={
|
||||||
|
"query": API_MOVE_MUTATION,
|
||||||
|
"variables": {
|
||||||
|
"input": {
|
||||||
|
"serviceId": service_id,
|
||||||
|
"location": location,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
def api_restart(client, service: Service) -> dict:
|
def api_restart(client, service: Service) -> dict:
|
||||||
return api_restart_by_name(client, service.get_id())
|
return api_restart_by_name(client, service.get_id())
|
||||||
|
|
||||||
|
@ -327,6 +367,16 @@ def test_disable_unauthorized(client, only_dummy_service):
|
||||||
assert mutation_response.json().get("data") is None
|
assert mutation_response.json().get("data") is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_move_nonexistent(authorized_client, only_dummy_service):
|
||||||
|
dummy_service = only_dummy_service
|
||||||
|
mutation_response = api_move_by_name(authorized_client, "bogus_service", "sda1")
|
||||||
|
data = get_data(mutation_response)["services"]["moveService"]
|
||||||
|
assert_notfound(data)
|
||||||
|
|
||||||
|
assert data["service"] is None
|
||||||
|
assert data["job"] is None
|
||||||
|
|
||||||
|
|
||||||
def test_start_nonexistent(authorized_client, only_dummy_service):
|
def test_start_nonexistent(authorized_client, only_dummy_service):
|
||||||
dummy_service = only_dummy_service
|
dummy_service = only_dummy_service
|
||||||
mutation_response = api_start_by_name(authorized_client, "bogus_service")
|
mutation_response = api_start_by_name(authorized_client, "bogus_service")
|
||||||
|
@ -395,3 +445,26 @@ def test_stop_start(authorized_client, only_dummy_service):
|
||||||
api_start(authorized_client, dummy_service)
|
api_start(authorized_client, dummy_service)
|
||||||
api_dummy_service = api_all_services(authorized_client)[0]
|
api_dummy_service = api_all_services(authorized_client)[0]
|
||||||
assert api_dummy_service["status"] == ServiceStatus.ACTIVE.value
|
assert api_dummy_service["status"] == ServiceStatus.ACTIVE.value
|
||||||
|
|
||||||
|
|
||||||
|
def test_move_immovable(authorized_client, only_dummy_service):
|
||||||
|
dummy_service = only_dummy_service
|
||||||
|
dummy_service.set_movable(False)
|
||||||
|
mutation_response = api_move(authorized_client, dummy_service, "sda1")
|
||||||
|
data = get_data(mutation_response)["services"]["moveService"]
|
||||||
|
assert_errorcode(data, 400)
|
||||||
|
|
||||||
|
# is there a meaning in returning the service in this?
|
||||||
|
assert data["service"] is not None
|
||||||
|
assert data["job"] is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_move_no_such_volume(authorized_client, only_dummy_service):
|
||||||
|
dummy_service = only_dummy_service
|
||||||
|
mutation_response = api_move(authorized_client, dummy_service, "bogus_volume")
|
||||||
|
data = get_data(mutation_response)["services"]["moveService"]
|
||||||
|
assert_notfound(data)
|
||||||
|
|
||||||
|
# is there a meaning in returning the service in this?
|
||||||
|
assert data["service"] is not None
|
||||||
|
assert data["job"] is None
|
||||||
|
|
Loading…
Reference in a new issue