add more tests

def_tests
def 2022-08-27 17:10:36 +02:00
parent 6b557d8e63
commit da92d6f835
1 changed files with 197 additions and 4 deletions

View File

@ -27,6 +27,33 @@ class BlockDevicesMock:
def get_block_device(self, name: str):
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):
pass
@ -42,7 +69,15 @@ def mock_block_device_return_none(mocker):
@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(
"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(
"/graphql",
json={
@ -73,7 +108,7 @@ def test_graphql_resize_volumea_unathorized_client(client, mock_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(
"/graphql",
@ -90,7 +125,7 @@ def test_graphql_resize_volume_nonexistent_block_device(
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(
"/graphql",
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"]["message"] is not None
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