- 新增 brand_api 测试: 覆盖所有异常处理分支 - 新增 main.py 测试: root 和 health 端点 - 新增 logging 测试: setup_logging 和 get_logger - 新增 KolVideo __repr__ 测试 - 总计 67 个测试全部通过 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
31 lines
942 B
Python
31 lines
942 B
Python
import pytest
|
|
from httpx import AsyncClient, ASGITransport
|
|
|
|
from app.main import app
|
|
|
|
|
|
class TestMainApp:
|
|
"""Tests for main app endpoints."""
|
|
|
|
@pytest.fixture
|
|
async def client(self):
|
|
"""Create test client."""
|
|
transport = ASGITransport(app=app)
|
|
async with AsyncClient(transport=transport, base_url="http://test") as ac:
|
|
yield ac
|
|
|
|
async def test_root_endpoint(self, client):
|
|
"""Test root endpoint returns app info."""
|
|
response = await client.get("/")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["message"] == "KOL Insight API"
|
|
assert data["version"] == "1.0.0"
|
|
|
|
async def test_health_endpoint(self, client):
|
|
"""Test health check endpoint."""
|
|
response = await client.get("/health")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["status"] == "healthy"
|