kol-insight/backend/tests/conftest.py
zfc 8fbcb72a3f feat(core): 完成 Phase 2 核心功能开发
- 实现查询API (query.py): 支持star_id/unique_id/nickname三种查询方式
- 实现计算模块 (calculator.py): CPM/自然搜索UV/搜索成本计算
- 实现品牌API集成 (brand_api.py): 批量并发调用,10并发限制
- 实现导出服务 (export_service.py): Excel/CSV导出
- 前端组件: QueryForm/ResultTable/ExportButton
- 主页面集成: 支持6种页面状态
- 测试: 44个测试全部通过,覆盖率88%

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 14:38:38 +08:00

77 lines
2.0 KiB
Python

import pytest
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
from app.database import Base, get_db
from app.models import KolVideo
from app.main import app
@pytest.fixture
def sample_video_data():
"""Sample video data for testing."""
return {
"item_id": "test_item_001",
"title": "测试视频标题",
"viral_type": "爆款",
"video_url": "https://example.com/video/001",
"star_id": "star_001",
"star_unique_id": "unique_001",
"star_nickname": "测试达人",
"natural_play_cnt": 100000,
"heated_play_cnt": 50000,
"total_play_cnt": 150000,
"total_interact": 5000,
"like_cnt": 3000,
"share_cnt": 1000,
"comment_cnt": 1000,
"new_a3_rate": 0.05,
"after_view_search_uv": 500,
"return_search_cnt": 200,
"industry_id": "ind_001",
"industry_name": "美妆",
"brand_id": "brand_001",
"estimated_video_cost": 10000.0,
}
@pytest.fixture
async def test_engine():
"""Create a test database engine using SQLite."""
engine = create_async_engine(
"sqlite+aiosqlite:///:memory:",
echo=False,
)
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
yield engine
await engine.dispose()
@pytest.fixture
async def async_session_factory(test_engine):
"""Create async session factory."""
return async_sessionmaker(
test_engine,
class_=AsyncSession,
expire_on_commit=False,
)
@pytest.fixture
async def test_session(async_session_factory):
"""Create a test database session."""
async with async_session_factory() as session:
yield session
@pytest.fixture
async def override_get_db(async_session_factory):
"""Override get_db dependency for testing."""
async def _get_db():
async with async_session_factory() as session:
yield session
app.dependency_overrides[get_db] = _get_db
yield
app.dependency_overrides.clear()