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.
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
"""
|
||||
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
|
||||
Reference in New Issue
Block a user