/
EastW
/
Reiai-python-FastAPI
Обзор
Документация
Войти
/
EastW
/
Reiai-python-FastAPI
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
tests/test_users.py
38 строк
1 KB
Dennis Mattews
code refactoring and updates
19 окт 2024, 05:44
19 окт 2024, 05:44
35c458d
Код
Авторство
О чём код?
import pytest from httpx import AsyncClient from api.main import app @pytest.fixture async def client(): async with AsyncClient(app=app, base_url="http://test") as ac: yield ac @pytest.mark.asyncio async def test_register_user(client: AsyncClient): response = await client.post("/api/v1/users/register", json={"username": "testuser", "password": "testpass"}) assert response.status_code == 200 data = response.json() assert data["username"] == "testuser" @pytest.mark.asyncio async def test_login_user(client: AsyncClient): await client.post("/api/v1/users/register", json={"username": "testuser", "password": "testpass"}) response = await client.post("/api/v1/users/login", json={"username": "testuser", "password": "testpass"}) assert response.status_code == 200 data = response.json() assert data["message"] == "Login successful" @pytest.mark.asyncio async def test_register_existing_user(client: AsyncClient): # Регистрируем нового пользователя await client.post("/api/v1/users/register", json={"username": "testuser", "password": "testpass"}) # Попытка повторной регистрации response = await client.post("/api/v1/users/register", json={"username": "testuser", "password": "testpass"}) assert response.status_code == 400 data = response.json() assert data["detail"] == "Username already registered"