Files
ProxyPool/tests/integration/test_health_api.py

58 lines
1.9 KiB
Python

"""健康检查 API 测试"""
import pytest
class TestHealthAPI:
"""测试健康检查端点"""
@pytest.mark.asyncio
async def test_root_endpoint(self, client):
"""测试根端点 /"""
response = await client.get("/")
assert response.status_code == 200
data = response.json()
assert "message" in data
assert "status" in data
assert data["status"] == "running"
@pytest.mark.asyncio
async def test_health_endpoint(self, client):
"""测试健康检查端点 /health"""
response = await client.get("/health")
assert response.status_code == 200
data = response.json()
assert data["status"] == "healthy"
assert "timestamp" in data
assert "database" in data
assert "scheduler" in data
assert "version" in data
@pytest.mark.asyncio
async def test_health_endpoint_structure(self, client):
"""测试健康检查端点返回结构"""
response = await client.get("/health")
data = response.json()
assert "status" in data
assert "timestamp" in data
assert "database" in data
assert "scheduler" in data
assert "version" in data
# 验证数据类型
assert isinstance(data["status"], str)
assert isinstance(data["timestamp"], str)
assert isinstance(data["database"], str)
assert isinstance(data["scheduler"], str)
assert isinstance(data["version"], str)
@pytest.mark.asyncio
async def test_404_not_found_unified_format(self, client):
"""测试 404 返回统一格式"""
response = await client.get("/api/not-exist")
assert response.status_code == 404
data = response.json()
assert data["code"] == 404
assert "message" in data
assert data["data"] is None