mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-12-01 19:06:45 +00:00
update storage tests
This commit is contained in:
parent
9ea6867edb
commit
13368dcfe3
|
@ -1,28 +1,26 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
class BlockDevicesMockReturnNone:
|
class BlockDeviceMockReturnNone:
|
||||||
"""Mock BlockDevices"""
|
"""Mock BlockDevices"""
|
||||||
|
|
||||||
def __init__(self, args, **kwargs):
|
def __init__(self, args, **kwargs):
|
||||||
self.args = args
|
self.args = args
|
||||||
self.kwargs = kwargs
|
self.kwargs = kwargs
|
||||||
|
|
||||||
def get_block_device(self, name: str):
|
|
||||||
return None
|
|
||||||
|
|
||||||
def resize(self):
|
def resize(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
returncode = 0
|
returncode = 0
|
||||||
|
|
||||||
|
|
||||||
class BlockDevicesMockReturnTrue:
|
class BlockDeviceMockReturnTrue:
|
||||||
"""Mock BlockDevices"""
|
"""Mock BlockDevices"""
|
||||||
|
|
||||||
def __init__(self, args, **kwargs):
|
def __init__(self, args, **kwargs):
|
||||||
self.args = args
|
self.args = args
|
||||||
self.kwargs = kwargs
|
self.kwargs = kwargs
|
||||||
|
self.name = "sdx"
|
||||||
|
|
||||||
def mount(self):
|
def mount(self):
|
||||||
return True
|
return True
|
||||||
|
@ -35,16 +33,14 @@ class BlockDevicesMockReturnTrue:
|
||||||
|
|
||||||
returncode = 0
|
returncode = 0
|
||||||
|
|
||||||
class BlockDevicesMockReturnFalse:
|
|
||||||
|
class BlockDeviceMockReturnFalse:
|
||||||
"""Mock BlockDevices"""
|
"""Mock BlockDevices"""
|
||||||
|
|
||||||
def __init__(self, args, **kwargs):
|
def __init__(self, args, **kwargs):
|
||||||
self.args = args
|
self.args = args
|
||||||
self.kwargs = kwargs
|
self.kwargs = kwargs
|
||||||
|
|
||||||
def get_block_device(self, name: str):
|
|
||||||
return 0
|
|
||||||
|
|
||||||
def mount(self):
|
def mount(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -60,7 +56,9 @@ class BlockDevicesMockReturnFalse:
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_block_device_return_none(mocker):
|
def mock_block_device_return_none(mocker):
|
||||||
mock = mocker.patch(
|
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
|
return mock
|
||||||
|
|
||||||
|
@ -68,7 +66,9 @@ def mock_block_device_return_none(mocker):
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_block_device_return_true(mocker):
|
def mock_block_device_return_true(mocker):
|
||||||
mock = mocker.patch(
|
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
|
return mock
|
||||||
|
|
||||||
|
@ -76,7 +76,9 @@ def mock_block_device_return_true(mocker):
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_block_device_return_false(mocker):
|
def mock_block_device_return_false(mocker):
|
||||||
mock = mocker.patch(
|
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
|
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(
|
response = client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
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
|
assert response.json()["data"]["resizeVolume"]["success"] is True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
API_MOUNT_VOLUME_MUTATION = """
|
API_MOUNT_VOLUME_MUTATION = """
|
||||||
mutation mountVolume($name: String!) {
|
mutation mountVolume($name: String!) {
|
||||||
mountVolume(name: $name) {
|
mountVolume(name: $name) {
|
||||||
|
@ -199,10 +201,7 @@ def test_graphql_mount_not_found_volume(
|
||||||
assert response.json()["data"]["mountVolume"]["success"] is False
|
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(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
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(
|
response = client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
|
@ -277,9 +278,7 @@ def test_graphql_unmount_volume_false(
|
||||||
assert response.json()["data"]["unmountVolume"]["success"] is False
|
assert response.json()["data"]["unmountVolume"]["success"] is False
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_unmount_volume(
|
def test_graphql_unmount_volume(authorized_client, mock_block_device_return_true):
|
||||||
authorized_client, mock_block_device_return_true
|
|
||||||
):
|
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
|
@ -293,4 +292,3 @@ def test_graphql_unmount_volume(
|
||||||
assert response.json()["data"]["unmountVolume"]["code"] == 200
|
assert response.json()["data"]["unmountVolume"]["code"] == 200
|
||||||
assert response.json()["data"]["unmountVolume"]["message"] is not None
|
assert response.json()["data"]["unmountVolume"]["message"] is not None
|
||||||
assert response.json()["data"]["unmountVolume"]["success"] is True
|
assert response.json()["data"]["unmountVolume"]["success"] is True
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue