1
- import os
2
- from unittest .mock import patch
1
+ import pytest
3
2
4
3
from mcp_server_qdrant .embeddings .types import EmbeddingProviderType
5
4
from mcp_server_qdrant .settings import (
@@ -18,34 +17,51 @@ def test_default_values(self):
18
17
# Should not raise error because there are no required fields
19
18
QdrantSettings ()
20
19
21
- @patch .dict (
22
- os .environ ,
23
- {"QDRANT_URL" : "http://localhost:6333" , "COLLECTION_NAME" : "test_collection" },
24
- )
25
- def test_minimal_config (self ):
20
+ def test_minimal_config (self , monkeypatch ):
26
21
"""Test loading minimal configuration from environment variables."""
22
+ monkeypatch .setenv ("QDRANT_URL" , "http://localhost:6333" )
23
+ monkeypatch .setenv ("COLLECTION_NAME" , "test_collection" )
24
+
27
25
settings = QdrantSettings ()
28
26
assert settings .location == "http://localhost:6333"
29
27
assert settings .collection_name == "test_collection"
30
28
assert settings .api_key is None
31
29
assert settings .local_path is None
32
30
33
- @patch .dict (
34
- os .environ ,
35
- {
36
- "QDRANT_URL" : "http://qdrant.example.com:6333" ,
37
- "QDRANT_API_KEY" : "test_api_key" ,
38
- "COLLECTION_NAME" : "my_memories" ,
39
- "QDRANT_LOCAL_PATH" : "/tmp/qdrant" ,
40
- },
41
- )
42
- def test_full_config (self ):
31
+ def test_full_config (self , monkeypatch ):
43
32
"""Test loading full configuration from environment variables."""
33
+ monkeypatch .setenv ("QDRANT_URL" , "http://qdrant.example.com:6333" )
34
+ monkeypatch .setenv ("QDRANT_API_KEY" , "test_api_key" )
35
+ monkeypatch .setenv ("COLLECTION_NAME" , "my_memories" )
36
+ monkeypatch .setenv ("QDRANT_SEARCH_LIMIT" , "15" )
37
+ monkeypatch .setenv ("QDRANT_READ_ONLY" , "1" )
38
+
44
39
settings = QdrantSettings ()
45
40
assert settings .location == "http://qdrant.example.com:6333"
46
41
assert settings .api_key == "test_api_key"
47
42
assert settings .collection_name == "my_memories"
48
- assert settings .local_path == "/tmp/qdrant"
43
+ assert settings .search_limit == 15
44
+ assert settings .read_only is True
45
+
46
+ def test_local_path_config (self , monkeypatch ):
47
+ """Test loading local path configuration from environment variables."""
48
+ monkeypatch .setenv ("QDRANT_LOCAL_PATH" , "/path/to/local/qdrant" )
49
+
50
+ settings = QdrantSettings ()
51
+ assert settings .local_path == "/path/to/local/qdrant"
52
+
53
+ def test_local_path_is_exclusive_with_url (self , monkeypatch ):
54
+ """Test that local path cannot be set if Qdrant URL is provided."""
55
+ monkeypatch .setenv ("QDRANT_URL" , "http://localhost:6333" )
56
+ monkeypatch .setenv ("QDRANT_LOCAL_PATH" , "/path/to/local/qdrant" )
57
+
58
+ with pytest .raises (ValueError ):
59
+ QdrantSettings ()
60
+
61
+ monkeypatch .delenv ("QDRANT_URL" , raising = False )
62
+ monkeypatch .setenv ("QDRANT_API_KEY" , "test_api_key" )
63
+ with pytest .raises (ValueError ):
64
+ QdrantSettings ()
49
65
50
66
51
67
class TestEmbeddingProviderSettings :
@@ -55,12 +71,9 @@ def test_default_values(self):
55
71
assert settings .provider_type == EmbeddingProviderType .FASTEMBED
56
72
assert settings .model_name == "sentence-transformers/all-MiniLM-L6-v2"
57
73
58
- @patch .dict (
59
- os .environ ,
60
- {"EMBEDDING_MODEL" : "custom_model" },
61
- )
62
- def test_custom_values (self ):
74
+ def test_custom_values (self , monkeypatch ):
63
75
"""Test loading custom values from environment variables."""
76
+ monkeypatch .setenv ("EMBEDDING_MODEL" , "custom_model" )
64
77
settings = EmbeddingProviderSettings ()
65
78
assert settings .provider_type == EmbeddingProviderType .FASTEMBED
66
79
assert settings .model_name == "custom_model"
@@ -73,35 +86,24 @@ def test_default_values(self):
73
86
assert settings .tool_store_description == DEFAULT_TOOL_STORE_DESCRIPTION
74
87
assert settings .tool_find_description == DEFAULT_TOOL_FIND_DESCRIPTION
75
88
76
- @patch .dict (
77
- os .environ ,
78
- {"TOOL_STORE_DESCRIPTION" : "Custom store description" },
79
- )
80
- def test_custom_store_description (self ):
89
+ def test_custom_store_description (self , monkeypatch ):
81
90
"""Test loading custom store description from environment variable."""
91
+ monkeypatch .setenv ("TOOL_STORE_DESCRIPTION" , "Custom store description" )
82
92
settings = ToolSettings ()
83
93
assert settings .tool_store_description == "Custom store description"
84
94
assert settings .tool_find_description == DEFAULT_TOOL_FIND_DESCRIPTION
85
95
86
- @patch .dict (
87
- os .environ ,
88
- {"TOOL_FIND_DESCRIPTION" : "Custom find description" },
89
- )
90
- def test_custom_find_description (self ):
96
+ def test_custom_find_description (self , monkeypatch ):
91
97
"""Test loading custom find description from environment variable."""
98
+ monkeypatch .setenv ("TOOL_FIND_DESCRIPTION" , "Custom find description" )
92
99
settings = ToolSettings ()
93
100
assert settings .tool_store_description == DEFAULT_TOOL_STORE_DESCRIPTION
94
101
assert settings .tool_find_description == "Custom find description"
95
102
96
- @patch .dict (
97
- os .environ ,
98
- {
99
- "TOOL_STORE_DESCRIPTION" : "Custom store description" ,
100
- "TOOL_FIND_DESCRIPTION" : "Custom find description" ,
101
- },
102
- )
103
- def test_all_custom_values (self ):
103
+ def test_all_custom_values (self , monkeypatch ):
104
104
"""Test loading all custom values from environment variables."""
105
+ monkeypatch .setenv ("TOOL_STORE_DESCRIPTION" , "Custom store description" )
106
+ monkeypatch .setenv ("TOOL_FIND_DESCRIPTION" , "Custom find description" )
105
107
settings = ToolSettings ()
106
108
assert settings .tool_store_description == "Custom store description"
107
109
assert settings .tool_find_description == "Custom find description"
0 commit comments