"""Test fixtures and configuration.""" import pytest from fastapi.testclient import TestClient from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession from sqlalchemy.orm import sessionmaker from sqlmodel import SQLModel from typing import AsyncGenerator from app.main import app from app.core.database import get_session from app.core.config import settings # Test database URL (use SQLite for tests) TEST_DATABASE_URL = "sqlite+aiosqlite:///:memory:" @pytest.fixture(scope="session") def test_app(): """Get test FastAPI application.""" return app @pytest.fixture(scope="session") def client(test_app): """Get test client.""" return TestClient(test_app) @pytest.fixture async def async_engine(): """Create async engine for tests.""" engine = create_async_engine( TEST_DATABASE_URL, echo=False, future=True, ) async with engine.begin() as conn: await conn.run_sync(SQLModel.metadata.create_all) yield engine async with engine.begin() as conn: await conn.run_sync(SQLModel.metadata.drop_all) await engine.dispose() @pytest.fixture async def async_session(async_engine) -> AsyncGenerator[AsyncSession, None]: """Get async session for tests.""" async_session_maker = sessionmaker( async_engine, class_=AsyncSession, expire_on_commit=False, ) async with async_session_maker() as session: yield session @pytest.fixture def override_get_session(async_session): """Override database session dependency.""" async def _override_get_session(): yield async_session app.dependency_overrides[get_session] = _override_get_session yield app.dependency_overrides.clear()