"""Tests for config module.""" import pytest from src.shared.config import ( __version__, Settings, get_settings, _get_version_from_pyproject, ) class TestVersion: """Test version loading from pyproject.toml.""" def test_version_is_loaded(self): """Version should be loaded from pyproject.toml.""" assert __version__ is not None assert isinstance(__version__, str) def test_version_format(self): """Version should follow semver format.""" parts = __version__.split(".") assert len(parts) >= 2, "Version should have at least major.minor" assert all(p.isdigit() for p in parts), "Version parts should be numeric" def test_version_matches_settings(self): """Settings app_version should match module version.""" settings = get_settings() assert settings.app_version == __version__ class TestGetVersionFromPyproject: """Test the version loading function.""" def test_returns_string(self): """Should return a string version.""" version = _get_version_from_pyproject() assert isinstance(version, str) def test_returns_valid_version(self): """Should return a valid version (not 0.0.0 if file exists).""" version = _get_version_from_pyproject() # Since pyproject.toml exists, version should not be fallback assert version != "0.0.0" class TestSettings: """Test Settings configuration class.""" def test_settings_has_app_name(self): """Settings should have app_name.""" settings = get_settings() assert settings.app_name == "Core Code API" def test_settings_has_version(self): """Settings should have app_version.""" settings = get_settings() assert settings.app_version is not None def test_settings_default_host(self): """Settings should have default host.""" settings = get_settings() assert settings.host == "0.0.0.0" def test_settings_default_port(self): """Settings should have default port.""" settings = get_settings() assert settings.port == 8083 def test_no_kuma_settings(self): """Settings should not have Kuma-related attributes.""" settings = get_settings() assert not hasattr(settings, "kuma_url") assert not hasattr(settings, "kuma_username") assert not hasattr(settings, "kuma_password") assert not hasattr(settings, "kuma_api_key") class TestGetSettings: """Test get_settings function.""" def test_returns_settings_instance(self): """Should return a Settings instance.""" settings = get_settings() assert isinstance(settings, Settings) def test_returns_cached_instance(self): """Should return the same cached instance.""" settings1 = get_settings() settings2 = get_settings() assert settings1 is settings2 def test_model_aliases_property(self): """Model aliases property should return dict.""" settings = get_settings() aliases = settings.model_aliases assert isinstance(aliases, dict) assert "gpt-3.5-turbo" in aliases assert "gpt-4" in aliases