The suite could not even collect: the venv was missing declared dependencies, and five tests asserted an API that had moved on. 11 collection errors to 381 passing. test_oidc.py was written for the single-issuer API and6243f29replaced it. issuer and audience became lists, jwks_uri stopped being an attribute in favour of get_jwks_uri(issuer), get_jwks became get_jwks_for_issuer, and the lru_cache became a per-issuer dict so cache_clear no longer exists. Rewritten against the current surface, with coverage added for the two behaviours the multi-issuer change introduced and never tested: is_valid_issuer rejecting an unconfigured issuer, and the cache keying per issuer. Both are security-relevant — a shared cache would serve one issuer keys for another. Three /auth/me tests asserted a path that does not exist. The route is declared as /me inside AuthController.create_router() and mounts at /auth/users/me; the generated spec is authoritative and the local app and the deployed service agree on it. Those tests had never passed. test_handles_empty_groups expected groups == [""] for an empty header. oidc.py has returned [] since the initial commit, and [] is correct — [""] would also be unsafe, since any check doing "" in groups would match. test_model_aliases_property covered Settings.model_aliases, deleted with the Ollama integration inc1f16d4. Removed rather than repaired. Co-Authored-By: Claude <noreply@anthropic.com>
95 lines
3.1 KiB
Python
95 lines
3.1 KiB
Python
"""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
|
|
|
|
# Removed: test_model_aliases_property. Settings.model_aliases mapped
|
|
# gpt-3.5-turbo and gpt-4 onto local models, and was deleted along with the
|
|
# Ollama integration in c1f16d4. The test outlived the feature it covered.
|