"""Tests for configuration and SQL loading.""" from app.config import SQL_DIR, Settings, load_sql class TestSettings: """Tests for the Settings class.""" def test_default_values(self): s = Settings() assert s.POSTGRES_HOST in ("localhost", s.POSTGRES_HOST) assert s.POSTGRES_PORT == int(s.POSTGRES_PORT) assert s.K_FACTOR > 0 assert s.DEFAULT_ELO > 0 def test_database_url_format(self): s = Settings() url = s.database_url assert url.startswith("postgresql+psycopg2://") assert str(s.POSTGRES_HOST) in url class TestLoadSql: """Tests for the SQL file loader.""" def test_sql_dir_exists(self): assert SQL_DIR.is_dir() def test_all_sql_files_exist(self): expected = [ "listing_select.sql", "recent_pairs.sql", "history.sql", "count_comparisons.sql", "count_rated.sql", "count_listings.sql", "elo_aggregates.sql", "elo_distribution.sql", "listing_images.sql", ] for name in expected: assert (SQL_DIR / name).is_file(), f"Missing SQL file: {name}" def test_load_sql_substitutes_schemas(self): sql = load_sql("listing_select.sql") # Should not contain any unresolved placeholders assert "{" not in sql assert "}" not in sql def test_load_sql_returns_string(self): sql = load_sql("count_comparisons.sql") assert isinstance(sql, str) assert "count" in sql.lower()