theo-agent-dashboard

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

conftest.py (1596B)


      1 """Shared test fixtures."""
      2 
      3 import os
      4 import tempfile
      5 from collections.abc import AsyncIterator
      6 from pathlib import Path
      7 from unittest.mock import AsyncMock, MagicMock
      8 
      9 import pytest
     10 from httpx import ASGITransport, AsyncClient
     11 
     12 # Isolate each test from real config files
     13 os.environ.pop("THEO_CONFIG_PATH", None)
     14 
     15 from app.main import app  # noqa: E402
     16 
     17 
     18 @pytest.fixture
     19 def tmp_config_dir(tmp_path: Path) -> Path:
     20     """Temporary directory for config files."""
     21     return tmp_path
     22 
     23 
     24 @pytest.fixture
     25 def temp_db_path(tmp_path: Path) -> Path:
     26     """Path to a temporary SQLite database file."""
     27     return tmp_path / "test.db"
     28 
     29 
     30 @pytest.fixture
     31 async def test_client() -> AsyncIterator[AsyncClient]:
     32     """Async HTTP client wired to the FastAPI app."""
     33     transport = ASGITransport(app=app)
     34     async with AsyncClient(transport=transport, base_url="http://test") as client:
     35         yield client
     36 
     37 
     38 @pytest.fixture
     39 def mock_hermes_client() -> MagicMock:
     40     """Mock Hermes client with all methods as AsyncMock."""
     41     client = MagicMock()
     42     client.list_sessions = AsyncMock(return_value={"sessions": []})
     43     client.get_session = AsyncMock(return_value={})
     44     client.create_session = AsyncMock(return_value={})
     45     client.update_session = AsyncMock(return_value={})
     46     client.delete_session = AsyncMock(return_value=None)
     47     client.get_messages = AsyncMock(return_value={"messages": []})
     48     client.fork_session = AsyncMock(return_value={})
     49     client.list_models = AsyncMock(return_value={"models": []})
     50     client.health_check = AsyncMock(return_value={"status": "ok"})
     51     return client