feat: endpoint GET /api/health + tests

Implémentation TDD : test écrit en premier (phase rouge), puis
app.main, app.api.health et app.api.media créés pour le faire passer.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-24 04:59:36 +02:00
parent be5c34e4f7
commit 94b971cdf3
5 changed files with 42 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
from fastapi import APIRouter
router = APIRouter()
@router.get("/health")
async def health():
return {"status": "ok"}
+3
View File
@@ -0,0 +1,3 @@
from fastapi import APIRouter
router = APIRouter()
+18
View File
@@ -0,0 +1,18 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.api.health import router as health_router
from app.api.media import router as media_router
from app.core.config import settings
app = FastAPI(title="HomeHub API", version="0.1.0")
app.add_middleware(
CORSMiddleware,
allow_origins=settings.cors_origins_list,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(health_router, prefix="/api")
app.include_router(media_router, prefix="/api/media")
+9
View File
@@ -0,0 +1,9 @@
import pytest
from httpx import AsyncClient, ASGITransport
from app.main import app
@pytest.fixture
async def client():
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as ac:
yield ac
+4
View File
@@ -0,0 +1,4 @@
async def test_health_retourne_ok(client):
response = await client.get("/api/health")
assert response.status_code == 200
assert response.json() == {"status": "ok"}