First commit
This commit is contained in:
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
0
tests/api/__init__.py
Normal file
0
tests/api/__init__.py
Normal file
20
tests/api/test_api.py
Normal file
20
tests/api/test_api.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import pytest
|
||||
from httpx import AsyncClient
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_read_root_success(test_client: AsyncClient):
|
||||
"""
|
||||
Vérifie que l'endpoint racine ("/") fonctionne et renvoie le message attendu
|
||||
"""
|
||||
# 1. Action (appel de l'API)
|
||||
response = await test_client.get("/")
|
||||
|
||||
# 2. Assertions (vérifications)
|
||||
|
||||
# Vérifie que la requête a réussi
|
||||
assert response.status_code == 200
|
||||
|
||||
# Vérifie le contenu de la réponse
|
||||
data = response.json()
|
||||
assert "fantastic" in data["message"]
|
||||
15
tests/conftest.py
Normal file
15
tests/conftest.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from typing import AsyncGenerator
|
||||
|
||||
import pytest
|
||||
from httpx import AsyncClient, ASGITransport
|
||||
|
||||
from app.main import app
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def test_client() -> AsyncGenerator[AsyncClient, None]:
|
||||
# On crée un "transport" pour l'application ASGI
|
||||
transport = ASGITransport(app=app)
|
||||
async with AsyncClient(transport=transport, base_url="http://test") as client:
|
||||
yield client
|
||||
app.dependency_overrides.clear()
|
||||
Reference in New Issue
Block a user