"""Shared fixtures for FactsDB tests.""" import os import tempfile import pytest from unittest.mock import MagicMock, patch from factsdb.config import Config, DatabaseConfig, AIEndpointConfig, FTPServerConfig, SchedulerConfig @pytest.fixture def temp_db_path(): """Provide a temporary database path that's cleaned up after the test.""" with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as f: path = f.name yield path if os.path.exists(path): os.unlink(path) @pytest.fixture def mock_env_vars(): """Set required environment variables for Config initialization.""" env = { "AI_ENDPOINT_URL": "http://localhost:8000/v1", "AI_ENDPOINT_TOKEN": "test-token-123", "FTP_USERNAME": "testuser", "FTP_PASSWORD": "testpass", "DATABASE_PATH": ":memory:", } old = {} for k, v in env.items(): old[k] = os.environ.get(k) os.environ[k] = v yield env for k, v in old.items(): if v is None: os.environ.pop(k, None) else: os.environ[k] = v @pytest.fixture def config(mock_env_vars): """Provide a fully configured Config instance.""" return Config() @pytest.fixture def db_config(temp_db_path): """Provide a DatabaseConfig pointing to a temp file.""" return DatabaseConfig(path=temp_db_path) @pytest.fixture def ai_endpoint_config(): """Provide an AIEndpointConfig for testing.""" return AIEndpointConfig(url="http://localhost:8000/v1", auth_token="test-token")