mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-29 15:31:28 +00:00
test: remove unused mocks, fix tests naming
This commit is contained in:
parent
d921206792
commit
abcd0bde77
|
@ -38,6 +38,7 @@ class BlockDevices:
|
|||
def get_block_device(location):
|
||||
return True
|
||||
|
||||
|
||||
class ProcessMock:
|
||||
"""Mock subprocess.Popen"""
|
||||
|
||||
|
@ -79,6 +80,7 @@ def mock_service_to_graphql_service(mocker):
|
|||
)
|
||||
return mock
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_job_to_api_job(mocker):
|
||||
mock = mocker.patch(
|
||||
|
@ -88,6 +90,7 @@ def mock_job_to_api_job(mocker):
|
|||
)
|
||||
return mock
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_block_devices_return_none(mocker):
|
||||
mock = mocker.patch(
|
||||
|
@ -142,7 +145,7 @@ mutation enableService($serviceId: String!) {
|
|||
"""
|
||||
|
||||
|
||||
def test_graphql_enable_service_unathorized_client(
|
||||
def test_graphql_enable_service_unauthorized_client(
|
||||
client, mock_get_service_by_id_return_none, mock_subprocess_popen
|
||||
):
|
||||
response = client.post(
|
||||
|
@ -211,7 +214,7 @@ mutation disableService($serviceId: String!) {
|
|||
"""
|
||||
|
||||
|
||||
def test_graphql_disable_service_unathorized_client(
|
||||
def test_graphql_disable_service_unauthorized_client(
|
||||
client,
|
||||
mock_get_service_by_id_return_none,
|
||||
mock_subprocess_popen,
|
||||
|
@ -284,7 +287,7 @@ mutation stopService($serviceId: String!) {
|
|||
"""
|
||||
|
||||
|
||||
def test_graphql_stop_service_unathorized_client(
|
||||
def test_graphql_stop_service_unauthorized_client(
|
||||
client,
|
||||
mock_get_service_by_id_return_none,
|
||||
mock_service_to_graphql_service,
|
||||
|
@ -324,7 +327,7 @@ def test_graphql_stop_not_found_service(
|
|||
assert response.json()["data"]["stopService"]["success"] is False
|
||||
|
||||
|
||||
def test_graphql_stop_services(
|
||||
def test_graphql_stop_service(
|
||||
authorized_client,
|
||||
mock_get_service_by_id,
|
||||
mock_service_to_graphql_service,
|
||||
|
@ -357,7 +360,7 @@ mutation startService($serviceId: String!) {
|
|||
"""
|
||||
|
||||
|
||||
def test_graphql_start_service_unathorized_client(
|
||||
def test_graphql_start_service_unauthorized_client(
|
||||
client,
|
||||
mock_get_service_by_id_return_none,
|
||||
mock_service_to_graphql_service,
|
||||
|
@ -397,7 +400,7 @@ def test_graphql_start_not_found_service(
|
|||
assert response.json()["data"]["startService"]["success"] is False
|
||||
|
||||
|
||||
def test_graphql_start_services(
|
||||
def test_graphql_start_service(
|
||||
authorized_client,
|
||||
mock_get_service_by_id,
|
||||
mock_service_to_graphql_service,
|
||||
|
@ -430,7 +433,7 @@ mutation restartService($serviceId: String!) {
|
|||
"""
|
||||
|
||||
|
||||
def test_graphql_restart_service_unathorized_client(
|
||||
def test_graphql_restart_service_unauthorized_client(
|
||||
client,
|
||||
mock_get_service_by_id_return_none,
|
||||
mock_service_to_graphql_service,
|
||||
|
@ -503,7 +506,7 @@ mutation moveService($input: MoveServiceInput!) {
|
|||
"""
|
||||
|
||||
|
||||
def test_graphql_move_service_unathorized_client(
|
||||
def test_graphql_move_service_unauthorized_client(
|
||||
client,
|
||||
mock_get_service_by_id_return_none,
|
||||
mock_service_to_graphql_service,
|
||||
|
@ -547,7 +550,7 @@ def test_graphql_move_not_found_service(
|
|||
assert response.json()["data"]["moveService"]["success"] is False
|
||||
|
||||
|
||||
def test_graphql_move_not_moveble_service(
|
||||
def test_graphql_move_not_movable_service(
|
||||
authorized_client,
|
||||
mock_get_service_by_id_return_none,
|
||||
mock_service_to_graphql_service,
|
||||
|
|
|
@ -1,25 +1,6 @@
|
|||
import pytest
|
||||
|
||||
|
||||
class BlockDeviceMockReturnNone:
|
||||
"""Mock BlockDevices"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.args = args
|
||||
self.kwargs = kwargs
|
||||
|
||||
def mount(self):
|
||||
return None
|
||||
|
||||
def unmount(self):
|
||||
return None
|
||||
|
||||
def resize(self):
|
||||
return None
|
||||
|
||||
returncode = 0
|
||||
|
||||
|
||||
class BlockDeviceMockReturnTrue:
|
||||
"""Mock BlockDevices"""
|
||||
|
||||
|
@ -39,25 +20,6 @@ class BlockDeviceMockReturnTrue:
|
|||
returncode = 0
|
||||
|
||||
|
||||
class BlockDeviceMockReturnFalse:
|
||||
"""Mock BlockDevices"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.args = args
|
||||
self.kwargs = kwargs
|
||||
|
||||
def mount(self):
|
||||
return False
|
||||
|
||||
def unmount(self):
|
||||
return False
|
||||
|
||||
def resize(self):
|
||||
return False
|
||||
|
||||
returncode = 0
|
||||
|
||||
|
||||
class BlockDevicesMockReturnTrue:
|
||||
def get_block_device(name: str): # type: ignore
|
||||
return BlockDeviceMockReturnTrue()
|
||||
|
@ -101,16 +63,6 @@ def mock_block_devices_return_none(mocker):
|
|||
return mock
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_block_device_return_none(mocker):
|
||||
mock = mocker.patch(
|
||||
"selfprivacy_api.utils.block_devices.BlockDevice",
|
||||
autospec=True,
|
||||
return_value=BlockDeviceMockReturnNone,
|
||||
)
|
||||
return mock
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_block_device_return_true(mocker):
|
||||
mock = mocker.patch(
|
||||
|
@ -121,16 +73,6 @@ def mock_block_device_return_true(mocker):
|
|||
return mock
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_block_device_return_false(mocker):
|
||||
mock = mocker.patch(
|
||||
"selfprivacy_api.utils.block_devices.BlockDevice",
|
||||
autospec=True,
|
||||
return_value=BlockDeviceMockReturnFalse,
|
||||
)
|
||||
return mock
|
||||
|
||||
|
||||
API_RESIZE_VOLUME_MUTATION = """
|
||||
mutation resizeVolume($name: String!) {
|
||||
resizeVolume(name: $name) {
|
||||
|
@ -142,7 +84,7 @@ mutation resizeVolume($name: String!) {
|
|||
"""
|
||||
|
||||
|
||||
def test_graphql_resize_volumea_unathorized_client(
|
||||
def test_graphql_resize_volume_unauthorized_client(
|
||||
client, mock_block_devices_return_true
|
||||
):
|
||||
response = client.post(
|
||||
|
@ -201,7 +143,9 @@ mutation mountVolume($name: String!) {
|
|||
"""
|
||||
|
||||
|
||||
def test_graphql_mount_volume_unathorized_client(client, mock_block_device_return_true):
|
||||
def test_graphql_mount_volume_unauthorized_client(
|
||||
client, mock_block_device_return_true
|
||||
):
|
||||
response = client.post(
|
||||
"/graphql",
|
||||
json={
|
||||
|
@ -276,7 +220,7 @@ mutation unmountVolume($name: String!) {
|
|||
"""
|
||||
|
||||
|
||||
def test_graphql_unmount_volume_unathorized_client(
|
||||
def test_graphql_unmount_volume_unauthorized_client(
|
||||
client, mock_block_devices_return_true
|
||||
):
|
||||
response = client.post(
|
||||
|
@ -290,25 +234,7 @@ def test_graphql_unmount_volume_unathorized_client(
|
|||
assert response.json().get("data") is None
|
||||
|
||||
|
||||
def test_graphql_unmount_not_fount_volume(
|
||||
authorized_client, mock_block_devices_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(
|
||||
def test_graphql_unmount_not_found_volume(
|
||||
authorized_client, mock_block_devices_return_none
|
||||
):
|
||||
response = authorized_client.post(
|
||||
|
|
Loading…
Reference in a new issue