2025-12-09 00:36:27 +08:00
|
|
|
"""
|
2025-12-11 23:25:16 +08:00
|
|
|
Strategy Service 测试
|
2025-12-09 00:36:27 +08:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
import pytest # type: ignore
|
|
|
|
|
from httpx import AsyncClient # type: ignore
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
2025-12-11 23:25:16 +08:00
|
|
|
class TestStrategyServiceHealth:
|
|
|
|
|
"""Strategy Service 健康检查测试"""
|
2025-12-09 00:36:27 +08:00
|
|
|
|
2025-12-11 23:25:16 +08:00
|
|
|
async def test_ping(self, strategy_service_client: AsyncClient) -> None:
|
2025-12-09 00:36:27 +08:00
|
|
|
"""测试 ping 接口"""
|
2025-12-11 23:25:16 +08:00
|
|
|
response = await strategy_service_client.get("/ping")
|
2025-12-09 00:36:27 +08:00
|
|
|
assert response.status_code == 200
|
|
|
|
|
data = response.json()
|
|
|
|
|
assert data["status"] == "ok"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
|
class TestStrategyRegistry:
|
|
|
|
|
"""策略注册测试"""
|
|
|
|
|
|
2025-12-11 23:25:16 +08:00
|
|
|
async def test_list_strategies(self, strategy_service_client: AsyncClient) -> None:
|
2025-12-09 00:36:27 +08:00
|
|
|
"""测试获取策略列表"""
|
2025-12-11 23:25:16 +08:00
|
|
|
response = await strategy_service_client.get("/api/v1/strategy/list")
|
2025-12-09 00:36:27 +08:00
|
|
|
assert response.status_code == 200
|
|
|
|
|
data = response.json()
|
|
|
|
|
assert "strategies" in data
|
|
|
|
|
|
|
|
|
|
async def test_get_builtin_strategies(
|
2025-12-11 23:25:16 +08:00
|
|
|
self, strategy_service_client: AsyncClient
|
2025-12-09 00:36:27 +08:00
|
|
|
) -> None:
|
|
|
|
|
"""测试获取内置策略"""
|
2025-12-11 23:25:16 +08:00
|
|
|
response = await strategy_service_client.get("/api/v1/strategy/builtin")
|
2025-12-09 00:36:27 +08:00
|
|
|
assert response.status_code == 200
|
|
|
|
|
data = response.json()
|
|
|
|
|
assert "strategies" in data
|
|
|
|
|
# 应该有内置策略
|
|
|
|
|
builtin = data["strategies"]
|
|
|
|
|
assert "grid" in builtin or "ma_cross" in builtin or "dual_ma" in builtin
|