22from typing import List
33from unittest import IsolatedAsyncioTestCase , mock
44
5- from qdrant_client import AsyncQdrantClient
65from qdrant_client .models import CollectionDescription , CollectionsResponse , ScoredPoint
76
87from src .app .models .collections import Collection
9- from src .app .services .search import (
10- DBClientSingleton ,
11- SearchService ,
12- concatenate_same_doc_id_slices ,
13- )
8+ from src .app .services .search import SearchService , concatenate_same_doc_id_slices
149
1510os .environ ["USE_CACHED_SETTINGS" ] = "False"
1611
1712
13+ class FakeQdrantClient :
14+ async def get_collections (self ):
15+ class Collections :
16+ collections = [
17+ type ("C" , (), {"name" : "collection_welearn_fr_exists" }),
18+ type ("C" , (), {"name" : "collection_welearn_en_exists" }),
19+ ]
20+
21+ return Collections ()
22+
23+
1824class alternate_mock_method (object ):
1925 def __init__ (self , url : str , timeout : int , port : int , ** kwargs ):
2026 return
@@ -37,24 +43,19 @@ def fake_callback_function(embedding, nb_results, filters, collection_info):
3743 return f"{ embedding } , { nb_results } , { filters } , { collection_info } "
3844
3945
40- @mock .patch ("qdrant_client.AsyncQdrantClient" , alternate_mock_method )
41- @mock .patch .object (AsyncQdrantClient , "get_collections" , return_value = collections )
4246class SearchServiceTests (IsolatedAsyncioTestCase ):
4347 def setUp (self ):
44- self .sp = SearchService ()
45-
46- def test_db_singleton (self , * mocks ):
47- db_sing1 = DBClientSingleton ()
48- db_sing2 = DBClientSingleton ()
48+ self .qdrant = FakeQdrantClient ()
49+ self .sp = SearchService (client = self .qdrant )
4950
50- self .assertEqual (db_sing1 , db_sing2 )
51+ async def test_get_collection_by_language (self ):
52+ collection = await self .sp .get_collection_by_language ("fr" )
5153
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" )
54+ self .assertEqual (collection .name , "collection_welearn_fr_exists" )
55+ self .assertEqual (collection .lang , "fr" )
56+ self .assertEqual (collection .model , "exists" )
5657
57- def test_get_info_from_collection_name (self , * mocks ):
58+ def test_get_info_from_collection_name (self ):
5859 collection = self .sp ._get_info_from_collection_name (
5960 "collection_welearn_fr_exists"
6061 )
@@ -63,7 +64,7 @@ def test_get_info_from_collection_name(self, *mocks):
6364 self .assertEqual (collection .lang , "fr" )
6465 self .assertEqual (collection .model , "exists" )
6566
66- async def test_get_collection_by_language_with_collection (self , * mocks ):
67+ async def test_get_collection_by_language_with_collection (self ):
6768 with mock .patch .object (
6869 SearchService ,
6970 "get_collections" ,
@@ -82,7 +83,7 @@ async def test_get_collection_by_language_with_collection(self, *mocks):
8283 self .assertEqual (collection .name , "collection_welearn_fr_exists" )
8384 self .assertEqual (collection , exp_collection )
8485
85- def test_concatenate_same_doc_id_slices (self , * mocks ):
86+ def test_concatenate_same_doc_id_slices (self ):
8687
8788 qdrant_docs : List [ScoredPoint ] = [
8889 ScoredPoint (
0 commit comments