From 13368dcfe3193acd83de8e84d32335441f6d8fc7 Mon Sep 17 00:00:00 2001 From: def Date: Tue, 30 Aug 2022 02:45:50 +0200 Subject: [PATCH] update storage tests --- tests/test_graphql/test_api_storage.py | 46 ++++++++++++-------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/tests/test_graphql/test_api_storage.py b/tests/test_graphql/test_api_storage.py index 25730640..10d3027f 100644 --- a/tests/test_graphql/test_api_storage.py +++ b/tests/test_graphql/test_api_storage.py @@ -1,28 +1,26 @@ import pytest -class BlockDevicesMockReturnNone: +class BlockDeviceMockReturnNone: """Mock BlockDevices""" def __init__(self, args, **kwargs): self.args = args self.kwargs = kwargs - def get_block_device(self, name: str): - return None - def resize(self): pass returncode = 0 -class BlockDevicesMockReturnTrue: +class BlockDeviceMockReturnTrue: """Mock BlockDevices""" def __init__(self, args, **kwargs): self.args = args self.kwargs = kwargs + self.name = "sdx" def mount(self): return True @@ -35,16 +33,14 @@ class BlockDevicesMockReturnTrue: returncode = 0 -class BlockDevicesMockReturnFalse: + +class BlockDeviceMockReturnFalse: """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 @@ -60,7 +56,9 @@ class BlockDevicesMockReturnFalse: @pytest.fixture def mock_block_device_return_none(mocker): mock = mocker.patch( - "selfprivacy_api.graphql.mutations.storage_mutation.BlockDevices", autospec=True, return_value=BlockDevicesMockReturnNone + "selfprivacy_api.utils.block_devices.BlockDevice", + autospec=True, + return_value=BlockDeviceMockReturnNone, ) return mock @@ -68,7 +66,9 @@ def mock_block_device_return_none(mocker): @pytest.fixture def mock_block_device_return_true(mocker): mock = mocker.patch( - "selfprivacy_api.graphql.mutations.storage_mutation.BlockDevices", autospec=True, return_value=BlockDevicesMockReturnTrue + "selfprivacy_api.utils.block_devices.BlockDevice", + autospec=True, + return_value=BlockDeviceMockReturnTrue, ) return mock @@ -76,7 +76,9 @@ def mock_block_device_return_true(mocker): @pytest.fixture def mock_block_device_return_false(mocker): mock = mocker.patch( - "selfprivacy_api.graphql.mutations.storage_mutation.BlockDevices", autospec=True, return_value=BlockDevicesMockReturnFalse + "selfprivacy_api.utils.block_devices.BlockDevice", + autospec=True, + return_value=BlockDeviceMockReturnFalse, ) return mock @@ -92,7 +94,9 @@ mutation resizeVolume($name: String!) { """ -def test_graphql_resize_volumea_unathorized_client(client, mock_block_device_return_true): +def test_graphql_resize_volumea_unathorized_client( + client, mock_block_device_return_true +): response = client.post( "/graphql", json={ @@ -138,8 +142,6 @@ def test_graphql_resize_volume(authorized_client, mock_block_device_return_true) assert response.json()["data"]["resizeVolume"]["success"] is True - - API_MOUNT_VOLUME_MUTATION = """ mutation mountVolume($name: String!) { mountVolume(name: $name) { @@ -199,10 +201,7 @@ def test_graphql_mount_not_found_volume( assert response.json()["data"]["mountVolume"]["success"] is False - -def test_graphql_mount_volume( - authorized_client, mock_block_device_return_true -): +def test_graphql_mount_volume(authorized_client, mock_block_device_return_true): response = authorized_client.post( "/graphql", json={ @@ -229,7 +228,9 @@ mutation unmountVolume($name: String!) { """ -def test_graphql_unmount_volume_unathorized_client(client, mock_block_device_return_true): +def test_graphql_unmount_volume_unathorized_client( + client, mock_block_device_return_true +): response = client.post( "/graphql", json={ @@ -277,9 +278,7 @@ def test_graphql_unmount_volume_false( assert response.json()["data"]["unmountVolume"]["success"] is False -def test_graphql_unmount_volume( - authorized_client, mock_block_device_return_true -): +def test_graphql_unmount_volume(authorized_client, mock_block_device_return_true): response = authorized_client.post( "/graphql", json={ @@ -293,4 +292,3 @@ def test_graphql_unmount_volume( assert response.json()["data"]["unmountVolume"]["code"] == 200 assert response.json()["data"]["unmountVolume"]["message"] is not None assert response.json()["data"]["unmountVolume"]["success"] is True -