import pytest from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker from app.database import Base from app.models import KolVideo @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 test_session(test_engine): """Create a test database session.""" async_session = async_sessionmaker( test_engine, class_=AsyncSession, expire_on_commit=False, ) async with async_session() as session: yield session