mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-12-01 19:06:45 +00:00
add more tests
This commit is contained in:
parent
6b557d8e63
commit
da92d6f835
|
@ -27,6 +27,33 @@ class BlockDevicesMock:
|
||||||
def get_block_device(self, name: str):
|
def get_block_device(self, name: str):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
def mount(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def unmount(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def resize(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
returncode = 0
|
||||||
|
|
||||||
|
class BlockDevicesMockReturnFalse:
|
||||||
|
"""Mock BlockDevices"""
|
||||||
|
|
||||||
|
def __init__(self, args, **kwargs):
|
||||||
|
self.args = args
|
||||||
|
self.kwargs = kwargs
|
||||||
|
|
||||||
|
def get_block_device(self, name: str):
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def mount(self):
|
||||||
|
return False
|
||||||
|
|
||||||
|
def unmount(self):
|
||||||
|
return False
|
||||||
|
|
||||||
def resize(self):
|
def resize(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -42,7 +69,15 @@ def mock_block_device_return_none(mocker):
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_block_device_return(mocker):
|
def mock_block_device_return_true(mocker):
|
||||||
|
mock = mocker.patch(
|
||||||
|
"selfprivacy_api.graphql.mutations.storage_mutation.BlockDevices", autospec=True
|
||||||
|
)
|
||||||
|
return mock
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def mock_block_device_return_false(mocker):
|
||||||
mock = mocker.patch(
|
mock = mocker.patch(
|
||||||
"selfprivacy_api.graphql.mutations.storage_mutation.BlockDevices", autospec=True
|
"selfprivacy_api.graphql.mutations.storage_mutation.BlockDevices", autospec=True
|
||||||
)
|
)
|
||||||
|
@ -60,7 +95,7 @@ mutation resizeVolume($name: String!) {
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_resize_volumea_unathorized_client(client, mock_block_device):
|
def test_graphql_resize_volumea_unathorized_client(client, mock_block_device_return_true):
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
|
@ -73,7 +108,7 @@ def test_graphql_resize_volumea_unathorized_client(client, mock_block_device):
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_resize_volume_nonexistent_block_device(
|
def test_graphql_resize_volume_nonexistent_block_device(
|
||||||
authorized_client, mock_block_device
|
authorized_client, mock_block_device_return_none
|
||||||
):
|
):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
|
@ -90,7 +125,7 @@ def test_graphql_resize_volume_nonexistent_block_device(
|
||||||
assert response.json()["data"]["resizeVolume"]["success"] is False
|
assert response.json()["data"]["resizeVolume"]["success"] is False
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_resize_volume(authorized_client, mock_block_device):
|
def test_graphql_resize_volume(authorized_client, mock_block_device_return_true):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
|
@ -104,3 +139,161 @@ def test_graphql_resize_volume(authorized_client, mock_block_device):
|
||||||
assert response.json()["data"]["resizeVolume"]["code"] == 200
|
assert response.json()["data"]["resizeVolume"]["code"] == 200
|
||||||
assert response.json()["data"]["resizeVolume"]["message"] is not None
|
assert response.json()["data"]["resizeVolume"]["message"] is not None
|
||||||
assert response.json()["data"]["resizeVolume"]["success"] is True
|
assert response.json()["data"]["resizeVolume"]["success"] is True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
API_MOUNT_VOLUME_MUTATION = """
|
||||||
|
mutation mountVolume($name: String!) {
|
||||||
|
mountVolume(name: $name) {
|
||||||
|
success
|
||||||
|
message
|
||||||
|
code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def test_graphql_mount_volume_unathorized_client(client, mock_block_device_return_true):
|
||||||
|
response = client.post(
|
||||||
|
"/graphql",
|
||||||
|
json={
|
||||||
|
"query": API_MOUNT_VOLUME_MUTATION,
|
||||||
|
"variables": {"name": "sdx"},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json().get("data") is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_graphql_mount_already_mounted_volume(
|
||||||
|
authorized_client, mock_block_device_return_false
|
||||||
|
):
|
||||||
|
response = authorized_client.post(
|
||||||
|
"/graphql",
|
||||||
|
json={
|
||||||
|
"query": API_MOUNT_VOLUME_MUTATION,
|
||||||
|
"variables": {"name": "sdx"},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json().get("data") is not None
|
||||||
|
|
||||||
|
assert response.json()["data"]["mountVolume"]["code"] == 409
|
||||||
|
assert response.json()["data"]["mountVolume"]["message"] is not None
|
||||||
|
assert response.json()["data"]["mountVolume"]["success"] is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_graphql_mount_not_found_volume(
|
||||||
|
authorized_client, mock_block_device_return_none
|
||||||
|
):
|
||||||
|
response = authorized_client.post(
|
||||||
|
"/graphql",
|
||||||
|
json={
|
||||||
|
"query": API_MOUNT_VOLUME_MUTATION,
|
||||||
|
"variables": {"name": "sdx"},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json().get("data") is not None
|
||||||
|
|
||||||
|
assert response.json()["data"]["mountVolume"]["code"] == 409
|
||||||
|
assert response.json()["data"]["mountVolume"]["message"] is not None
|
||||||
|
assert response.json()["data"]["mountVolume"]["success"] is False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def test_graphql_mount_volume(
|
||||||
|
authorized_client, mock_block_device_return_true
|
||||||
|
):
|
||||||
|
response = authorized_client.post(
|
||||||
|
"/graphql",
|
||||||
|
json={
|
||||||
|
"query": API_MOUNT_VOLUME_MUTATION,
|
||||||
|
"variables": {"name": "sdx"},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json().get("data") is not None
|
||||||
|
|
||||||
|
assert response.json()["data"]["mountVolume"]["code"] == 200
|
||||||
|
assert response.json()["data"]["mountVolume"]["message"] is not None
|
||||||
|
assert response.json()["data"]["mountVolume"]["success"] is True
|
||||||
|
|
||||||
|
|
||||||
|
API_UNMOUNT_VOLUME_MUTATION = """
|
||||||
|
mutation unmountVolume($name: String!) {
|
||||||
|
unmountVolume(name: $name) {
|
||||||
|
success
|
||||||
|
message
|
||||||
|
code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def test_graphql_unmount_volume_unathorized_client(client, mock_block_device_return_true):
|
||||||
|
response = client.post(
|
||||||
|
"/graphql",
|
||||||
|
json={
|
||||||
|
"query": API_UNMOUNT_VOLUME_MUTATION,
|
||||||
|
"variables": {"name": "sdx"},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json().get("data") is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_graphql_unmount_not_fount_volume(
|
||||||
|
authorized_client, mock_block_device_return_none
|
||||||
|
):
|
||||||
|
response = authorized_client.post(
|
||||||
|
"/graphql",
|
||||||
|
json={
|
||||||
|
"query": API_UNMOUNT_VOLUME_MUTATION,
|
||||||
|
"variables": {"name": "sdx"},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json().get("data") is not None
|
||||||
|
|
||||||
|
assert response.json()["data"]["unmountVolume"]["code"] == 404
|
||||||
|
assert response.json()["data"]["unmountVolume"]["message"] is not None
|
||||||
|
assert response.json()["data"]["unmountVolume"]["success"] is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_graphql_unmount_volume_false(
|
||||||
|
authorized_client, mock_block_device_return_false
|
||||||
|
):
|
||||||
|
response = authorized_client.post(
|
||||||
|
"/graphql",
|
||||||
|
json={
|
||||||
|
"query": API_UNMOUNT_VOLUME_MUTATION,
|
||||||
|
"variables": {"name": "sdx"},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json().get("data") is not None
|
||||||
|
|
||||||
|
assert response.json()["data"]["unmountVolume"]["code"] == 409
|
||||||
|
assert response.json()["data"]["unmountVolume"]["message"] is not None
|
||||||
|
assert response.json()["data"]["unmountVolume"]["success"] is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_graphql_unmount_volume(
|
||||||
|
authorized_client, mock_block_device_return_true
|
||||||
|
):
|
||||||
|
response = authorized_client.post(
|
||||||
|
"/graphql",
|
||||||
|
json={
|
||||||
|
"query": API_UNMOUNT_VOLUME_MUTATION,
|
||||||
|
"variables": {"name": "sdx"},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json().get("data") is not None
|
||||||
|
|
||||||
|
assert response.json()["data"]["unmountVolume"]["code"] == 200
|
||||||
|
assert response.json()["data"]["unmountVolume"]["message"] is not None
|
||||||
|
assert response.json()["data"]["unmountVolume"]["success"] is True
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue