Files
Imago/tests/test_versioning.py
T
bruno 2f2a5e9b4a
CI / Lint & Format (push) Failing after 28s
CI / Tests (push) Has been skipped
CI / Security Scan (push) Failing after 8s
CI / Docker Build (push) Has been skipped
Add admin panel, WebSocket support, and API versioning
Introduce an admin portal (React + Nginx), WebSocket routing, and
API versioning middleware with `/api/v1/` prefix deprecation.
Add master API key authentication, new Prometheus metrics for AI
token consumption and active WebSockets, and extend S3 config
with a public endpoint URL. Update test paths and fixtures to
align with the new routing structure.
2026-06-22 11:25:22 -04:00

65 lines
2.2 KiB
Python

"""
Tests pour vérifier le versionnement de l'API (Middleware & router prefix).
"""
import pytest
from httpx import AsyncClient, ASGITransport
from app.main import app as main_app
@pytest.mark.asyncio
async def test_api_v1_headers():
"""
Vérifie que les requêtes sous /api/v1/ renvoient bien l'entête X-API-Version.
"""
async with AsyncClient(
transport=ASGITransport(app=main_app), base_url="http://testserver"
) as client:
# On teste une route qui retourne typiquement un 401 ou 422
# mais on vérifie juste la présence de l'entête
response = await client.get("/api/v1/images/")
assert "x-api-version" in response.headers
assert response.headers["x-api-version"] == "v1"
@pytest.mark.asyncio
async def test_non_versioned_routes_no_header():
"""
Vérifie que les requêtes hors /api/v1/ (ex: /health) n'ont pas l'entête.
"""
async with AsyncClient(
transport=ASGITransport(app=main_app), base_url="http://testserver"
) as client:
response = await client.get("/health")
assert response.status_code == 200
assert "x-api-version" not in response.headers
@pytest.mark.asyncio
async def test_sunset_header_if_configured(monkeypatch):
"""
Vérifie que l'entête Sunset est ajouté si la config est présente.
"""
import app.middleware.versioning
# Mock settings in the versioning module
class MockSettings:
API_V1_SUNSET_DATE = "2025-12-31"
monkeypatch.setattr(app.middleware.versioning, "settings", MockSettings())
async with AsyncClient(
transport=ASGITransport(app=main_app), base_url="http://testserver"
) as client:
response = await client.get("/api/v1/images/")
assert "sunset" in response.headers
assert response.headers["sunset"] == "2025-12-31"
@pytest.mark.asyncio
async def test_deprecated_root_paths_return_404():
"""
Vérifie que l'ancienne route /images renvoie bien un 404.
"""
async with AsyncClient(
transport=ASGITransport(app=main_app), base_url="http://testserver"
) as client:
response = await client.get("/images/")
assert response.status_code == 404