Files
life-echo/api/tests/test_main_app_smoke.py

31 lines
1.0 KiB
Python
Raw Permalink Normal View History

"""Production FastAPI app smoke tests (handlers + middleware + routers)."""
from __future__ import annotations
import pytest
from httpx import ASGITransport, AsyncClient
from app.main import app
@pytest.mark.asyncio
async def test_main_app_health() -> None:
transport = ASGITransport(app=app, raise_app_exceptions=False)
async with AsyncClient(transport=transport, base_url="http://test") as client:
r = await client.get("/health")
assert r.status_code == 200
assert r.json() == {"status": "ok"}
@pytest.mark.asyncio
async def test_main_app_unauthenticated_conversations_401() -> None:
transport = ASGITransport(app=app, raise_app_exceptions=False)
async with AsyncClient(transport=transport, base_url="http://test") as client:
r = await client.get("/api/conversations")
assert r.status_code == 401
body = r.json()
assert body["error_code"] == "AUTHENTICATION_FAILED"
assert "request_id" in body
assert r.headers.get("x-request-id")
assert r.headers.get("www-authenticate") == "Bearer"