test(service): moving errors

This commit is contained in:
Houkime 2023-10-06 13:17:48 +00:00
parent 1e77129f4f
commit 9a3800ac7b
3 changed files with 85 additions and 3 deletions

View file

@ -247,6 +247,8 @@ class Service(ABC):
@abstractmethod
def move_to_volume(self, volume: BlockDevice) -> Job:
"""Cannot raise errors.
Returns errors as an errored out Job instead."""
pass
@classmethod

View file

@ -24,6 +24,7 @@ class DummyService(Service):
folders: List[str] = []
startstop_delay = 0.0
backuppable = True
movable = True
def __init_subclass__(cls, folders: List[str]):
cls.folders = folders
@ -62,9 +63,9 @@ class DummyService(Service):
domain = "test.com"
return f"https://password.{domain}"
@staticmethod
def is_movable() -> bool:
return True
@classmethod
def is_movable(cls) -> bool:
return cls.movable
@staticmethod
def is_required() -> bool:
@ -137,6 +138,12 @@ class DummyService(Service):
we can only set it up dynamically for tests via a classmethod"""
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
def can_be_backed_up(cls) -> bool:
"""`True` if the service can be backed up."""

View file

@ -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):
assert_errorcode(data, 404)
@ -166,6 +186,26 @@ def api_start_by_name(client, service_id: str) -> dict:
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:
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
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):
dummy_service = only_dummy_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_dummy_service = api_all_services(authorized_client)[0]
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