geo/backend/tests/test_api/test_platforms_routes.py

60 lines
2.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""平台API路由测试 - 验证不存在双重前缀问题"""
import pytest
import pytest_asyncio
from httpx import AsyncClient, ASGITransport
from app.main import app
class TestPlatformsRoutePrefix:
"""平台路由前缀测试"""
@pytest.mark.asyncio
async def test_platforms_endpoint_not_double_prefixed(self):
"""
验证platforms端点路径不是 /api/v1/api/*
预期:
- /api/v1/api/platforms/health 应该返回404不存在
- /api/v1/platforms/health 应该返回200正确路径
"""
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as client:
wrong_path_response = await client.get("/api/v1/api/platforms/health")
correct_path_response = await client.get("/api/v1/platforms/health")
assert wrong_path_response.status_code == 404, \
f"错误:/api/v1/api/platforms/health 返回 {wrong_path_response.status_code}应该是404说明存在双重前缀问题"
assert correct_path_response.status_code == 200, \
f"错误:/api/v1/platforms/health 返回 {correct_path_response.status_code}应该是200端点不可用"
@pytest.mark.asyncio
async def test_platforms_health_endpoint_accessible(self):
"""验证platforms健康检查端点可通过正确路径访问"""
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as client:
response = await client.get("/api/v1/platforms/health")
assert response.status_code == 200, \
f"平台健康检查端点无法访问,状态码: {response.status_code}"
data = response.json()
assert "platforms" in data
assert "total" in data
assert "configured_count" in data
@pytest.mark.asyncio
async def test_platforms_health_by_name_endpoint(self):
"""验证platforms按名称健康检查端点可通过正确路径访问"""
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as client:
response = await client.get("/api/v1/platforms/health/kimi")
assert response.status_code == 200, \
f"平台按名称健康检查端点无法访问,状态码: {response.status_code}"
data = response.json()
assert "name" in data
assert data["name"] == "kimi"