mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-29 15:31:28 +00:00
fix tests
This commit is contained in:
parent
241753b6f8
commit
6b557d8e63
|
@ -1,4 +1,20 @@
|
||||||
from typing import ByteString
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
class BlockDevicesMockReturnNone:
|
||||||
|
"""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 BlockDevicesMock:
|
class BlockDevicesMock:
|
||||||
|
@ -8,20 +24,33 @@ class BlockDevicesMock:
|
||||||
self.args = args
|
self.args = args
|
||||||
self.kwargs = kwargs
|
self.kwargs = kwargs
|
||||||
|
|
||||||
def get_block_device(name: str): # pylint: disable=no-method-argument
|
def get_block_device(self, name: str):
|
||||||
return None
|
return 0
|
||||||
|
|
||||||
|
def resize(self):
|
||||||
|
pass
|
||||||
|
|
||||||
returncode = 0
|
returncode = 0
|
||||||
|
|
||||||
|
|
||||||
@ByteString.fixture
|
@pytest.fixture
|
||||||
def mock_get_block_device(mocker):
|
def mock_block_device_return_none(mocker):
|
||||||
mock = mocker.patch("BlockDevices", autospec=True)
|
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
|
||||||
|
)
|
||||||
return mock
|
return mock
|
||||||
|
|
||||||
|
|
||||||
API_RESIZE_VOLUME_MUTATION = """
|
API_RESIZE_VOLUME_MUTATION = """
|
||||||
mutation resizeVolume($name: str!) {
|
mutation resizeVolume($name: String!) {
|
||||||
resizeVolume(name: $name) {
|
resizeVolume(name: $name) {
|
||||||
success
|
success
|
||||||
message
|
message
|
||||||
|
@ -30,14 +59,27 @@ mutation resizeVolume($name: str!) {
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def test_graphql_get_nonexistent_block_device(authorized_client, mock_get_block_device):
|
|
||||||
|
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
|
||||||
|
):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_RESIZE_VOLUME_MUTATION,
|
"query": API_RESIZE_VOLUME_MUTATION,
|
||||||
"variables": {
|
"variables": {"name": "sdx"},
|
||||||
"name": "sdc"
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
@ -46,3 +88,19 @@ def test_graphql_get_nonexistent_block_device(authorized_client, mock_get_block_
|
||||||
assert response.json()["data"]["resizeVolume"]["code"] == 404
|
assert response.json()["data"]["resizeVolume"]["code"] == 404
|
||||||
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 False
|
assert response.json()["data"]["resizeVolume"]["success"] is False
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
Loading…
Reference in a new issue