@@ -150,79 +150,6 @@ async def test_try_server_versions():
150150 assert await try_server ("http://localhost:8300" ) is False
151151
152152
153- @pytest .mark .asyncio
154- async def test_get_client ():
155- config = Config (db_url = "https://test_host:1234" , db_path = "test_db" )
156- config1 = Config (
157- db_url = "http://test_host1:1234" ,
158- db_path = "test_db" ,
159- db_settings = {"anonymized_telemetry" : True },
160- )
161- config1_alt = Config (
162- db_url = "http://test_host1:1234" ,
163- db_path = "test_db" ,
164- db_settings = {"anonymized_telemetry" : True , "other_setting" : "value" },
165- )
166- # Patch chromadb.AsyncHttpClient to avoid actual network calls
167- with (
168- patch ("chromadb.AsyncHttpClient" ) as MockAsyncHttpClient ,
169- patch ("vectorcode.common.try_server" , return_value = True ),
170- ):
171- mock_client = MagicMock (spec = AsyncClientAPI )
172- MockAsyncHttpClient .return_value = mock_client
173-
174- async with (
175- ClientManager ().get_client (config ) as client ,
176- ):
177- assert isinstance (client , AsyncClientAPI )
178- MockAsyncHttpClient .assert_called ()
179- assert (
180- MockAsyncHttpClient .call_args .kwargs ["settings" ].chroma_server_host
181- == "test_host"
182- )
183- assert (
184- MockAsyncHttpClient .call_args .kwargs ["settings" ].chroma_server_http_port
185- == 1234
186- )
187- assert (
188- MockAsyncHttpClient .call_args .kwargs ["settings" ].anonymized_telemetry
189- is False
190- )
191- assert (
192- MockAsyncHttpClient .call_args .kwargs [
193- "settings"
194- ].chroma_server_ssl_enabled
195- is True
196- )
197-
198- async with (
199- ClientManager ().get_client (config1 ) as client1 ,
200- ClientManager ().get_client (config1_alt ) as client1_alt ,
201- ):
202- assert isinstance (client1 , AsyncClientAPI )
203- MockAsyncHttpClient .assert_called ()
204- assert (
205- MockAsyncHttpClient .call_args .kwargs ["settings" ].chroma_server_host
206- == "test_host1"
207- )
208- assert (
209- MockAsyncHttpClient .call_args .kwargs [
210- "settings"
211- ].chroma_server_http_port
212- == 1234
213- )
214- assert (
215- MockAsyncHttpClient .call_args .kwargs [
216- "settings"
217- ].anonymized_telemetry
218- is True
219- )
220-
221- # Test with multiple db_settings, including an invalid one. The invalid one
222- # should be filtered out inside get_client.
223- assert id (client1_alt ) == id (client1 )
224-
225-
226153def test_verify_ef ():
227154 # Mocking AsyncCollection and Config
228155 mock_collection = MagicMock ()
@@ -582,31 +509,75 @@ async def test_wait_for_server_timeout():
582509
583510@pytest .mark .asyncio
584511async def test_client_manager_get_client ():
585- ClientManager ().clear ()
512+ config = Config (db_url = "https://test_host:1234" , db_path = "test_db" )
513+ config1 = Config (
514+ db_url = "http://test_host1:1234" ,
515+ db_path = "test_db" ,
516+ db_settings = {"anonymized_telemetry" : True },
517+ )
518+ config1_alt = Config (
519+ db_url = "http://test_host1:1234" ,
520+ db_path = "test_db" ,
521+ db_settings = {"anonymized_telemetry" : True , "other_setting" : "value" },
522+ )
523+ # Patch chromadb.AsyncHttpClient to avoid actual network calls
586524 with (
587- patch ("vectorcode.common.try_server" , return_value = False ) as mock_try_server ,
588- patch (
589- "vectorcode.common.start_server" , return_value = MagicMock ()
590- ) as mock_start_server ,
525+ patch ("chromadb.AsyncHttpClient" ) as MockAsyncHttpClient ,
526+ patch ("vectorcode.common.try_server" , return_value = True ),
591527 ):
592- # need to start a new server
593- manager = ClientManager ()
594- async with manager .get_client (Config ()):
595- mock_try_server .assert_called_once ()
596- mock_start_server .assert_called_once ()
528+ mock_client = MagicMock (spec = AsyncClientAPI )
529+ MockAsyncHttpClient .return_value = mock_client
597530
598- ClientManager ().clear ()
599- with (
600- patch ("vectorcode.common.try_server" , return_value = True ) as mock_try_server ,
601- patch (
602- "vectorcode.common.start_server" , return_value = MagicMock ()
603- ) as mock_start_server ,
604- ):
605- # need to start a new server
606- manager = ClientManager ()
607- async with manager .get_client (Config ()):
608- mock_try_server .assert_called_once ()
609- mock_start_server .assert_not_called ()
531+ async with (
532+ ClientManager ().get_client (config ) as client ,
533+ ):
534+ assert isinstance (client , AsyncClientAPI )
535+ MockAsyncHttpClient .assert_called ()
536+ assert (
537+ MockAsyncHttpClient .call_args .kwargs ["settings" ].chroma_server_host
538+ == "test_host"
539+ )
540+ assert (
541+ MockAsyncHttpClient .call_args .kwargs ["settings" ].chroma_server_http_port
542+ == 1234
543+ )
544+ assert (
545+ MockAsyncHttpClient .call_args .kwargs ["settings" ].anonymized_telemetry
546+ is False
547+ )
548+ assert (
549+ MockAsyncHttpClient .call_args .kwargs [
550+ "settings"
551+ ].chroma_server_ssl_enabled
552+ is True
553+ )
554+
555+ async with (
556+ ClientManager ().get_client (config1 ) as client1 ,
557+ ClientManager ().get_client (config1_alt ) as client1_alt ,
558+ ):
559+ assert isinstance (client1 , AsyncClientAPI )
560+ MockAsyncHttpClient .assert_called ()
561+ assert (
562+ MockAsyncHttpClient .call_args .kwargs ["settings" ].chroma_server_host
563+ == "test_host1"
564+ )
565+ assert (
566+ MockAsyncHttpClient .call_args .kwargs [
567+ "settings"
568+ ].chroma_server_http_port
569+ == 1234
570+ )
571+ assert (
572+ MockAsyncHttpClient .call_args .kwargs [
573+ "settings"
574+ ].anonymized_telemetry
575+ is True
576+ )
577+
578+ # Test with multiple db_settings, including an invalid one. The invalid one
579+ # should be filtered out inside get_client.
580+ assert id (client1_alt ) == id (client1 )
610581
611582
612583@pytest .mark .asyncio
0 commit comments