More refactoring

This commit is contained in:
lvrossem
2023-04-18 02:52:26 -06:00
parent d074074b03
commit 3968dfd4eb
10 changed files with 156 additions and 64 deletions

View File

@@ -1,17 +1,18 @@
import pytest
from tests.base import avatar_index, client, password, register_user, username
from tests.base import (avatar_index, client, get_headers, password,
register_user, username)
from tests.config.database import clear_db
@pytest.mark.asyncio
async def test_register():
async def test_register_should_succeed():
"""Test the register endpoint"""
clear_db()
response = client.post(
"/register",
headers={"Content-Type": "application/json"},
headers=get_headers(),
json={"username": username, "password": password, "avatar_index": avatar_index},
)
@@ -27,7 +28,7 @@ async def test_register_duplicate_name_should_fail():
response = client.post(
"/register",
headers={"Content-Type": "application/json"},
headers=get_headers(),
json={"username": username, "password": password, "avatar_index": avatar_index},
)
@@ -42,7 +43,7 @@ async def test_register_without_username_should_fail():
response = client.post(
"/register",
headers={"Content-Type": "application/json"},
headers=get_headers(),
json={"password": password, "avatar_index": avatar_index},
)
@@ -57,7 +58,7 @@ async def test_register_without_password_should_fail():
response = client.post(
"/register",
headers={"Content-Type": "application/json"},
headers=get_headers(),
json={"username": username, "avatar_index": avatar_index},
)
@@ -72,7 +73,7 @@ async def test_register_without_avatar_should_fail():
response = client.post(
"/register",
headers={"Content-Type": "application/json"},
headers=get_headers(),
json={"username": username, "password": password},
)
@@ -81,14 +82,14 @@ async def test_register_without_avatar_should_fail():
@pytest.mark.asyncio
async def test_login():
async def test_login_should_succeed():
"""Test the login endpoint"""
clear_db()
await register_user()
response = client.post(
"/login",
headers={"Content-Type": "application/json"},
headers=get_headers(),
json={"username": username, "password": password},
)
@@ -104,7 +105,7 @@ async def test_login_wrong_password_should_fail():
wrong_password = password + "extra characters"
response = client.post(
"/login",
headers={"Content-Type": "application/json"},
headers=get_headers(),
json={"username": username, "password": wrong_password},
)
@@ -120,7 +121,7 @@ async def test_login_without_username_should_fail():
response = client.post(
"/login",
headers={"Content-Type": "application/json"},
headers=get_headers(),
json={"password": password},
)
@@ -136,7 +137,7 @@ async def test_login_without_password_should_fail():
response = client.post(
"/login",
headers={"Content-Type": "application/json"},
headers=get_headers(),
json={"username": username},
)