test(users): delete a user and CHECK that it was deleted

This commit is contained in:
Houkime 2023-12-27 14:31:50 +00:00
parent 2e775dad90
commit e7c89e3e3f
3 changed files with 42 additions and 10 deletions

View file

@ -133,6 +133,17 @@ allUsers {
"""
def api_all_users(authorized_client):
response = authorized_client.post(
"/graphql",
json={
"query": generate_users_query([API_USERS_INFO]),
},
)
output = get_data(response)["users"]["allUsers"]
return output
def test_graphql_get_users_unauthorized(client, some_users, mock_subprocess_popen):
"""Test wrong auth"""
response = client.post(
@ -543,6 +554,11 @@ def test_graphql_delete_user(authorized_client, some_users, mock_subprocess_pope
assert response.json()["data"]["users"]["deleteUser"]["message"] is not None
assert response.json()["data"]["users"]["deleteUser"]["success"] is True
new_users = api_all_users(authorized_client)
assert len(new_users) == 3
usernames = [user["username"] for user in new_users]
assert set(usernames) == set(["user2", "user3", "tester"])
@pytest.mark.parametrize("username", ["", "def"])
def test_graphql_delete_nonexistent_users(

View file

@ -111,16 +111,6 @@ def mock_subprocess_popen(mocker):
## TESTS ######################################################
# gql counterpart is too weak
def test_delete_user(authorized_client, some_users, mock_subprocess_popen):
response = authorized_client.delete("/users/user1")
assert response.status_code == 200
assert read_json(some_users / "some_users.json")["users"] == [
{"username": "user2", "hashedPassword": "HASHED_PASSWORD_2", "sshKeys": []},
{"username": "user3", "hashedPassword": "HASHED_PASSWORD_3"},
]
def test_delete_main_user(authorized_client, some_users, mock_subprocess_popen):
response = authorized_client.delete("/users/tester")
assert response.status_code == 400

26
tests/test_users.py Normal file
View file

@ -0,0 +1,26 @@
from selfprivacy_api.utils import ReadUserData, WriteUserData
from selfprivacy_api.actions.users import delete_user
"""
A place for user storage tests and other user tests that are not Graphql-specific.
"""
# yes it is an incomplete suite.
# It was born in order to not lose things that REST API tests checked for
# In the future, user storage tests that are not dependent on actual API (graphql or otherwise) go here.
def test_delete_user_writes_json(generic_userdata):
delete_user("user2")
with ReadUserData() as data:
assert data["users"] == [
{
"username": "user1",
"hashedPassword": "HASHED_PASSWORD_1",
"sshKeys": ["ssh-rsa KEY user1@pc"]
},
{
"username": "user3",
"hashedPassword": "HASHED_PASSWORD_3",
"sshKeys": ["ssh-rsa KEY user3@pc"]
}
]