77
88from src .app .models .collections import Collection
99from src .app .services .search import (
10- DBClientSingleton ,
1110 SearchService ,
1211 concatenate_same_doc_id_slices ,
1312)
1413
1514os .environ ["USE_CACHED_SETTINGS" ] = "False"
1615
16+ class FakeQdrantClient :
17+ async def get_collections (self ):
18+ class Collections :
19+ collections = [
20+ type ("C" , (), {"name" : "collection_welearn_fr_exists" }),
21+ type ("C" , (), {"name" : "collection_welearn_en_exists" }),
22+ ]
23+ return Collections ()
1724
1825class alternate_mock_method (object ):
1926 def __init__ (self , url : str , timeout : int , port : int , ** kwargs ):
@@ -37,24 +44,19 @@ def fake_callback_function(embedding, nb_results, filters, collection_info):
3744 return f"{ embedding } , { nb_results } , { filters } , { collection_info } "
3845
3946
40- @mock .patch ("qdrant_client.AsyncQdrantClient" , alternate_mock_method )
41- @mock .patch .object (AsyncQdrantClient , "get_collections" , return_value = collections )
4247class SearchServiceTests (IsolatedAsyncioTestCase ):
4348 def setUp (self ):
44- self .sp = SearchService ()
49+ self .qdrant = FakeQdrantClient ()
50+ self .sp = SearchService (client = self .qdrant )
4551
46- def test_db_singleton (self , * mocks ):
47- db_sing1 = DBClientSingleton ()
48- db_sing2 = DBClientSingleton ()
52+ async def test_get_collection_by_language (self ):
53+ collection = await self .sp .get_collection_by_language ("fr" )
4954
50- self .assertEqual (db_sing1 , db_sing2 )
51-
52- async def test_get_collection_by_language (self , * mocks ):
53- collections = await self .sp .get_collection_by_language ("fr" )
54-
55- self .assertEqual (collections .name , "collection_welearn_fr_exists" )
56-
57- def test_get_info_from_collection_name (self , * mocks ):
55+ self .assertEqual (collection .name , "collection_welearn_fr_exists" )
56+ self .assertEqual (collection .lang , "fr" )
57+ self .assertEqual (collection .model , "exists" )
58+
59+ def test_get_info_from_collection_name (self ):
5860 collection = self .sp ._get_info_from_collection_name (
5961 "collection_welearn_fr_exists"
6062 )
@@ -63,7 +65,7 @@ def test_get_info_from_collection_name(self, *mocks):
6365 self .assertEqual (collection .lang , "fr" )
6466 self .assertEqual (collection .model , "exists" )
6567
66- async def test_get_collection_by_language_with_collection (self , * mocks ):
68+ async def test_get_collection_by_language_with_collection (self ):
6769 with mock .patch .object (
6870 SearchService ,
6971 "get_collections" ,
@@ -82,7 +84,7 @@ async def test_get_collection_by_language_with_collection(self, *mocks):
8284 self .assertEqual (collection .name , "collection_welearn_fr_exists" )
8385 self .assertEqual (collection , exp_collection )
8486
85- def test_concatenate_same_doc_id_slices (self , * mocks ):
87+ def test_concatenate_same_doc_id_slices (self ):
8688
8789 qdrant_docs : List [ScoredPoint ] = [
8890 ScoredPoint (
0 commit comments