Files
Daniel Samson 9a6f75ebd8 feat: add FastAPI backend with SQLite models and Docker setup
Implement milestone M2 (backend setup):

- FastAPI app factory (core/app.py) with CORS, lifespan table
  creation, and global error handlers using a standardized
  {detail, code, errors?} envelope
- Endpoints: GET /health, GET /api/v1/health, GET /api/v1/version
- SQLAlchemy 2.0 ORM: Article, Author, Category models with
  relationships, unique constraints, and FK pragma for SQLite
- Pydantic v2 schemas (create/update/read) for all models
- Env-driven config (DATABASE_URL, CORS_ORIGINS) + .env.example
- pytest suite (19 tests, ~95% coverage) with per-test SQLite
  databases via fixtures
- Dockerfile (python:3.11-slim) and docker-compose.yml with a
  persistent ./data/db volume and healthcheck
2026-10-30 12:44:54 +00:00

30 lines
930 B
Python

"""Tests for the health check endpoints."""
def test_health_returns_200_ok(client) -> None:
response = client.get("/health")
assert response.status_code == 200
def test_health_returns_expected_json_structure(client) -> None:
payload = client.get("/health").json()
assert payload["status"] == "ok"
assert "version" in payload
def test_api_v1_health_returns_200_ok(client) -> None:
"""The alternative health path ``/api/v1/health`` must behave the same."""
response = client.get("/api/v1/health")
assert response.status_code == 200
payload = response.json()
assert payload["status"] == "ok"
assert "version" in payload
def test_unknown_route_returns_standardized_error(client) -> None:
response = client.get("/api/v1/does-not-exist")
assert response.status_code == 404
payload = response.json()
assert payload["code"] == "not_found"
assert "detail" in payload