46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
|
|
"""
|
|||
|
|
Gateway 服务测试
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
import pytest # type: ignore
|
|||
|
|
from httpx import AsyncClient # type: ignore
|
|||
|
|
|
|||
|
|
|
|||
|
|
@pytest.mark.asyncio
|
|||
|
|
class TestGatewayHealth:
|
|||
|
|
"""Gateway 健康检查测试"""
|
|||
|
|
|
|||
|
|
async def test_ping(self, gateway_client: AsyncClient) -> None:
|
|||
|
|
"""测试 ping 接口"""
|
|||
|
|
response = await gateway_client.get("/ping")
|
|||
|
|
assert response.status_code == 200
|
|||
|
|
data = response.json()
|
|||
|
|
assert data["status"] == "ok"
|
|||
|
|
|
|||
|
|
async def test_health(self, gateway_client: AsyncClient) -> None:
|
|||
|
|
"""测试 health 接口"""
|
|||
|
|
response = await gateway_client.get("/health")
|
|||
|
|
assert response.status_code == 200
|
|||
|
|
data = response.json()
|
|||
|
|
assert data["status"] == "healthy"
|
|||
|
|
assert data["service"] == "gateway"
|
|||
|
|
|
|||
|
|
|
|||
|
|
@pytest.mark.asyncio
|
|||
|
|
class TestGatewayMarket:
|
|||
|
|
"""Gateway 行情接口测试"""
|
|||
|
|
|
|||
|
|
async def test_get_tick(self, gateway_client: AsyncClient) -> None:
|
|||
|
|
"""测试获取 Tick"""
|
|||
|
|
response = await gateway_client.get("/api/v1/market/tick/000001.SZ")
|
|||
|
|
# 可能返回 200 或 503(服务不可用)
|
|||
|
|
assert response.status_code in [200, 503]
|
|||
|
|
|
|||
|
|
async def test_get_kline(self, gateway_client: AsyncClient) -> None:
|
|||
|
|
"""测试获取 K 线"""
|
|||
|
|
response = await gateway_client.get(
|
|||
|
|
"/api/v1/market/kline/000001.SZ",
|
|||
|
|
params={"period": "1d", "count": 10},
|
|||
|
|
)
|
|||
|
|
assert response.status_code in [200, 503]
|