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
This commit is contained in:
1 parent
357a72114b
commit
9a6f75ebd8
32 files changed
+1465
-1
No files matched your search
@@ -0,0 +1,23 @@
|
||||
"""Tests for the version endpoint."""
|
||||
|
||||
import re
|
||||
|
||||
_SEMVER = re.compile(r"^\d+\.\d+\.\d+$")
|
||||
|
||||
|
||||
def test_version_returns_200_ok(client) -> None:
|
||||
response = client.get("/api/v1/version")
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_version_response_format(client) -> None:
|
||||
payload = client.get("/api/v1/version").json()
|
||||
assert payload["app"] == "newzy"
|
||||
assert _SEMVER.match(payload["version"]), f"unexpected version format: {payload['version']}"
|
||||
|
||||
|
||||
def test_version_matches_configured_app_version(client) -> None:
|
||||
from config import APP_VERSION
|
||||
|
||||
payload = client.get("/api/v1/version").json()
|
||||
assert payload["version"] == APP_VERSION
|
||||
Reference in new issue
Block a user