57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
"""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"
|