Skip to content

Commit

Permalink
Test 100% for get_user
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Bayart committed Jul 4, 2024
1 parent d909d46 commit 14079c3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/routes/test_admin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import fastapi.testclient

from src import sql_api
from .. import sql_api

def test_users__create(db_api, ox_cluster, client, log):
# At the beginning of time, database is empty, random users accepted and are admins
response = client.get("/users", auth=("useless", "useless"))
assert response.status_code == 200
assert response.json() == []

# If we GET the user, it is not found
response = client.get("/users/first_admin", auth=("useless", "useless"))
assert response.status_code == 404

response = client.post(
"/users",
json={"name": "first_admin", "password": "toto", "is_admin": True},
Expand All @@ -22,6 +27,15 @@ def test_users__create(db_api, ox_cluster, client, log):
assert response.status_code == 200
assert response.json() == [{"name": "first_admin", "uuid": uuid, "is_admin": True}]

# Check we can get the user we newly created
response = client.get("/users/first_admin", auth=("first_admin", "toto"))
assert response.status_code == 200
assert response.json() == {"name": "first_admin", "uuid": uuid, "is_admin": True}

# If we GET a user that does not exist
response = client.get("/users/nobody", auth=("first_admin", "toto"))
assert response.status_code == 404

# without auth, we got a 401 error
response = client.post(
"/users",
Expand Down

0 comments on commit 14079c3

Please sign in to comment.