File size: 1,202 Bytes
d44b33d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | """Pytest fixtures: isolated temp DB/Chroma paths and a patched FastAPI test client."""
import sys
from pathlib import Path
import pytest
from fastapi.testclient import TestClient
PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from api.config import Settings
from api.main import app
@pytest.fixture
def test_settings(tmp_path) -> Settings:
return Settings(
llm_provider="ollama",
chroma_persist_directory=str(tmp_path / "chroma"),
audit_db_path=str(tmp_path / "audit.db"),
jobs_db_path=str(tmp_path / "jobs.db"),
max_file_size_mb=1,
top_k_results=3,
)
@pytest.fixture
def settings(test_settings) -> Settings:
"""Alias for audit tests that name the fixture `settings`."""
return test_settings
@pytest.fixture
def client(test_settings, monkeypatch):
monkeypatch.setattr("api.main.get_settings", lambda: test_settings)
for route_mod in ("ingest", "query", "audit", "jobs"):
monkeypatch.setattr(f"api.routes.{route_mod}.get_settings", lambda ts=test_settings: ts)
with TestClient(app) as test_client:
yield test_client
|