More refactors
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from src.main import app, get_db
|
||||
from tests.base import avatar_index, client, password, username, register_user
|
||||
from tests.config.database import clear_db, override_get_db
|
||||
from tests.base import avatar_index, client, register_user, username
|
||||
from tests.config.database import clear_db
|
||||
|
||||
patched_username = "New name"
|
||||
patched_password = "New password"
|
||||
patched_avatar = "New avatar"
|
||||
patched_avatar_index = 2
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -22,7 +20,7 @@ async def test_get_current_user():
|
||||
assert response.status_code == 200
|
||||
response = response.json()
|
||||
assert response["username"] == username
|
||||
assert response["avatar"] == avatar
|
||||
assert response["avatar_index"] == avatar_index
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -40,14 +38,7 @@ async def test_patch_user():
|
||||
"""Test the patching of a user's username, password and avatar"""
|
||||
clear_db()
|
||||
|
||||
response = client.post(
|
||||
"/register",
|
||||
headers={"Content-Type": "application/json"},
|
||||
json={"username": username, "password": password, "avatar": avatar},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
token = response.json()["access_token"]
|
||||
token = await register_user()
|
||||
|
||||
headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
|
||||
|
||||
@@ -56,7 +47,7 @@ async def test_patch_user():
|
||||
json={
|
||||
"username": patched_username,
|
||||
"password": patched_password,
|
||||
"avatar": patched_avatar,
|
||||
"avatar_index": patched_avatar_index,
|
||||
},
|
||||
headers=headers,
|
||||
)
|
||||
@@ -77,7 +68,7 @@ async def test_patch_user():
|
||||
assert response.status_code == 200
|
||||
|
||||
# Correctness of password and username is already asserted by the login
|
||||
assert response.json()["avatar"] == patched_avatar
|
||||
assert response.json()["avatar_index"] == patched_avatar_index
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -85,14 +76,7 @@ async def test_patch_user_with_empty_fields():
|
||||
"""Patching a user with empty fields should fail"""
|
||||
clear_db()
|
||||
|
||||
response = client.post(
|
||||
"/register",
|
||||
headers={"Content-Type": "application/json"},
|
||||
json={"username": username, "password": password, "avatar": avatar},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
token = response.json()["access_token"]
|
||||
token = await register_user()
|
||||
|
||||
headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
|
||||
|
||||
@@ -101,18 +85,18 @@ async def test_patch_user_with_empty_fields():
|
||||
json={
|
||||
"username": patched_username,
|
||||
"password": patched_password,
|
||||
"avatar": "",
|
||||
"avatar_index": "",
|
||||
},
|
||||
headers=headers,
|
||||
)
|
||||
assert response.status_code == 400
|
||||
assert response.status_code == 422
|
||||
|
||||
response = client.patch(
|
||||
"/users",
|
||||
json={
|
||||
"username": patched_username,
|
||||
"password": "",
|
||||
"avatar": patched_avatar,
|
||||
"avatar_index": patched_avatar_index,
|
||||
},
|
||||
headers=headers,
|
||||
)
|
||||
@@ -123,7 +107,7 @@ async def test_patch_user_with_empty_fields():
|
||||
json={
|
||||
"username": "",
|
||||
"password": patched_password,
|
||||
"avatar": patched_avatar,
|
||||
"avatar_index": patched_avatar_index,
|
||||
},
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user