94 lines
2.3 KiB
Python
94 lines
2.3 KiB
Python
import pytest
|
|
|
|
from tests.base import (avatar_index, client, get_headers, register_user,
|
|
username)
|
|
from tests.config.database import clear_db
|
|
|
|
patched_username = "New name"
|
|
patched_password = "New password"
|
|
patched_avatar_index = 2
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_patch_user_should_succeed():
|
|
"""Test the patching of a user's username, password and avatar"""
|
|
clear_db()
|
|
|
|
token = await register_user()
|
|
|
|
headers = get_headers(token)
|
|
|
|
response = client.patch(
|
|
"/users",
|
|
json={
|
|
"username": patched_username,
|
|
"password": patched_password,
|
|
"avatar_index": patched_avatar_index,
|
|
},
|
|
headers=headers,
|
|
)
|
|
assert response.status_code == 200
|
|
|
|
response = client.post(
|
|
"/login",
|
|
headers=get_headers(),
|
|
json={"username": patched_username, "password": patched_password},
|
|
)
|
|
assert response.status_code == 200
|
|
|
|
token = response.json()["access_token"]
|
|
|
|
headers = get_headers(token)
|
|
|
|
response = client.get("/saveddata", headers=headers)
|
|
assert response.status_code == 200
|
|
|
|
# Correctness of password and username is already asserted by the login
|
|
assert response.json()["avatar_index"] == patched_avatar_index
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_patch_user_with_empty_fields_should_succeed():
|
|
"""Patching a user with empty fields should still succeed"""
|
|
clear_db()
|
|
|
|
token = await register_user()
|
|
|
|
headers = get_headers(token)
|
|
|
|
response = client.patch(
|
|
"/users",
|
|
json={
|
|
"username": "",
|
|
"password": patched_password,
|
|
"avatar_index": patched_avatar_index,
|
|
"playtime": 0.0,
|
|
},
|
|
headers=headers,
|
|
)
|
|
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
|