This commit is contained in:
Ubuntu
2026-01-31 15:55:22 +00:00
parent 833eb21c79
commit 3c71d5da0a
6 changed files with 355 additions and 225 deletions

View File

@@ -9,7 +9,7 @@ from aegis_gitea_mcp.config import Settings, get_settings, reset_settings
def test_settings_from_env(mock_env: None) -> None:
"""Test loading settings from environment variables."""
settings = get_settings()
assert settings.gitea_base_url == "https://gitea.example.com"
assert settings.gitea_token == "test-token-12345"
assert settings.mcp_host == "0.0.0.0"
@@ -21,9 +21,9 @@ def test_settings_defaults(monkeypatch: pytest.MonkeyPatch) -> None:
"""Test default values when not specified."""
monkeypatch.setenv("GITEA_URL", "https://gitea.example.com")
monkeypatch.setenv("GITEA_TOKEN", "test-token")
settings = get_settings()
assert settings.mcp_host == "0.0.0.0"
assert settings.mcp_port == 8080
assert settings.log_level == "INFO"
@@ -31,13 +31,18 @@ def test_settings_defaults(monkeypatch: pytest.MonkeyPatch) -> None:
assert settings.request_timeout_seconds == 30
def test_settings_validation_missing_required(monkeypatch: pytest.MonkeyPatch) -> None:
def test_settings_validation_missing_required(monkeypatch: pytest.MonkeyPatch, tmp_path) -> None:
"""Test that missing required fields raise validation errors."""
import os
monkeypatch.delenv("GITEA_URL", raising=False)
monkeypatch.delenv("GITEA_TOKEN", raising=False)
# Change to tmp directory so .env file won't be found
monkeypatch.chdir(tmp_path)
reset_settings()
with pytest.raises(ValidationError):
get_settings()
@@ -47,9 +52,9 @@ def test_settings_invalid_log_level(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("GITEA_URL", "https://gitea.example.com")
monkeypatch.setenv("GITEA_TOKEN", "test-token")
monkeypatch.setenv("LOG_LEVEL", "INVALID")
reset_settings()
with pytest.raises(ValidationError):
get_settings()
@@ -58,9 +63,9 @@ def test_settings_empty_token(monkeypatch: pytest.MonkeyPatch) -> None:
"""Test that empty tokens are rejected."""
monkeypatch.setenv("GITEA_URL", "https://gitea.example.com")
monkeypatch.setenv("GITEA_TOKEN", " ")
reset_settings()
with pytest.raises(ValidationError):
get_settings()
@@ -69,5 +74,5 @@ def test_settings_singleton() -> None:
"""Test that get_settings returns same instance."""
settings1 = get_settings()
settings2 = get_settings()
assert settings1 is settings2