Project started 🍾

This commit is contained in:
2026-06-01 18:47:59 +03:00
commit 4bca90a50e
39 changed files with 2340 additions and 0 deletions
View File
+28
View File
@@ -0,0 +1,28 @@
"""Shared test fixtures.
The ASGI app is driven in-process via httpx + asgi-lifespan (no network, no
running server). DB/Redis-backed integration fixtures arrive with the data
layer (plan §11 step 2).
"""
import os
from collections.abc import AsyncIterator
import pytest
from asgi_lifespan import LifespanManager
from httpx import ASGITransport, AsyncClient
# Force a test-safe environment before settings load.
os.environ.setdefault("ENVIRONMENT", "test")
os.environ.setdefault("JWT_SECRET", "test-secret")
@pytest.fixture
async def client() -> AsyncIterator[AsyncClient]:
from app.main import create_app
app = create_app()
async with LifespanManager(app):
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
yield ac
+22
View File
@@ -0,0 +1,22 @@
"""Smoke tests for the health endpoints."""
from httpx import AsyncClient
async def test_liveness_ok(client: AsyncClient) -> None:
resp = await client.get("/health")
assert resp.status_code == 200
assert resp.json() == {"status": "ok"}
async def test_correlation_id_echoed(client: AsyncClient) -> None:
resp = await client.get("/health", headers={"X-Correlation-Id": "abc123"})
assert resp.headers.get("x-correlation-id") == "abc123"
async def test_readiness_reports_checks(client: AsyncClient) -> None:
# No DB/Redis running in unit env → degraded, but the contract holds.
resp = await client.get("/health/ready")
body = resp.json()
assert set(body["checks"]) == {"database", "redis", "ml"}
assert body["status"] in {"ready", "degraded"}