@@ -97,59 +97,6 @@ def test_get_embedding_function_init_exception():
9797 )
9898
9999
100- @pytest .mark .asyncio
101- async def test_try_server_versions ():
102- # Test successful v1 response
103- with patch ("httpx.AsyncClient" ) as mock_client :
104- mock_response = MagicMock ()
105- mock_response .status_code = 200
106- mock_client .return_value .__aenter__ .return_value .get .return_value = (
107- mock_response
108- )
109- assert await try_server ("http://localhost:8300" ) is True
110- mock_client .return_value .__aenter__ .return_value .get .assert_called_once_with (
111- url = "http://localhost:8300/api/v1/heartbeat"
112- )
113-
114- # Test fallback to v2 when v1 fails
115- with patch ("httpx.AsyncClient" ) as mock_client :
116- mock_response_v1 = MagicMock ()
117- mock_response_v1 .status_code = 404
118- mock_response_v2 = MagicMock ()
119- mock_response_v2 .status_code = 200
120- mock_client .return_value .__aenter__ .return_value .get .side_effect = [
121- mock_response_v1 ,
122- mock_response_v2 ,
123- ]
124- assert await try_server ("http://localhost:8300" ) is True
125- assert mock_client .return_value .__aenter__ .return_value .get .call_count == 2
126-
127- # Test both versions fail
128- with patch ("httpx.AsyncClient" ) as mock_client :
129- mock_response_v1 = MagicMock ()
130- mock_response_v1 .status_code = 404
131- mock_response_v2 = MagicMock ()
132- mock_response_v2 .status_code = 500
133- mock_client .return_value .__aenter__ .return_value .get .side_effect = [
134- mock_response_v1 ,
135- mock_response_v2 ,
136- ]
137- assert await try_server ("http://localhost:8300" ) is False
138-
139- # Test connection error cases
140- with patch ("httpx.AsyncClient" ) as mock_client :
141- mock_client .return_value .__aenter__ .return_value .get .side_effect = (
142- httpx .ConnectError ("Cannot connect" )
143- )
144- assert await try_server ("http://localhost:8300" ) is False
145-
146- with patch ("httpx.AsyncClient" ) as mock_client :
147- mock_client .return_value .__aenter__ .return_value .get .side_effect = (
148- httpx .ConnectTimeout ("Connection timeout" )
149- )
150- assert await try_server ("http://localhost:8300" ) is False
151-
152-
153100def test_verify_ef ():
154101 # Mocking AsyncCollection and Config
155102 mock_collection = MagicMock ()
@@ -190,10 +137,18 @@ async def test_try_server_mocked(mock_socket):
190137 with patch ("httpx.AsyncClient" ) as mock_client :
191138 mock_response = MagicMock ()
192139 mock_response .status_code = 200
140+ mock_response .content = b'{"info":{"title": "Chroma"}}'
193141 mock_client .return_value .__aenter__ .return_value .get .return_value = (
194142 mock_response
195143 )
196144 assert await try_server ("http://localhost:8000" ) is True
145+ with patch ("httpx.AsyncClient" ) as mock_client :
146+ mock_response = MagicMock ()
147+ mock_response .status_code = 404
148+ mock_client .return_value .__aenter__ .return_value .get .return_value = (
149+ mock_response
150+ )
151+ assert await try_server ("http://localhost:8000" ) is False
197152
198153 # Mocking httpx.AsyncClient to raise a ConnectError
199154 with patch ("httpx.AsyncClient" ) as mock_client :
@@ -202,6 +157,15 @@ async def test_try_server_mocked(mock_socket):
202157 )
203158 assert await try_server ("http://localhost:8000" ) is False
204159
160+ with patch ("httpx.AsyncClient" ) as mock_client :
161+ mock_response = MagicMock ()
162+ mock_response .status_code = 200
163+ mock_response .content = b'{"info":{"title": "Dummy"}}'
164+ mock_client .return_value .__aenter__ .return_value .get .return_value = (
165+ mock_response
166+ )
167+ assert await try_server ("http://localhost:8000" ) is False
168+
205169 # Mocking httpx.AsyncClient to raise a ConnectTimeout
206170 with patch ("httpx.AsyncClient" ) as mock_client :
207171 mock_client .return_value .__aenter__ .return_value .get .side_effect = (
0 commit comments