new: update type hints (#64)

* new: update type hints

* fix: do not pass location and path to qdrant client, and do not accept them together

* new: update settings tests

* fix: revert removal of local path
This commit is contained in:
George
2025-06-12 00:55:07 +04:00
committed by GitHub
parent b657656363
commit 28bf298a32
6 changed files with 83 additions and 78 deletions

View File

@@ -1,5 +1,4 @@
import os
from unittest.mock import patch
import pytest
from mcp_server_qdrant.embeddings.types import EmbeddingProviderType
from mcp_server_qdrant.settings import (
@@ -18,34 +17,51 @@ class TestQdrantSettings:
# Should not raise error because there are no required fields
QdrantSettings()
@patch.dict(
os.environ,
{"QDRANT_URL": "http://localhost:6333", "COLLECTION_NAME": "test_collection"},
)
def test_minimal_config(self):
def test_minimal_config(self, monkeypatch):
"""Test loading minimal configuration from environment variables."""
monkeypatch.setenv("QDRANT_URL", "http://localhost:6333")
monkeypatch.setenv("COLLECTION_NAME", "test_collection")
settings = QdrantSettings()
assert settings.location == "http://localhost:6333"
assert settings.collection_name == "test_collection"
assert settings.api_key is None
assert settings.local_path is None
@patch.dict(
os.environ,
{
"QDRANT_URL": "http://qdrant.example.com:6333",
"QDRANT_API_KEY": "test_api_key",
"COLLECTION_NAME": "my_memories",
"QDRANT_LOCAL_PATH": "/tmp/qdrant",
},
)
def test_full_config(self):
def test_full_config(self, monkeypatch):
"""Test loading full configuration from environment variables."""
monkeypatch.setenv("QDRANT_URL", "http://qdrant.example.com:6333")
monkeypatch.setenv("QDRANT_API_KEY", "test_api_key")
monkeypatch.setenv("COLLECTION_NAME", "my_memories")
monkeypatch.setenv("QDRANT_SEARCH_LIMIT", "15")
monkeypatch.setenv("QDRANT_READ_ONLY", "1")
settings = QdrantSettings()
assert settings.location == "http://qdrant.example.com:6333"
assert settings.api_key == "test_api_key"
assert settings.collection_name == "my_memories"
assert settings.local_path == "/tmp/qdrant"
assert settings.search_limit == 15
assert settings.read_only is True
def test_local_path_config(self, monkeypatch):
"""Test loading local path configuration from environment variables."""
monkeypatch.setenv("QDRANT_LOCAL_PATH", "/path/to/local/qdrant")
settings = QdrantSettings()
assert settings.local_path == "/path/to/local/qdrant"
def test_local_path_is_exclusive_with_url(self, monkeypatch):
"""Test that local path cannot be set if Qdrant URL is provided."""
monkeypatch.setenv("QDRANT_URL", "http://localhost:6333")
monkeypatch.setenv("QDRANT_LOCAL_PATH", "/path/to/local/qdrant")
with pytest.raises(ValueError):
QdrantSettings()
monkeypatch.delenv("QDRANT_URL", raising=False)
monkeypatch.setenv("QDRANT_API_KEY", "test_api_key")
with pytest.raises(ValueError):
QdrantSettings()
class TestEmbeddingProviderSettings:
@@ -55,12 +71,9 @@ class TestEmbeddingProviderSettings:
assert settings.provider_type == EmbeddingProviderType.FASTEMBED
assert settings.model_name == "sentence-transformers/all-MiniLM-L6-v2"
@patch.dict(
os.environ,
{"EMBEDDING_MODEL": "custom_model"},
)
def test_custom_values(self):
def test_custom_values(self, monkeypatch):
"""Test loading custom values from environment variables."""
monkeypatch.setenv("EMBEDDING_MODEL", "custom_model")
settings = EmbeddingProviderSettings()
assert settings.provider_type == EmbeddingProviderType.FASTEMBED
assert settings.model_name == "custom_model"
@@ -73,35 +86,24 @@ class TestToolSettings:
assert settings.tool_store_description == DEFAULT_TOOL_STORE_DESCRIPTION
assert settings.tool_find_description == DEFAULT_TOOL_FIND_DESCRIPTION
@patch.dict(
os.environ,
{"TOOL_STORE_DESCRIPTION": "Custom store description"},
)
def test_custom_store_description(self):
def test_custom_store_description(self, monkeypatch):
"""Test loading custom store description from environment variable."""
monkeypatch.setenv("TOOL_STORE_DESCRIPTION", "Custom store description")
settings = ToolSettings()
assert settings.tool_store_description == "Custom store description"
assert settings.tool_find_description == DEFAULT_TOOL_FIND_DESCRIPTION
@patch.dict(
os.environ,
{"TOOL_FIND_DESCRIPTION": "Custom find description"},
)
def test_custom_find_description(self):
def test_custom_find_description(self, monkeypatch):
"""Test loading custom find description from environment variable."""
monkeypatch.setenv("TOOL_FIND_DESCRIPTION", "Custom find description")
settings = ToolSettings()
assert settings.tool_store_description == DEFAULT_TOOL_STORE_DESCRIPTION
assert settings.tool_find_description == "Custom find description"
@patch.dict(
os.environ,
{
"TOOL_STORE_DESCRIPTION": "Custom store description",
"TOOL_FIND_DESCRIPTION": "Custom find description",
},
)
def test_all_custom_values(self):
def test_all_custom_values(self, monkeypatch):
"""Test loading all custom values from environment variables."""
monkeypatch.setenv("TOOL_STORE_DESCRIPTION", "Custom store description")
monkeypatch.setenv("TOOL_FIND_DESCRIPTION", "Custom find description")
settings = ToolSettings()
assert settings.tool_store_description == "Custom store description"
assert settings.tool_find_description == "Custom find description"