44from vortexdb .client import VortexDB
55from vortexdb .connection import GRPCConnection
66from vortexdb .models import DenseVector , Payload , Similarity , ContentType , Point
7- from vortexdb .exceptions import InvalidArgumentError
87from vortexdb .models import SearchQuery
98
109
11-
1210# Fixtures for a mock connection and client layer
1311
12+
1413@pytest .fixture
1514def mock_connection (monkeypatch ):
1615 """
@@ -31,6 +30,7 @@ def client(mock_connection):
3130
3231# Insert
3332
33+
3434def test_insert_success (client , mock_connection ):
3535 response = Mock ()
3636 response .id = Mock ()
@@ -56,6 +56,7 @@ def test_insert_rejects_invalid_vector(client):
5656
5757# Batch Insert
5858
59+
5960def test_batch_insert_success (client , mock_connection ):
6061 response = Mock ()
6162 response .ids = [
@@ -70,17 +71,20 @@ def test_batch_insert_success(client, mock_connection):
7071 result = client .batch_insert (items = items )
7172 assert result == ["p1" , "p2" ]
7273
74+
7375def test_batch_insert_invalid_items_type (client ):
7476 with pytest .raises (TypeError ):
7577 client .batch_insert (items = "not-a-list" )
7678
79+
7780def test_batch_insert_invalid_tuple_structure (client ):
7881 items = [
7982 (DenseVector ([1 , 2 , 3 ]),), # only one element
8083 ]
8184 with pytest .raises (TypeError ):
8285 client .batch_insert (items = items )
8386
87+
8488def test_batch_insert_invalid_vector (client ):
8589 items = [
8690 ([1 , 2 , 3 ], Payload .text ("a" )), # not DenseVector
@@ -91,6 +95,7 @@ def test_batch_insert_invalid_vector(client):
9195
9296# Get
9397
98+
9499def test_get_point_success (client , mock_connection ):
95100 proto_point = Mock ()
96101 proto_point .id .id .value = "point-123"
@@ -117,6 +122,7 @@ def test_get_point_not_found(client, mock_connection):
117122
118123# Delete
119124
125+
120126def test_delete_success (client , mock_connection ):
121127 mock_connection .call .return_value = None
122128
@@ -127,6 +133,7 @@ def test_delete_success(client, mock_connection):
127133
128134# Search
129135
136+
130137def test_search_success (client , mock_connection ):
131138 mock_connection .call .return_value = Mock (
132139 result_point_ids = [
@@ -167,7 +174,6 @@ def test_search_invalid_vector(client):
167174 )
168175
169176
170-
171177def test_batch_search_accepts_ef (client , mock_connection ):
172178 mock_connection .call .return_value = Mock (results = [])
173179
@@ -182,8 +188,10 @@ def test_batch_search_accepts_ef(client, mock_connection):
182188 request = mock_connection .call .call_args .args [1 ]
183189 assert [query .ef for query in request .queries ] == [256 , 256 ]
184190
191+
185192# Batch Search
186193
194+
187195def test_batch_search_full_tuple (client , mock_connection ):
188196 mock_connection .call .return_value = Mock (
189197 results = [
@@ -198,6 +206,7 @@ def test_batch_search_full_tuple(client, mock_connection):
198206 result = client .batch_search (queries = queries )
199207 assert result == [["p1" ], ["p2" ]]
200208
209+
201210def test_batch_search_vectors_with_global_params (client , mock_connection ):
202211 mock_connection .call .return_value = Mock (
203212 results = [
@@ -212,6 +221,7 @@ def test_batch_search_vectors_with_global_params(client, mock_connection):
212221 )
213222 assert result == [["p1" ]]
214223
224+
215225def test_batch_search_vector_similarity_with_global_limit (client , mock_connection ):
216226 mock_connection .call .return_value = Mock (
217227 results = [
@@ -227,6 +237,7 @@ def test_batch_search_vector_similarity_with_global_limit(client, mock_connectio
227237 )
228238 assert result == [["p1" ]]
229239
240+
230241def test_batch_search_searchquery_objects (client , mock_connection ):
231242 mock_connection .call .return_value = Mock (
232243 results = [
@@ -239,29 +250,35 @@ def test_batch_search_searchquery_objects(client, mock_connection):
239250 result = client .batch_search (queries = queries )
240251 assert result == [["p1" ]]
241252
253+
242254def test_batch_search_missing_globals_for_vector (client ):
243255 queries = [DenseVector ([1 , 2 , 3 ])]
244256 with pytest .raises (ValueError ):
245257 client .batch_search (queries = queries )
246258
259+
247260def test_batch_search_missing_limit (client ):
248261 queries = [
249262 (DenseVector ([1 , 2 , 3 ]), Similarity .COSINE ),
250263 ]
251264 with pytest .raises (ValueError ):
252265 client .batch_search (queries = queries )
253266
267+
254268def test_batch_search_invalid_format (client ):
255269 queries = ["invalid" ]
256270 with pytest .raises (TypeError ):
257271 client .batch_search (queries = queries )
258272
273+
259274# Close
260275
276+
261277def test_close_closes_connection (client , mock_connection ):
262278 client .close ()
263279 mock_connection .close .assert_called_once ()
264280
281+
265282def test_context_manager_closes_connection (monkeypatch ):
266283 conn = Mock (spec = GRPCConnection )
267284 monkeypatch .setattr ("vortexdb.client.GRPCConnection" , lambda _ : conn )
0 commit comments