mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-01-09 17:39:31 +00:00
update tests
This commit is contained in:
parent
6fd63ac0ea
commit
8d21cdcb2b
|
@ -17,10 +17,7 @@ A job is a dictionary with the following keys:
|
||||||
import typing
|
import typing
|
||||||
import datetime
|
import datetime
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
import asyncio
|
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
import time
|
|
||||||
import uuid
|
import uuid
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
from selfprivacy_api.jobs.__init__ import Job
|
||||||
|
|
||||||
|
|
||||||
class ProcessMock:
|
class ProcessMock:
|
||||||
|
@ -14,12 +15,18 @@ class ProcessMock:
|
||||||
returncode = 0
|
returncode = 0
|
||||||
|
|
||||||
|
|
||||||
class JobsMock:
|
class JobsMockReturnTrue:
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def remove_by_uuid(self, job_uuid: str):
|
def remove_by_uuid(self, job_uuid: str):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class JobsMockReturnFalse:
|
class JobsMockReturnFalse:
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def remove_by_uuid(self, job_uuid: str):
|
def remove_by_uuid(self, job_uuid: str):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -31,9 +38,11 @@ def mock_subprocess_popen(mocker):
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_jobs(mocker):
|
def mock_jobs_return_true(mocker):
|
||||||
mock = mocker.patch(
|
mock = mocker.patch(
|
||||||
"selfprivacy_api.jobs.__init__.Jobs", autospec=True, return_value=JobsMock
|
"selfprivacy_api.jobs.__init__.Jobs",
|
||||||
|
autospec=True,
|
||||||
|
return_value=JobsMockReturnTrue,
|
||||||
)
|
)
|
||||||
return mock
|
return mock
|
||||||
|
|
||||||
|
@ -41,14 +50,16 @@ def mock_jobs(mocker):
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_jobs_return_false(mocker):
|
def mock_jobs_return_false(mocker):
|
||||||
mock = mocker.patch(
|
mock = mocker.patch(
|
||||||
"selfprivacy_api.jobs.__init__.Jobs", autospec=True, return_value=JobsMock
|
"selfprivacy_api.jobs.__init__.Jobs",
|
||||||
|
autospec=True,
|
||||||
|
return_value=JobsMockReturnTrue,
|
||||||
)
|
)
|
||||||
return mock
|
return mock
|
||||||
|
|
||||||
|
|
||||||
API_REMOVE_JOB_MUTATION = """
|
API_REMOVE_JOB_MUTATION = """
|
||||||
mutation removeJob($sshInput: SshMutationInput!) {
|
mutation removeJob($job: Job!) {
|
||||||
removeJob(sshInput: $sshInput) {
|
removeJob(job: $job) {
|
||||||
success
|
success
|
||||||
message
|
message
|
||||||
code
|
code
|
||||||
|
@ -57,15 +68,16 @@ mutation removeJob($sshInput: SshMutationInput!) {
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_remove_job_unauthorized(client, mock_subprocess_popen, mock_jobs):
|
def test_graphql_remove_job_unauthorized(
|
||||||
|
client, mock_subprocess_popen, mock_jobs_return_true
|
||||||
|
):
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_REMOVE_JOB_MUTATION,
|
"query": API_REMOVE_JOB_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"sshInput": {
|
"Job": {
|
||||||
"username": "user1",
|
"uid": "12345",
|
||||||
"sshKey": "ssh-rsa KEY test_key@pc",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -74,16 +86,23 @@ def test_graphql_remove_job_unauthorized(client, mock_subprocess_popen, mock_job
|
||||||
assert response.json().get("data") is None
|
assert response.json().get("data") is None
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_remove_job(authorized_client, mock_subprocess_popen, mock_jobs):
|
def test_graphql_remove_job(
|
||||||
|
authorized_client, mock_subprocess_popen, mock_jobs_return_true
|
||||||
|
):
|
||||||
response = authorized_client.post(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
"query": API_REMOVE_JOB_MUTATION,
|
"query": API_REMOVE_JOB_MUTATION,
|
||||||
"variables": {
|
"variables": {
|
||||||
"job_id": "3301",
|
"Job": {
|
||||||
|
"uid": "12345",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json().get("data") is None
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue