change == to is

pull/12/head
def 2022-07-28 02:16:47 +02:00
parent 4f86d7c0fb
commit fb451e90a9
2 changed files with 20 additions and 15 deletions

View File

@ -7,7 +7,6 @@ from tests.common import (
) )
class ProcessMock: class ProcessMock:
"""Mock subprocess.Popen""" """Mock subprocess.Popen"""
@ -26,6 +25,7 @@ def mock_subprocess_popen(mocker):
mock = mocker.patch("subprocess.Popen", autospec=True, return_value=ProcessMock) mock = mocker.patch("subprocess.Popen", autospec=True, return_value=ProcessMock)
return mock return mock
@pytest.fixture @pytest.fixture
def some_users(mocker, datadir): def some_users(mocker, datadir):
mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "some_users.json") mocker.patch("selfprivacy_api.utils.USERDATA_FILE", new=datadir / "some_users.json")
@ -41,7 +41,6 @@ def some_users(mocker, datadir):
return datadir return datadir
# TESTS ######################################################## # TESTS ########################################################
@ -76,6 +75,7 @@ def test_graphql_add_ssh_unauthorized(client, some_users, mock_subprocess_popen)
assert response.status_code == 200 assert response.status_code == 200
assert response.json.get("data") is None assert response.json.get("data") is None
def test_graphql_add_ssh(authorized_client, some_users, mock_subprocess_popen): def test_graphql_add_ssh(authorized_client, some_users, mock_subprocess_popen):
response = authorized_client.post( response = authorized_client.post(
"/graphql", "/graphql",
@ -99,9 +99,10 @@ def test_graphql_add_ssh(authorized_client, some_users, mock_subprocess_popen):
assert response.json["data"]["createSsh"]["user"]["username"] == "user1" assert response.json["data"]["createSsh"]["user"]["username"] == "user1"
assert response.json["data"]["createSsh"]["user"]["sshKeys"] == [ assert response.json["data"]["createSsh"]["user"]["sshKeys"] == [
"ssh-rsa KEY tester@pc", "ssh-rsa KEY tester@pc",
"ssh-rsa KEY test_key@pc" "ssh-rsa KEY test_key@pc",
] ]
def test_graphql_add_root_ssh(authorized_client, some_users, mock_subprocess_popen): def test_graphql_add_root_ssh(authorized_client, some_users, mock_subprocess_popen):
response = authorized_client.post( response = authorized_client.post(
"/graphql", "/graphql",
@ -125,9 +126,10 @@ def test_graphql_add_root_ssh(authorized_client, some_users, mock_subprocess_pop
assert response.json["data"]["createSsh"]["user"]["username"] == "root" assert response.json["data"]["createSsh"]["user"]["username"] == "root"
assert response.json["data"]["createSsh"]["user"]["sshKeys"] == [ assert response.json["data"]["createSsh"]["user"]["sshKeys"] == [
"ssh-ed25519 KEY test@pc", "ssh-ed25519 KEY test@pc",
"ssh-rsa KEY test_key@pc" "ssh-rsa KEY test_key@pc",
] ]
def test_graphql_add_main_ssh(authorized_client, some_users, mock_subprocess_popen): def test_graphql_add_main_ssh(authorized_client, some_users, mock_subprocess_popen):
response = authorized_client.post( response = authorized_client.post(
"/graphql", "/graphql",
@ -151,7 +153,7 @@ def test_graphql_add_main_ssh(authorized_client, some_users, mock_subprocess_pop
assert response.json["data"]["createSsh"]["user"]["username"] == "tester" assert response.json["data"]["createSsh"]["user"]["username"] == "tester"
assert response.json["data"]["createSsh"]["user"]["sshKeys"] == [ assert response.json["data"]["createSsh"]["user"]["sshKeys"] == [
"ssh-rsa KEY tester@pc", "ssh-rsa KEY tester@pc",
"ssh-rsa KEY test_key@pc" "ssh-rsa KEY test_key@pc",
] ]
@ -211,6 +213,7 @@ mutation deleteSsh($input: SshMutationsInput!) {
} }
""" """
def test_graphql_dell_ssh_unauthorized(client, some_users, mock_subprocess_popen): def test_graphql_dell_ssh_unauthorized(client, some_users, mock_subprocess_popen):
response = client.post( response = client.post(
"/graphql", "/graphql",
@ -227,6 +230,7 @@ def test_graphql_dell_ssh_unauthorized(client, some_users, mock_subprocess_popen
assert response.status_code == 200 assert response.status_code == 200
assert response.json.get("data") is None assert response.json.get("data") is None
def test_graphql_dell_ssh(authorized_client, some_users, mock_subprocess_popen): def test_graphql_dell_ssh(authorized_client, some_users, mock_subprocess_popen):
response = authorized_client.post( response = authorized_client.post(
"/graphql", "/graphql",
@ -252,6 +256,7 @@ def test_graphql_dell_ssh(authorized_client, some_users, mock_subprocess_popen):
"ssh-rsa KEY user1@pc" "ssh-rsa KEY user1@pc"
] ]
def test_graphql_dell_root_ssh(authorized_client, some_users, mock_subprocess_popen): def test_graphql_dell_root_ssh(authorized_client, some_users, mock_subprocess_popen):
response = authorized_client.post( response = authorized_client.post(
"/graphql", "/graphql",
@ -299,6 +304,7 @@ def test_graphql_dell_main_ssh(authorized_client, some_users, mock_subprocess_po
assert response.json["data"]["deleteSsh"]["user"]["username"] == "tester" assert response.json["data"]["deleteSsh"]["user"]["username"] == "tester"
assert response.json["data"]["deleteSsh"]["user"]["sshKeys"] == [] assert response.json["data"]["deleteSsh"]["user"]["sshKeys"] == []
def test_graphql_dell_404ssh(authorized_client, some_users, mock_subprocess_popen): def test_graphql_dell_404ssh(authorized_client, some_users, mock_subprocess_popen):
response = authorized_client.post( response = authorized_client.post(
"/graphql", "/graphql",
@ -339,4 +345,3 @@ def test_graphql_dell_ssh_404user(authorized_client, some_users, mock_subprocess
assert response.json["data"]["deleteSsh"]["code"] == 404 assert response.json["data"]["deleteSsh"]["code"] == 404
assert response.json["data"]["deleteSsh"]["message"] is not None assert response.json["data"]["deleteSsh"]["message"] is not None
assert response.json["data"]["deleteSsh"]["success"] is False assert response.json["data"]["deleteSsh"]["success"] is False

View File

@ -289,7 +289,7 @@ def test_graphql_get_404user(authorized_client, one_user, mock_subprocess_popen)
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"]["users"]["getUser"] == None assert response.json["data"]["users"]["getUser"] is None
API_CHANGE_USERS_MUTATION = """ API_CHANGE_USERS_MUTATION = """
@ -396,7 +396,7 @@ def test_graphql_add_without_password(
assert response.json["data"]["createUser"]["code"] == 400 assert response.json["data"]["createUser"]["code"] == 400
assert response.json["data"]["createUser"]["success"] is False assert response.json["data"]["createUser"]["success"] is False
assert response.json["data"]["createUser"]["user"] == None assert response.json["data"]["createUser"]["user"] is None
def test_graphql_add_without_both(authorized_client, one_user, mock_subprocess_popen): def test_graphql_add_without_both(authorized_client, one_user, mock_subprocess_popen):
@ -419,7 +419,7 @@ def test_graphql_add_without_both(authorized_client, one_user, mock_subprocess_p
assert response.json["data"]["createUser"]["code"] == 400 assert response.json["data"]["createUser"]["code"] == 400
assert response.json["data"]["createUser"]["success"] is False assert response.json["data"]["createUser"]["success"] is False
assert response.json["data"]["createUser"]["user"] == None assert response.json["data"]["createUser"]["user"] is None
@pytest.mark.parametrize("username", invalid_usernames) @pytest.mark.parametrize("username", invalid_usernames)
@ -445,7 +445,7 @@ def test_graphql_add_system_username(
assert response.json["data"]["createUser"]["code"] == 409 assert response.json["data"]["createUser"]["code"] == 409
assert response.json["data"]["createUser"]["success"] is False assert response.json["data"]["createUser"]["success"] is False
assert response.json["data"]["createUser"]["user"] == None assert response.json["data"]["createUser"]["user"] is None
def test_graphql_add_existing_user(authorized_client, one_user, mock_subprocess_popen): def test_graphql_add_existing_user(authorized_client, one_user, mock_subprocess_popen):
@ -468,7 +468,7 @@ def test_graphql_add_existing_user(authorized_client, one_user, mock_subprocess_
assert response.json["data"]["createUser"]["code"] == 409 assert response.json["data"]["createUser"]["code"] == 409
assert response.json["data"]["createUser"]["success"] is False assert response.json["data"]["createUser"]["success"] is False
assert response.json["data"]["createUser"]["user"] == None assert response.json["data"]["createUser"]["user"] is None
def test_graphql_add_main_user(authorized_client, one_user, mock_subprocess_popen): def test_graphql_add_main_user(authorized_client, one_user, mock_subprocess_popen):
@ -491,7 +491,7 @@ def test_graphql_add_main_user(authorized_client, one_user, mock_subprocess_pope
assert response.json["data"]["createUser"]["code"] == 409 assert response.json["data"]["createUser"]["code"] == 409
assert response.json["data"]["createUser"]["success"] is False assert response.json["data"]["createUser"]["success"] is False
assert response.json["data"]["createUser"]["user"] == None assert response.json["data"]["createUser"]["user"] is None
def test_graphql_add_long_username(authorized_client, one_user, mock_subprocess_popen): def test_graphql_add_long_username(authorized_client, one_user, mock_subprocess_popen):
@ -514,7 +514,7 @@ def test_graphql_add_long_username(authorized_client, one_user, mock_subprocess_
assert response.json["data"]["createUser"]["code"] == 400 assert response.json["data"]["createUser"]["code"] == 400
assert response.json["data"]["createUser"]["success"] is False assert response.json["data"]["createUser"]["success"] is False
assert response.json["data"]["createUser"]["user"] == None assert response.json["data"]["createUser"]["user"] is None
@pytest.mark.parametrize("username", ["", "1", "фыр", "user1@", "^-^"]) @pytest.mark.parametrize("username", ["", "1", "фыр", "user1@", "^-^"])
@ -540,7 +540,7 @@ def test_graphql_add_invalid_username(
assert response.json["data"]["createUser"]["code"] == 400 assert response.json["data"]["createUser"]["code"] == 400
assert response.json["data"]["createUser"]["success"] is False assert response.json["data"]["createUser"]["success"] is False
assert response.json["data"]["createUser"]["user"] == None assert response.json["data"]["createUser"]["user"] is None
API_DELETE_USERS_MUTATION = """ API_DELETE_USERS_MUTATION = """
@ -718,5 +718,5 @@ def test_graphql_update_404user(authorized_client, some_users, mock_subprocess_p
assert response.json["data"]["updateUser"]["message"] is not None assert response.json["data"]["updateUser"]["message"] is not None
assert response.json["data"]["updateUser"]["success"] is False assert response.json["data"]["updateUser"]["success"] is False
assert response.json["data"]["updateUser"]["user"] == None assert response.json["data"]["updateUser"]["user"] is None
assert mock_subprocess_popen.call_count == 1 assert mock_subprocess_popen.call_count == 1