Document-Audit-RAG / tests /conftest.py
Mayank Chugh
Deploy DocuAudit AI to Hugging Face Space (no binaries)
d44b33d
"""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