Migrate to package

This commit is contained in:
2026-03-02 17:44:18 +00:00
parent 3e2386b9b6
commit 8dfd2048a5
13 changed files with 356 additions and 31 deletions

56
tests/test_config.py Normal file
View File

@@ -0,0 +1,56 @@
"""Tests for configuration management."""
import os
import pytest
from pydantic import ValidationError
from knowledge_search_mcp.config import Settings
def test_settings_from_env():
"""Test that Settings can be loaded from environment variables."""
# Environment is set by conftest.py fixture
settings = Settings.model_validate({})
assert settings.project_id == "test-project"
assert settings.location == "us-central1"
assert settings.bucket == "test-bucket"
assert settings.index_name == "test-index"
assert settings.deployed_index_id == "test-deployed-index"
def test_settings_defaults():
"""Test that Settings has correct default values."""
settings = Settings.model_validate({})
assert settings.embedding_model == "gemini-embedding-001"
assert settings.search_limit == 10
assert settings.log_name == "va_agent_evaluation_logs"
assert settings.log_level == "INFO"
def test_settings_custom_values(monkeypatch):
"""Test that Settings can be customized via environment."""
monkeypatch.setenv("EMBEDDING_MODEL", "custom-embedding-model")
monkeypatch.setenv("SEARCH_LIMIT", "20")
monkeypatch.setenv("LOG_LEVEL", "DEBUG")
settings = Settings.model_validate({})
assert settings.embedding_model == "custom-embedding-model"
assert settings.search_limit == 20
assert settings.log_level == "DEBUG"
def test_settings_validation_error():
"""Test that Settings raises ValidationError when required fields are missing."""
# Clear all env vars temporarily
required_vars = [
"PROJECT_ID", "LOCATION", "BUCKET", "INDEX_NAME",
"DEPLOYED_INDEX_ID", "ENDPOINT_NAME", "ENDPOINT_DOMAIN"
]
# This should work with conftest fixture
settings = Settings.model_validate({})
assert settings.project_id == "test-project"