Étape 1 : squelette du projet
- Monorepo backend/ + frontend/ + deploy/ - Backend FastAPI/SQLModel/Alembic/uv qui démarre (health check, config, i18n, base de test PostgreSQL, pytest) - docker-compose de développement (db + backend hot-reload) - Chaîne CI/CD GitHub Actions : lint + tests, build image, push GHCR, déploiement SSH sur le VPS à chaque push main - CLAUDE.md : vocabulaire du domaine, conventions, commandes Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017uUsRg7XzopkCPWimwg9ZM
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from sqlmodel import Session, SQLModel, create_engine
|
||||
|
||||
from app import models # noqa: F401 (enregistre les tables sur SQLModel.metadata)
|
||||
from app.config import get_settings
|
||||
from app.db import get_session
|
||||
from app.main import app
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def engine():
|
||||
"""Vraie base PostgreSQL de test (voir docker/postgres-init)."""
|
||||
eng = create_engine(get_settings().test_database_url, pool_pre_ping=True)
|
||||
SQLModel.metadata.create_all(eng)
|
||||
yield eng
|
||||
SQLModel.metadata.drop_all(eng)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def session(engine):
|
||||
"""Session isolée : tout est annulé à la fin du test."""
|
||||
connection = engine.connect()
|
||||
transaction = connection.begin()
|
||||
with Session(bind=connection) as s:
|
||||
yield s
|
||||
transaction.rollback()
|
||||
connection.close()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(session):
|
||||
app.dependency_overrides[get_session] = lambda: session
|
||||
with TestClient(app) as c:
|
||||
yield c
|
||||
app.dependency_overrides.clear()
|
||||
@@ -0,0 +1,13 @@
|
||||
def test_health_ok(client):
|
||||
resp = client.get("/health")
|
||||
assert resp.status_code == 200
|
||||
body = resp.json()
|
||||
assert body["status"] == "ok"
|
||||
# Message issu du catalogue de traduction, pas d'une chaîne en dur.
|
||||
assert body["message"] == "Service opérationnel"
|
||||
|
||||
|
||||
def test_health_db_ok(client):
|
||||
resp = client.get("/health/db")
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["status"] == "ok"
|
||||
@@ -0,0 +1,20 @@
|
||||
from app.i18n import t
|
||||
|
||||
|
||||
def test_known_key_is_translated():
|
||||
assert t("health.ok") == "Service opérationnel"
|
||||
|
||||
|
||||
def test_unknown_key_returns_key():
|
||||
assert t("does.not.exist") == "does.not.exist"
|
||||
|
||||
|
||||
def test_params_are_interpolated(tmp_path, monkeypatch):
|
||||
# Vérifie le mécanisme d'interpolation sans dépendre du catalogue réel.
|
||||
from app import i18n
|
||||
|
||||
i18n._catalog.cache_clear()
|
||||
monkeypatch.setattr(
|
||||
i18n, "_catalog", lambda locale: {"greet": "Bonjour {name}"}
|
||||
)
|
||||
assert i18n.t("greet", name="Festival") == "Bonjour Festival"
|
||||
Reference in New Issue
Block a user