"""Shared test fixtures. `app_client` spins up the FastAPI app against an isolated temp SQLite DB with known auth secrets, so any test can exercise the real routes over httpx without touching the developer's database. """ import pytest from httpx import ASGITransport, AsyncClient @pytest.fixture async def app_client(tmp_path, monkeypatch): db_path = tmp_path / "test.db" monkeypatch.setenv("DATABASE_URL", f"sqlite+aiosqlite:///{db_path}") monkeypatch.setenv("JWT_SECRET", "test-jwt-secret") monkeypatch.setenv("IMPACTFLOW_API_KEY", "test-api-key") monkeypatch.setenv("GOOGLE_CLIENT_ID", "fake-client-id") monkeypatch.setenv("GOOGLE_CLIENT_SECRET", "fake-client-secret") monkeypatch.setenv("ALLOWED_EMAIL_DOMAINS", "") # Plain http test transport: non-Secure cookies so the jar replays them. monkeypatch.setenv("COOKIE_SECURE", "false") # Clear app modules so they re-read the patched env at import time. import importlib import sys for mod in list(sys.modules): if mod.startswith("app"): del sys.modules[mod] from app import database importlib.reload(database) from app.database import Base, engine from app.main import app async with engine.begin() as conn: await conn.run_sync(Base.metadata.create_all) transport = ASGITransport(app=app) async with AsyncClient( transport=transport, base_url="http://test" ) as client: yield client