From 94b971cdf3982c01688ceb479cafb31e6de66680 Mon Sep 17 00:00:00 2001 From: Gilles Soulier Date: Sun, 24 May 2026 04:59:36 +0200 Subject: [PATCH] feat: endpoint GET /api/health + tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- backend/app/api/health.py | 8 ++++++++ backend/app/api/media.py | 3 +++ backend/app/main.py | 18 ++++++++++++++++++ backend/tests/conftest.py | 9 +++++++++ backend/tests/test_health.py | 4 ++++ 5 files changed, 42 insertions(+) create mode 100644 backend/app/api/health.py create mode 100644 backend/app/api/media.py create mode 100644 backend/app/main.py create mode 100644 backend/tests/conftest.py create mode 100644 backend/tests/test_health.py diff --git a/backend/app/api/health.py b/backend/app/api/health.py new file mode 100644 index 0000000..b992325 --- /dev/null +++ b/backend/app/api/health.py @@ -0,0 +1,8 @@ +from fastapi import APIRouter + +router = APIRouter() + + +@router.get("/health") +async def health(): + return {"status": "ok"} diff --git a/backend/app/api/media.py b/backend/app/api/media.py new file mode 100644 index 0000000..af9233c --- /dev/null +++ b/backend/app/api/media.py @@ -0,0 +1,3 @@ +from fastapi import APIRouter + +router = APIRouter() diff --git a/backend/app/main.py b/backend/app/main.py new file mode 100644 index 0000000..cf7a5ca --- /dev/null +++ b/backend/app/main.py @@ -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") diff --git a/backend/tests/conftest.py b/backend/tests/conftest.py new file mode 100644 index 0000000..d062391 --- /dev/null +++ b/backend/tests/conftest.py @@ -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 diff --git a/backend/tests/test_health.py b/backend/tests/test_health.py new file mode 100644 index 0000000..4985e3d --- /dev/null +++ b/backend/tests/test_health.py @@ -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"}