mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-22 04:01:27 +00:00
fix: service tests
This commit is contained in:
parent
e01b8ed8f0
commit
b5183948af
|
@ -1,100 +1,99 @@
|
||||||
|
# pylint: disable=redefined-outer-name
|
||||||
|
# pylint: disable=unused-argument
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from tests.common import read_json
|
||||||
def get_service_by_id_return_none_mock():
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def get_service_by_id_mock():
|
class NextcloudMockReturnTrue:
|
||||||
return "nextcloud"
|
|
||||||
|
|
||||||
|
|
||||||
def service_to_graphql_service_mock():
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class BlockDevicesMock:
|
|
||||||
def get_block_device(self, name: str):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class BlockDevicesReturnNoneMock:
|
|
||||||
def get_block_device(self, name: str):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
class NextcloudMock:
|
|
||||||
def __init__(self, args, **kwargs):
|
def __init__(self, args, **kwargs):
|
||||||
self.args = args
|
self.args = args
|
||||||
self.kwargs = kwargs
|
self.kwargs = kwargs
|
||||||
|
|
||||||
def enable(self):
|
def enable():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def disable(self):
|
def disable():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def stop(self):
|
def stop():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def is_movable(self):
|
def is_movable():
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def move_to_volume(self):
|
def move_to_volume(what):
|
||||||
|
return None
|
||||||
|
|
||||||
|
def start():
|
||||||
|
pass
|
||||||
|
|
||||||
|
def restart():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
returncode = 0
|
returncode = 0
|
||||||
|
|
||||||
|
|
||||||
class NextcloudReturnFalseMock:
|
class BlockDevices:
|
||||||
|
def get_block_device(location):
|
||||||
|
return True
|
||||||
|
|
||||||
|
class ProcessMock:
|
||||||
|
"""Mock subprocess.Popen"""
|
||||||
|
|
||||||
def __init__(self, args, **kwargs):
|
def __init__(self, args, **kwargs):
|
||||||
self.args = args
|
self.args = args
|
||||||
self.kwargs = kwargs
|
self.kwargs = kwargs
|
||||||
|
|
||||||
def enable(self):
|
def communicate(): # pylint: disable=no-method-argument
|
||||||
pass
|
return (b"", None)
|
||||||
|
|
||||||
def disable(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def stop(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def is_movable(self):
|
|
||||||
return False
|
|
||||||
|
|
||||||
def move_to_volume(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
returncode = 0
|
returncode = 0
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def mock_subprocess_popen(mocker):
|
||||||
|
mock = mocker.patch("subprocess.Popen", autospec=True, return_value=ProcessMock)
|
||||||
|
return mock
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def one_user(mocker, datadir):
|
||||||
|
mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "one_user.json")
|
||||||
|
assert read_json(datadir / "one_user.json")["users"] == [
|
||||||
|
{
|
||||||
|
"username": "user1",
|
||||||
|
"hashedPassword": "HASHED_PASSWORD_1",
|
||||||
|
"sshKeys": ["ssh-rsa KEY user1@pc"],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
return datadir
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_service_to_graphql_service(mocker):
|
def mock_service_to_graphql_service(mocker):
|
||||||
mock = mocker.patch(
|
mock = mocker.patch(
|
||||||
"selfprivacy_api.graphql.common_types.service.service_to_graphql_service",
|
"selfprivacy_api.graphql.mutations.services_mutations.service_to_graphql_service",
|
||||||
autospec=True,
|
autospec=True,
|
||||||
return_value=service_to_graphql_service_mock,
|
return_value=None,
|
||||||
)
|
)
|
||||||
return mock
|
return mock
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_nextcloud(mocker):
|
def mock_job_to_api_job(mocker):
|
||||||
mock = mocker.patch(
|
mock = mocker.patch(
|
||||||
"selfprivacy_api.services.nextcloud.__init__.Nextcloud",
|
"selfprivacy_api.graphql.mutations.services_mutations.job_to_api_job",
|
||||||
autospec=True,
|
autospec=True,
|
||||||
return_value=NextcloudMock,
|
return_value=None,
|
||||||
)
|
)
|
||||||
return mock
|
return mock
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_block_devices_return_none(mocker):
|
def mock_block_devices_return_none(mocker):
|
||||||
mock = mocker.patch(
|
mock = mocker.patch(
|
||||||
"selfprivacy_api.utils.block_devices.BlockDevices",
|
"selfprivacy_api.utils.block_devices.BlockDevices",
|
||||||
autospec=True,
|
autospec=True,
|
||||||
return_value=BlockDevicesReturnNoneMock,
|
return_value=None,
|
||||||
)
|
)
|
||||||
return mock
|
return mock
|
||||||
|
|
||||||
|
@ -102,19 +101,9 @@ def mock_block_devices_return_none(mocker):
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_block_devices(mocker):
|
def mock_block_devices(mocker):
|
||||||
mock = mocker.patch(
|
mock = mocker.patch(
|
||||||
"selfprivacy_api.utils.block_devices.BlockDevices",
|
"selfprivacy_api.graphql.mutations.services_mutations.BlockDevices",
|
||||||
autospec=True,
|
autospec=True,
|
||||||
return_value=BlockDevicesMock,
|
return_value=BlockDevices,
|
||||||
)
|
|
||||||
return mock
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def mock_nextcloud_return_false(mocker):
|
|
||||||
mock = mocker.patch(
|
|
||||||
"selfprivacy_api.services.nextcloud.__init__.Nextcloud",
|
|
||||||
autospec=True,
|
|
||||||
return_value=NextcloudReturnFalseMock,
|
|
||||||
)
|
)
|
||||||
return mock
|
return mock
|
||||||
|
|
||||||
|
@ -122,9 +111,9 @@ def mock_nextcloud_return_false(mocker):
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_get_service_by_id_return_none(mocker):
|
def mock_get_service_by_id_return_none(mocker):
|
||||||
mock = mocker.patch(
|
mock = mocker.patch(
|
||||||
"selfprivacy_api.services.__init__.get_service_by_id",
|
"selfprivacy_api.graphql.mutations.services_mutations.get_service_by_id",
|
||||||
autospec=True,
|
autospec=True,
|
||||||
return_value=mock_get_service_by_id_return_none,
|
return_value=None,
|
||||||
)
|
)
|
||||||
return mock
|
return mock
|
||||||
|
|
||||||
|
@ -132,9 +121,9 @@ def mock_get_service_by_id_return_none(mocker):
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_get_service_by_id(mocker):
|
def mock_get_service_by_id(mocker):
|
||||||
mock = mocker.patch(
|
mock = mocker.patch(
|
||||||
"selfprivacy_api.services.__init__.get_service_by_id",
|
"selfprivacy_api.graphql.mutations.services_mutations.get_service_by_id",
|
||||||
autospec=True,
|
autospec=True,
|
||||||
return_value=mock_get_service_by_id,
|
return_value=NextcloudMockReturnTrue,
|
||||||
)
|
)
|
||||||
return mock
|
return mock
|
||||||
|
|
||||||
|
@ -143,8 +132,8 @@ def mock_get_service_by_id(mocker):
|
||||||
|
|
||||||
|
|
||||||
API_ENABLE_SERVICE_MUTATION = """
|
API_ENABLE_SERVICE_MUTATION = """
|
||||||
mutation enableService($service_id: String!) {
|
mutation enableService($serviceId: String!) {
|
||||||
enableService(service_id: $service_id) {
|
enableService(serviceId: $serviceId) {
|
||||||
success
|
success
|
||||||
message
|
message
|
||||||
code
|
code
|
||||||
|
@ -154,13 +143,13 @@ mutation enableService($service_id: String!) {
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_enable_service_unathorized_client(
|
def test_graphql_enable_service_unathorized_client(
|
||||||
client, mock_get_service_by_id_return_none, mock_nextcloud
|
client, mock_get_service_by_id_return_none, mock_subprocess_popen
|
||||||
):
|
):
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_ENABLE_SERVICE_MUTATION,
|
"query": API_ENABLE_SERVICE_MUTATION,
|
||||||
"variables": {"service_id": "nextcloud"},
|
"variables": {"serviceId": "nextcloud"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
@ -168,13 +157,17 @@ def test_graphql_enable_service_unathorized_client(
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_enable_not_found_service(
|
def test_graphql_enable_not_found_service(
|
||||||
authorized_client, mock_get_service_by_id_return_none, mock_nextcloud
|
authorized_client,
|
||||||
|
mock_get_service_by_id_return_none,
|
||||||
|
mock_subprocess_popen,
|
||||||
|
one_user,
|
||||||
|
mock_service_to_graphql_service,
|
||||||
):
|
):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_ENABLE_SERVICE_MUTATION,
|
"query": API_ENABLE_SERVICE_MUTATION,
|
||||||
"variables": {"service_id": "nextcloud"},
|
"variables": {"serviceId": "nextcloud"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
@ -186,13 +179,17 @@ def test_graphql_enable_not_found_service(
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_enable_service(
|
def test_graphql_enable_service(
|
||||||
authorized_client, mock_get_service_by_id, mock_nextcloud
|
authorized_client,
|
||||||
|
mock_get_service_by_id,
|
||||||
|
mock_subprocess_popen,
|
||||||
|
one_user,
|
||||||
|
mock_service_to_graphql_service,
|
||||||
):
|
):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_ENABLE_SERVICE_MUTATION,
|
"query": API_ENABLE_SERVICE_MUTATION,
|
||||||
"variables": {"service_id": "nextcloud"},
|
"variables": {"serviceId": "nextcloud"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
@ -204,8 +201,8 @@ def test_graphql_enable_service(
|
||||||
|
|
||||||
|
|
||||||
API_DISABLE_SERVICE_MUTATION = """
|
API_DISABLE_SERVICE_MUTATION = """
|
||||||
mutation disableService($service_id: String!) {
|
mutation disableService($serviceId: String!) {
|
||||||
disableService(service_id: $service_id) {
|
disableService(serviceId: $serviceId) {
|
||||||
success
|
success
|
||||||
message
|
message
|
||||||
code
|
code
|
||||||
|
@ -215,13 +212,17 @@ mutation disableService($service_id: String!) {
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_disable_service_unathorized_client(
|
def test_graphql_disable_service_unathorized_client(
|
||||||
client, mock_get_service_by_id_return_none, mock_nextcloud
|
client,
|
||||||
|
mock_get_service_by_id_return_none,
|
||||||
|
mock_subprocess_popen,
|
||||||
|
one_user,
|
||||||
|
mock_service_to_graphql_service,
|
||||||
):
|
):
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_DISABLE_SERVICE_MUTATION,
|
"query": API_DISABLE_SERVICE_MUTATION,
|
||||||
"variables": {"service_id": "nextcloud"},
|
"variables": {"serviceId": "nextcloud"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
@ -229,13 +230,17 @@ def test_graphql_disable_service_unathorized_client(
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_disable_not_found_service(
|
def test_graphql_disable_not_found_service(
|
||||||
authorized_client, mock_get_service_by_id_return_none, mock_nextcloud
|
authorized_client,
|
||||||
|
mock_get_service_by_id_return_none,
|
||||||
|
mock_subprocess_popen,
|
||||||
|
one_user,
|
||||||
|
mock_service_to_graphql_service,
|
||||||
):
|
):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_DISABLE_SERVICE_MUTATION,
|
"query": API_DISABLE_SERVICE_MUTATION,
|
||||||
"variables": {"service_id": "nextcloud"},
|
"variables": {"serviceId": "nextcloud"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
@ -247,13 +252,17 @@ def test_graphql_disable_not_found_service(
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_disable_services(
|
def test_graphql_disable_services(
|
||||||
authorized_client, mock_get_service_by_id, mock_nextcloud
|
authorized_client,
|
||||||
|
mock_get_service_by_id,
|
||||||
|
mock_subprocess_popen,
|
||||||
|
one_user,
|
||||||
|
mock_service_to_graphql_service,
|
||||||
):
|
):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_DISABLE_SERVICE_MUTATION,
|
"query": API_DISABLE_SERVICE_MUTATION,
|
||||||
"variables": {"service_id": "nextcloud"},
|
"variables": {"serviceId": "nextcloud"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
@ -265,8 +274,8 @@ def test_graphql_disable_services(
|
||||||
|
|
||||||
|
|
||||||
API_STOP_SERVICE_MUTATION = """
|
API_STOP_SERVICE_MUTATION = """
|
||||||
mutation stopService($service_id: String!) {
|
mutation stopService($serviceId: String!) {
|
||||||
stopService(service_id: $service_id) {
|
stopService(serviceId: $serviceId) {
|
||||||
success
|
success
|
||||||
message
|
message
|
||||||
code
|
code
|
||||||
|
@ -278,14 +287,15 @@ mutation stopService($service_id: String!) {
|
||||||
def test_graphql_stop_service_unathorized_client(
|
def test_graphql_stop_service_unathorized_client(
|
||||||
client,
|
client,
|
||||||
mock_get_service_by_id_return_none,
|
mock_get_service_by_id_return_none,
|
||||||
mock_nextcloud,
|
|
||||||
mock_service_to_graphql_service,
|
mock_service_to_graphql_service,
|
||||||
|
mock_subprocess_popen,
|
||||||
|
one_user,
|
||||||
):
|
):
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_STOP_SERVICE_MUTATION,
|
"query": API_STOP_SERVICE_MUTATION,
|
||||||
"variables": {"service_id": "nextcloud"},
|
"variables": {"serviceId": "nextcloud"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
@ -295,14 +305,15 @@ def test_graphql_stop_service_unathorized_client(
|
||||||
def test_graphql_stop_not_found_service(
|
def test_graphql_stop_not_found_service(
|
||||||
authorized_client,
|
authorized_client,
|
||||||
mock_get_service_by_id_return_none,
|
mock_get_service_by_id_return_none,
|
||||||
mock_nextcloud,
|
|
||||||
mock_service_to_graphql_service,
|
mock_service_to_graphql_service,
|
||||||
|
mock_subprocess_popen,
|
||||||
|
one_user,
|
||||||
):
|
):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_STOP_SERVICE_MUTATION,
|
"query": API_STOP_SERVICE_MUTATION,
|
||||||
"variables": {"service_id": "nextcloud"},
|
"variables": {"serviceId": "nextcloud"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
@ -316,14 +327,15 @@ def test_graphql_stop_not_found_service(
|
||||||
def test_graphql_stop_services(
|
def test_graphql_stop_services(
|
||||||
authorized_client,
|
authorized_client,
|
||||||
mock_get_service_by_id,
|
mock_get_service_by_id,
|
||||||
mock_nextcloud,
|
|
||||||
mock_service_to_graphql_service,
|
mock_service_to_graphql_service,
|
||||||
|
mock_subprocess_popen,
|
||||||
|
one_user,
|
||||||
):
|
):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_STOP_SERVICE_MUTATION,
|
"query": API_STOP_SERVICE_MUTATION,
|
||||||
"variables": {"service_id": "nextcloud"},
|
"variables": {"serviceId": "nextcloud"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
@ -335,8 +347,8 @@ def test_graphql_stop_services(
|
||||||
|
|
||||||
|
|
||||||
API_START_SERVICE_MUTATION = """
|
API_START_SERVICE_MUTATION = """
|
||||||
mutation startService($service_id: String!) {
|
mutation startService($serviceId: String!) {
|
||||||
startService(service_id: $service_id) {
|
startService(serviceId: $serviceId) {
|
||||||
success
|
success
|
||||||
message
|
message
|
||||||
code
|
code
|
||||||
|
@ -348,14 +360,15 @@ mutation startService($service_id: String!) {
|
||||||
def test_graphql_start_service_unathorized_client(
|
def test_graphql_start_service_unathorized_client(
|
||||||
client,
|
client,
|
||||||
mock_get_service_by_id_return_none,
|
mock_get_service_by_id_return_none,
|
||||||
mock_nextcloud,
|
|
||||||
mock_service_to_graphql_service,
|
mock_service_to_graphql_service,
|
||||||
|
mock_subprocess_popen,
|
||||||
|
one_user,
|
||||||
):
|
):
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_START_SERVICE_MUTATION,
|
"query": API_START_SERVICE_MUTATION,
|
||||||
"variables": {"service_id": "nextcloud"},
|
"variables": {"serviceId": "nextcloud"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
@ -365,14 +378,15 @@ def test_graphql_start_service_unathorized_client(
|
||||||
def test_graphql_start_not_found_service(
|
def test_graphql_start_not_found_service(
|
||||||
authorized_client,
|
authorized_client,
|
||||||
mock_get_service_by_id_return_none,
|
mock_get_service_by_id_return_none,
|
||||||
mock_nextcloud,
|
|
||||||
mock_service_to_graphql_service,
|
mock_service_to_graphql_service,
|
||||||
|
mock_subprocess_popen,
|
||||||
|
one_user,
|
||||||
):
|
):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_START_SERVICE_MUTATION,
|
"query": API_START_SERVICE_MUTATION,
|
||||||
"variables": {"service_id": "nextcloud"},
|
"variables": {"serviceId": "nextcloud"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
@ -386,14 +400,15 @@ def test_graphql_start_not_found_service(
|
||||||
def test_graphql_start_services(
|
def test_graphql_start_services(
|
||||||
authorized_client,
|
authorized_client,
|
||||||
mock_get_service_by_id,
|
mock_get_service_by_id,
|
||||||
mock_nextcloud,
|
|
||||||
mock_service_to_graphql_service,
|
mock_service_to_graphql_service,
|
||||||
|
mock_subprocess_popen,
|
||||||
|
one_user,
|
||||||
):
|
):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_START_SERVICE_MUTATION,
|
"query": API_START_SERVICE_MUTATION,
|
||||||
"variables": {"service_id": "nextcloud"},
|
"variables": {"serviceId": "nextcloud"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
@ -405,8 +420,8 @@ def test_graphql_start_services(
|
||||||
|
|
||||||
|
|
||||||
API_RESTART_SERVICE_MUTATION = """
|
API_RESTART_SERVICE_MUTATION = """
|
||||||
mutation restartService($service_id: String!) {
|
mutation restartService($serviceId: String!) {
|
||||||
restartService(service_id: $service_id) {
|
restartService(serviceId: $serviceId) {
|
||||||
success
|
success
|
||||||
message
|
message
|
||||||
code
|
code
|
||||||
|
@ -418,14 +433,15 @@ mutation restartService($service_id: String!) {
|
||||||
def test_graphql_restart_service_unathorized_client(
|
def test_graphql_restart_service_unathorized_client(
|
||||||
client,
|
client,
|
||||||
mock_get_service_by_id_return_none,
|
mock_get_service_by_id_return_none,
|
||||||
mock_nextcloud,
|
|
||||||
mock_service_to_graphql_service,
|
mock_service_to_graphql_service,
|
||||||
|
mock_subprocess_popen,
|
||||||
|
one_user,
|
||||||
):
|
):
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_RESTART_SERVICE_MUTATION,
|
"query": API_RESTART_SERVICE_MUTATION,
|
||||||
"variables": {"service_id": "nextcloud"},
|
"variables": {"serviceId": "nextcloud"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
@ -435,14 +451,15 @@ def test_graphql_restart_service_unathorized_client(
|
||||||
def test_graphql_restart_not_found_service(
|
def test_graphql_restart_not_found_service(
|
||||||
authorized_client,
|
authorized_client,
|
||||||
mock_get_service_by_id_return_none,
|
mock_get_service_by_id_return_none,
|
||||||
mock_nextcloud,
|
|
||||||
mock_service_to_graphql_service,
|
mock_service_to_graphql_service,
|
||||||
|
mock_subprocess_popen,
|
||||||
|
one_user,
|
||||||
):
|
):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_RESTART_SERVICE_MUTATION,
|
"query": API_RESTART_SERVICE_MUTATION,
|
||||||
"variables": {"service_id": "nextcloud"},
|
"variables": {"serviceId": "nextcloud"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
@ -456,14 +473,15 @@ def test_graphql_restart_not_found_service(
|
||||||
def test_graphql_restart_service(
|
def test_graphql_restart_service(
|
||||||
authorized_client,
|
authorized_client,
|
||||||
mock_get_service_by_id,
|
mock_get_service_by_id,
|
||||||
mock_nextcloud,
|
|
||||||
mock_service_to_graphql_service,
|
mock_service_to_graphql_service,
|
||||||
|
mock_subprocess_popen,
|
||||||
|
one_user,
|
||||||
):
|
):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_RESTART_SERVICE_MUTATION,
|
"query": API_RESTART_SERVICE_MUTATION,
|
||||||
"variables": {"service_id": "nextcloud"},
|
"variables": {"serviceId": "nextcloud"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
@ -488,15 +506,16 @@ mutation moveService($input: MoveServiceInput!) {
|
||||||
def test_graphql_move_service_unathorized_client(
|
def test_graphql_move_service_unathorized_client(
|
||||||
client,
|
client,
|
||||||
mock_get_service_by_id_return_none,
|
mock_get_service_by_id_return_none,
|
||||||
mock_nextcloud,
|
|
||||||
mock_service_to_graphql_service,
|
mock_service_to_graphql_service,
|
||||||
|
mock_subprocess_popen,
|
||||||
|
one_user,
|
||||||
):
|
):
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_MOVE_SERVICE_MUTATION,
|
"query": API_MOVE_SERVICE_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"input": {"service_id": "nextcloud", "location": "sdx"},
|
"input": {"serviceId": "nextcloud", "location": "sdx"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -507,15 +526,16 @@ def test_graphql_move_service_unathorized_client(
|
||||||
def test_graphql_move_not_found_service(
|
def test_graphql_move_not_found_service(
|
||||||
authorized_client,
|
authorized_client,
|
||||||
mock_get_service_by_id_return_none,
|
mock_get_service_by_id_return_none,
|
||||||
mock_nextcloud,
|
|
||||||
mock_service_to_graphql_service,
|
mock_service_to_graphql_service,
|
||||||
|
mock_subprocess_popen,
|
||||||
|
one_user,
|
||||||
):
|
):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_MOVE_SERVICE_MUTATION,
|
"query": API_MOVE_SERVICE_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"input": {"service_id": "nextcloud", "location": "sdx"},
|
"input": {"serviceId": "nextcloud", "location": "sdx"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -529,47 +549,50 @@ def test_graphql_move_not_found_service(
|
||||||
|
|
||||||
def test_graphql_move_not_moveble_service(
|
def test_graphql_move_not_moveble_service(
|
||||||
authorized_client,
|
authorized_client,
|
||||||
mock_get_service_by_id,
|
mock_get_service_by_id_return_none,
|
||||||
mock_nextcloud_return_false,
|
|
||||||
mock_service_to_graphql_service,
|
mock_service_to_graphql_service,
|
||||||
|
mock_subprocess_popen,
|
||||||
|
one_user,
|
||||||
):
|
):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_MOVE_SERVICE_MUTATION,
|
"query": API_MOVE_SERVICE_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"input": {"service_id": "nextcloud", "location": "sdx"},
|
"input": {"serviceId": "nextcloud", "location": "sdx"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json().get("data") is not None
|
assert response.json().get("data") is not None
|
||||||
|
|
||||||
assert response.json()["data"]["moveService"]["code"] == 400
|
assert response.json()["data"]["moveService"]["code"] == 404
|
||||||
assert response.json()["data"]["moveService"]["message"] is not None
|
assert response.json()["data"]["moveService"]["message"] is not None
|
||||||
assert response.json()["data"]["moveService"]["success"] is False
|
assert response.json()["data"]["moveService"]["success"] is False
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_move_service_volume_not_found(
|
def test_graphql_move_service_volume_not_found(
|
||||||
authorized_client,
|
authorized_client,
|
||||||
mock_get_service_by_id,
|
mock_get_service_by_id_return_none,
|
||||||
mock_nextcloud,
|
|
||||||
mock_service_to_graphql_service,
|
mock_service_to_graphql_service,
|
||||||
mock_block_devices_return_none,
|
mock_block_devices_return_none,
|
||||||
|
mock_subprocess_popen,
|
||||||
|
one_user,
|
||||||
):
|
):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_MOVE_SERVICE_MUTATION,
|
"query": API_MOVE_SERVICE_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"input": {"service_id": "nextcloud", "location": "sdx"},
|
"input": {"serviceId": "nextcloud", "location": "sdx"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json().get("data") is not None
|
assert response.json().get("data") is not None
|
||||||
|
|
||||||
assert response.json()["data"]["moveService"]["code"] == 400
|
assert response.json()["data"]["moveService"]["code"] == 404
|
||||||
assert response.json()["data"]["moveService"]["message"] is not None
|
assert response.json()["data"]["moveService"]["message"] is not None
|
||||||
assert response.json()["data"]["moveService"]["success"] is False
|
assert response.json()["data"]["moveService"]["success"] is False
|
||||||
|
|
||||||
|
@ -577,16 +600,18 @@ def test_graphql_move_service_volume_not_found(
|
||||||
def test_graphql_move_service(
|
def test_graphql_move_service(
|
||||||
authorized_client,
|
authorized_client,
|
||||||
mock_get_service_by_id,
|
mock_get_service_by_id,
|
||||||
mock_nextcloud,
|
|
||||||
mock_service_to_graphql_service,
|
mock_service_to_graphql_service,
|
||||||
mock_block_devices,
|
mock_block_devices,
|
||||||
|
mock_subprocess_popen,
|
||||||
|
one_user,
|
||||||
|
mock_job_to_api_job,
|
||||||
):
|
):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_MOVE_SERVICE_MUTATION,
|
"query": API_MOVE_SERVICE_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"input": {"service_id": "nextcloud", "location": "sdx"},
|
"input": {"serviceId": "nextcloud", "location": "sdx"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
61
tests/test_graphql/test_api_services/one_user.json
Normal file
61
tests/test_graphql/test_api_services/one_user.json
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
{
|
||||||
|
"backblaze": {
|
||||||
|
"accountId": "ID",
|
||||||
|
"accountKey": "KEY",
|
||||||
|
"bucket": "selfprivacy"
|
||||||
|
},
|
||||||
|
"api": {
|
||||||
|
"token": "TEST_TOKEN",
|
||||||
|
"enableSwagger": false
|
||||||
|
},
|
||||||
|
"bitwarden": {
|
||||||
|
"enable": false
|
||||||
|
},
|
||||||
|
"cloudflare": {
|
||||||
|
"apiKey": "TOKEN"
|
||||||
|
},
|
||||||
|
"databasePassword": "PASSWORD",
|
||||||
|
"domain": "test.tld",
|
||||||
|
"hashedMasterPassword": "HASHED_PASSWORD",
|
||||||
|
"hostname": "test-instance",
|
||||||
|
"nextcloud": {
|
||||||
|
"adminPassword": "ADMIN",
|
||||||
|
"databasePassword": "ADMIN",
|
||||||
|
"enable": true
|
||||||
|
},
|
||||||
|
"resticPassword": "PASS",
|
||||||
|
"ssh": {
|
||||||
|
"enable": true,
|
||||||
|
"passwordAuthentication": true,
|
||||||
|
"rootKeys": [
|
||||||
|
"ssh-ed25519 KEY test@pc"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"username": "tester",
|
||||||
|
"gitea": {
|
||||||
|
"enable": false
|
||||||
|
},
|
||||||
|
"ocserv": {
|
||||||
|
"enable": true
|
||||||
|
},
|
||||||
|
"pleroma": {
|
||||||
|
"enable": true
|
||||||
|
},
|
||||||
|
"autoUpgrade": {
|
||||||
|
"enable": true,
|
||||||
|
"allowReboot": true
|
||||||
|
},
|
||||||
|
"timezone": "Europe/Moscow",
|
||||||
|
"sshKeys": [
|
||||||
|
"ssh-rsa KEY test@pc"
|
||||||
|
],
|
||||||
|
"users": [
|
||||||
|
{
|
||||||
|
"username": "user1",
|
||||||
|
"hashedPassword": "HASHED_PASSWORD_1",
|
||||||
|
"sshKeys": [
|
||||||
|
"ssh-rsa KEY user1@pc"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -291,7 +291,7 @@ def test_graphql_unmount_volume_unathorized_client(
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_unmount_not_fount_volume(
|
def test_graphql_unmount_not_fount_volume(
|
||||||
authorized_client, mock_block_devices_return_true
|
authorized_client, mock_block_devices_return_none
|
||||||
):
|
):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
|
@ -309,7 +309,7 @@ def test_graphql_unmount_not_fount_volume(
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_unmount_volume_false(
|
def test_graphql_unmount_volume_false(
|
||||||
authorized_client, mock_block_devices_return_true
|
authorized_client, mock_block_devices_return_none
|
||||||
):
|
):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
|
|
Loading…
Reference in a new issue