Refactoring: auth tests pass
This commit is contained in:
@@ -2,22 +2,10 @@ import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from src.main import app, get_db
|
||||
from tests.base import avatar, client, password, username
|
||||
from tests.base import avatar_index, client, password, username, register_user
|
||||
from tests.config.database import clear_db, override_get_db
|
||||
|
||||
|
||||
async def register_user():
|
||||
response = client.post(
|
||||
"/register",
|
||||
headers={"Content-Type": "application/json"},
|
||||
json={"username": username, "password": password, "avatar": avatar},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
return response.json()["access_token"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_register():
|
||||
"""Test the register endpoint"""
|
||||
@@ -26,7 +14,7 @@ async def test_register():
|
||||
response = client.post(
|
||||
"/register",
|
||||
headers={"Content-Type": "application/json"},
|
||||
json={"username": username, "password": password, "avatar": avatar},
|
||||
json={"username": username, "password": password, "avatar_index": avatar_index},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
@@ -42,7 +30,7 @@ async def test_register_duplicate_name_should_fail():
|
||||
response = client.post(
|
||||
"/register",
|
||||
headers={"Content-Type": "application/json"},
|
||||
json={"username": username, "password": password, "avatar": avatar},
|
||||
json={"username": username, "password": password, "avatar_index": avatar_index},
|
||||
)
|
||||
|
||||
assert response.status_code == 400
|
||||
@@ -57,7 +45,7 @@ async def test_register_without_username_should_fail():
|
||||
response = client.post(
|
||||
"/register",
|
||||
headers={"Content-Type": "application/json"},
|
||||
json={"password": password, "avatar": avatar},
|
||||
json={"password": password, "avatar_index": avatar_index},
|
||||
)
|
||||
|
||||
assert response.status_code == 422
|
||||
@@ -72,7 +60,7 @@ async def test_register_without_password_should_fail():
|
||||
response = client.post(
|
||||
"/register",
|
||||
headers={"Content-Type": "application/json"},
|
||||
json={"username": username, "avatar": avatar},
|
||||
json={"username": username, "avatar_index": avatar_index},
|
||||
)
|
||||
|
||||
assert response.status_code == 422
|
||||
|
||||
Reference in New Issue
Block a user