feat: application Courrier V1a socle et tri du jour (tt-2026-11-059)

This commit is contained in:
gemini-ops committed 2026-11-17 12:14:55 +01:00
1 parent 0199477821
commit b51a8bba69
19 files changed
+1731 -2

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
import os
import tempfile
import pytest
from fastapi.testclient import TestClient
import jwt
# Configure test environment variables before importing app
TEST_SECRET = "secret-test-courrier-tt-2026-11-059"
os.environ["CF_TEST_SECRET"] = TEST_SECRET
os.environ["CF_ACCESS_AUD"] = "courrier-test-aud"
from app.main import app
from app.db import init_db
@pytest.fixture
def temp_db():
"""Crée une base SQLite temporaire isolée pour chaque test."""
with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as f:
db_path = f.name
init_db(db_path)
yield db_path
if os.path.exists(db_path):
os.remove(db_path)
@pytest.fixture
def valid_jwt_token():
"""Génère un jeton JWT valide pour les tests d'API."""
payload = {
"sub": "user@example.com",
"email": "user@example.com",
"aud": "courrier-test-aud",
"iss": "https://test.cloudflareaccess.com",
"exp": 9999999999
}
return jwt.encode(payload, TEST_SECRET, algorithm="HS256")
@pytest.fixture
def client(valid_jwt_token, temp_db, monkeypatch):
"""Client de test FastAPI avec injecteur d'en-tête Cloudflare Access et DB isolée."""
monkeypatch.setattr("app.config.DB_PATH", temp_db)
monkeypatch.setattr("app.db.DB_PATH", temp_db)
init_db(temp_db)
with TestClient(app) as c:
c.headers.update({"Cf-Access-Jwt-Assertion": valid_jwt_token})
yield c