Fix tests for users and highscores

This commit is contained in:
lvrossem
2023-04-17 14:52:36 -06:00
parent 3596394f3f
commit 81e9eb154b
11 changed files with 156 additions and 201 deletions

View File

@@ -8,30 +8,6 @@ patched_password = "New password"
patched_avatar_index = 2
@pytest.mark.asyncio
async def test_get_current_user():
"""Test the GET /users endpoint to get info about the current user"""
clear_db()
token = await register_user()
headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
response = client.get("/users", headers=headers)
assert response.status_code == 200
response = response.json()
assert response["username"] == username
assert response["avatar_index"] == avatar_index
@pytest.mark.asyncio
async def test_get_current_user_without_auth():
"""Getting the current user without a token should fail"""
clear_db()
response = client.get("/users", headers={"Content-Type": "application/json"})
assert response.status_code == 403
@pytest.mark.asyncio
async def test_patch_user():
@@ -64,7 +40,7 @@ async def test_patch_user():
headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
response = client.get("/users", headers=headers)
response = client.get("/saveddata", headers=headers)
assert response.status_code == 200
# Correctness of password and username is already asserted by the login
@@ -80,35 +56,38 @@ async def test_patch_user_with_empty_fields():
headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
response = client.patch(
"/users",
json={
"username": patched_username,
"password": patched_password,
"avatar_index": "",
},
headers=headers,
)
assert response.status_code == 422
response = client.patch(
"/users",
json={
"username": patched_username,
"password": "",
"avatar_index": patched_avatar_index,
},
headers=headers,
)
assert response.status_code == 400
response = client.patch(
"/users",
json={
"username": "",
"password": patched_password,
"avatar_index": patched_avatar_index,
"playtime": 0.0
},
headers=headers,
)
assert response.status_code == 400
assert response.status_code == 200
response = client.patch(
"/users",
json={
"username": username,
"password": patched_password,
"avatar_index": -1,
"playtime": 0.0
},
headers=headers,
)
assert response.status_code == 200
response = client.patch(
"/users",
json={
"username": username,
"password": "",
"avatar_index": patched_avatar_index,
"playtime": 0.0
},
headers=headers,
)
assert response.status_code == 200