51feae55ba
- 后端:FastAPI + SQLAlchemy + Alembic,7 张核心表迁移成功 - 前端:Next.js 16 + TailwindCSS 4 + 三端布局(投资人/创始人/Admin) - 数据库:PostgreSQL 16,7 张核心实体表(tenants/users/companies/monthly_reports/health_scores/risk_events/audit_logs) - Docker:docker-compose.yml + 前后端 Dockerfile - 测试:健康检查 4 个测试全部 GREEN - 文档:README/run.md/AGENTS.md/docs 体系完整
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
"""健康检查端点测试。"""
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from app.main import app
|
|
|
|
|
|
@pytest.fixture
|
|
def client():
|
|
"""创建测试客户端。"""
|
|
return TestClient(app)
|
|
|
|
|
|
class TestHealthCheck:
|
|
"""健康检查测试。"""
|
|
|
|
def test_health_returns_ok(self, client: TestClient):
|
|
"""RED: 健康检查应返回 200 和 status=ok。"""
|
|
response = client.get("/health")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["status"] == "ok"
|
|
assert data["service"] == "aiportpilot-backend"
|
|
|
|
def test_health_returns_version(self, client: TestClient):
|
|
"""RED: 健康检查应返回版本号。"""
|
|
response = client.get("/health")
|
|
data = response.json()
|
|
assert "version" in data
|
|
|
|
def test_trace_id_in_response_header(self, client: TestClient):
|
|
"""RED: 响应头应包含 X-Trace-Id。"""
|
|
response = client.get("/health")
|
|
assert "X-Trace-Id" in response.headers
|
|
|
|
def test_trace_id_echoed_from_request(self, client: TestClient):
|
|
"""RED: 请求头传入的 trace_id 应在响应头中原样返回。"""
|
|
custom_trace_id = "test-trace-12345"
|
|
response = client.get("/health", headers={"X-Trace-Id": custom_trace_id})
|
|
assert response.headers["X-Trace-Id"] == custom_trace_id
|