selfprivacy-rest-api/tests/test_graphql/test_api_storage.py

107 lines
2.5 KiB
Python
Raw Normal View History

2022-08-26 03:07:55 +00:00
import pytest
2022-08-25 15:37:32 +00:00
2022-08-26 03:07:55 +00:00
class BlockDevicesMockReturnNone:
2022-08-25 15:37:32 +00:00
"""Mock BlockDevices"""
def __init__(self, args, **kwargs):
self.args = args
self.kwargs = kwargs
2022-08-26 03:07:55 +00:00
def get_block_device(self, name: str):
2022-08-25 15:37:32 +00:00
return None
2022-08-26 03:07:55 +00:00
def resize(self):
pass
returncode = 0
class BlockDevicesMock:
"""Mock BlockDevices"""
def __init__(self, args, **kwargs):
self.args = args
self.kwargs = kwargs
def get_block_device(self, name: str):
return 0
def resize(self):
pass
2022-08-25 15:37:32 +00:00
returncode = 0
2022-08-26 03:07:55 +00:00
@pytest.fixture
def mock_block_device_return_none(mocker):
mock = mocker.patch(
"selfprivacy_api.graphql.mutations.storage_mutation.BlockDevices", autospec=True
)
return mock
@pytest.fixture
def mock_block_device_return(mocker):
mock = mocker.patch(
"selfprivacy_api.graphql.mutations.storage_mutation.BlockDevices", autospec=True
)
2022-08-25 15:37:32 +00:00
return mock
API_RESIZE_VOLUME_MUTATION = """
2022-08-26 03:07:55 +00:00
mutation resizeVolume($name: String!) {
2022-08-25 15:37:32 +00:00
resizeVolume(name: $name) {
success
message
code
}
}
"""
2022-08-26 03:07:55 +00:00
def test_graphql_resize_volumea_unathorized_client(client, mock_block_device):
response = client.post(
"/graphql",
json={
"query": API_RESIZE_VOLUME_MUTATION,
"variables": {"name": "sdx"},
},
)
assert response.status_code == 200
assert response.json().get("data") is None
def test_graphql_resize_volume_nonexistent_block_device(
authorized_client, mock_block_device
):
2022-08-25 15:37:32 +00:00
response = authorized_client.post(
"/graphql",
json={
"query": API_RESIZE_VOLUME_MUTATION,
2022-08-26 03:07:55 +00:00
"variables": {"name": "sdx"},
2022-08-25 15:37:32 +00:00
},
)
assert response.status_code == 200
assert response.json().get("data") is not None
2022-08-25 15:41:31 +00:00
assert response.json()["data"]["resizeVolume"]["code"] == 404
assert response.json()["data"]["resizeVolume"]["message"] is not None
assert response.json()["data"]["resizeVolume"]["success"] is False
2022-08-26 03:07:55 +00:00
def test_graphql_resize_volume(authorized_client, mock_block_device):
response = authorized_client.post(
"/graphql",
json={
"query": API_RESIZE_VOLUME_MUTATION,
"variables": {"name": "sdx"},
},
)
assert response.status_code == 200
assert response.json().get("data") is not None
assert response.json()["data"]["resizeVolume"]["code"] == 200
assert response.json()["data"]["resizeVolume"]["message"] is not None
assert response.json()["data"]["resizeVolume"]["success"] is True