"""Tests for config module.""" import os import pytest from factsdb.config import Config, DatabaseConfig, AIEndpointConfig, FTPServerConfig, SchedulerConfig class TestDatabaseConfig: def test_default_path(self): cfg = DatabaseConfig() assert cfg.path == "./facts.db" def test_custom_path(self): cfg = DatabaseConfig(path="/tmp/test.db") assert cfg.path == "/tmp/test.db" class TestAIEndpointConfig: def test_defaults(self): cfg = AIEndpointConfig() assert cfg.url == "" assert cfg.auth_token == "" def test_custom_values(self): cfg = AIEndpointConfig(url="http://example.com", auth_token="tok") assert cfg.url == "http://example.com" assert cfg.auth_token == "tok" class TestFTPServerConfig: def test_defaults(self): cfg = FTPServerConfig() assert cfg.host == "0.0.0.0" assert cfg.port == 2121 assert cfg.username == "" assert cfg.password == "" def test_custom_values(self): cfg = FTPServerConfig(host="127.0.0.1", port=2122, username="u", password="p") assert cfg.host == "127.0.0.1" assert cfg.port == 2122 assert cfg.username == "u" assert cfg.password == "p" class TestSchedulerConfig: def test_default_interval(self): cfg = SchedulerConfig() assert cfg.interval_minutes == 10 def test_custom_interval(self): cfg = SchedulerConfig(interval_minutes=5) assert cfg.interval_minutes == 5 class TestConfig: def test_raises_missing_ai_token(self, monkeypatch): monkeypatch.delenv("AI_ENDPOINT_TOKEN", raising=False) monkeypatch.setenv("AI_ENDPOINT_URL", "http://x") monkeypatch.delenv("FTP_USERNAME", raising=False) monkeypatch.delenv("FTP_PASSWORD", raising=False) with pytest.raises(ValueError, match="AI_ENDPOINT_TOKEN"): Config() def test_raises_missing_ai_url(self, monkeypatch): monkeypatch.setenv("AI_ENDPOINT_TOKEN", "tok") monkeypatch.delenv("AI_ENDPOINT_URL", raising=False) monkeypatch.delenv("FTP_USERNAME", raising=False) monkeypatch.delenv("FTP_PASSWORD", raising=False) with pytest.raises(ValueError, match="AI_ENDPOINT_URL"): Config() def test_raises_missing_ftp_username(self, monkeypatch): monkeypatch.setenv("AI_ENDPOINT_TOKEN", "tok") monkeypatch.setenv("AI_ENDPOINT_URL", "http://x") monkeypatch.delenv("FTP_USERNAME", raising=False) monkeypatch.setenv("FTP_PASSWORD", "p") with pytest.raises(ValueError, match="FTP_USERNAME"): Config() def test_raises_missing_ftp_password(self, monkeypatch): monkeypatch.setenv("AI_ENDPOINT_TOKEN", "tok") monkeypatch.setenv("AI_ENDPOINT_URL", "http://x") monkeypatch.setenv("FTP_USERNAME", "u") monkeypatch.delenv("FTP_PASSWORD", raising=False) with pytest.raises(ValueError, match="FTP_PASSWORD"): Config() def test_full_config(self, monkeypatch, tmp_path): db_path = str(tmp_path / "test.db") monkeypatch.setenv("DATABASE_PATH", db_path) monkeypatch.setenv("AI_ENDPOINT_URL", "http://ai.test") monkeypatch.setenv("AI_ENDPOINT_TOKEN", "secret") monkeypatch.setenv("FTP_USERNAME", "user") monkeypatch.setenv("FTP_PASSWORD", "pass") monkeypatch.setenv("FTP_HOST", "127.0.0.1") monkeypatch.setenv("FTP_PORT", "2122") monkeypatch.setenv("SCHEDULER_INTERVAL", "5") cfg = Config() assert cfg.database.path == db_path assert cfg.ai_endpoint.url == "http://ai.test" assert cfg.ai_endpoint.auth_token == "secret" assert cfg.ftp_server.host == "127.0.0.1" assert cfg.ftp_server.port == 2122 assert cfg.ftp_server.username == "user" assert cfg.ftp_server.password == "pass" assert cfg.scheduler.interval_minutes == 5