@@ -139,3 +139,126 @@ def test_get_client_with_api_key_auth():
139139 call_kwargs ["auth_credentials" ], weaviate .auth .AuthApiKey
140140 )
141141 assert call_kwargs ["auth_credentials" ].api_key == "test-key"
142+
143+
144+ def test_get_client_with_ip_address ():
145+ config_data = {
146+ "host" : "127.0.0.1" ,
147+ "grpc_host" : "127.0.0.1" ,
148+ "http_port" : 8080 ,
149+ "grpc_port" : 50051 ,
150+ }
151+
152+ with patch ("builtins.open" , mock_open (read_data = json .dumps (config_data ))):
153+ with patch ("os.path.isfile" ) as mock_isfile :
154+ mock_isfile .return_value = True
155+ with patch ("weaviate.connect_to_custom" ) as mock_connect :
156+ config = ConfigManager (config_file = "test_config.json" )
157+ config .get_client ()
158+
159+ mock_connect .assert_called_once ()
160+ call_kwargs = mock_connect .call_args .kwargs
161+ assert call_kwargs ["http_host" ] == "127.0.0.1"
162+ assert call_kwargs ["grpc_host" ] == "127.0.0.1"
163+ assert call_kwargs ["http_port" ] == 8080
164+ assert call_kwargs ["grpc_port" ] == 50051
165+ assert call_kwargs ["http_secure" ] == False
166+ assert call_kwargs ["grpc_secure" ] == False
167+
168+
169+ def test_get_client_with_ip_address_and_secure_ports ():
170+ config_data = {
171+ "host" : "127.0.0.1" ,
172+ "grpc_host" : "127.0.0.1" ,
173+ "http_port" : 443 ,
174+ "grpc_port" : 443 ,
175+ }
176+
177+ with patch ("builtins.open" , mock_open (read_data = json .dumps (config_data ))):
178+ with patch ("os.path.isfile" ) as mock_isfile :
179+ mock_isfile .return_value = True
180+ with patch ("weaviate.connect_to_custom" ) as mock_connect :
181+ config = ConfigManager (config_file = "test_config.json" )
182+ config .get_client ()
183+
184+ mock_connect .assert_called_once ()
185+ call_kwargs = mock_connect .call_args .kwargs
186+ assert call_kwargs ["http_host" ] == "127.0.0.1"
187+ assert call_kwargs ["grpc_host" ] == "127.0.0.1"
188+ assert call_kwargs ["http_port" ] == 443
189+ assert call_kwargs ["grpc_port" ] == 443
190+ assert call_kwargs ["http_secure" ] == True
191+ assert call_kwargs ["grpc_secure" ] == True
192+
193+
194+ def test_get_client_with_ip_address_with_https ():
195+ config_data = {
196+ "host" : "https://85.10.20.30" ,
197+ "grpc_host" : "https://85.10.20.31" ,
198+ "http_port" : 443 ,
199+ "grpc_port" : 443 ,
200+ }
201+
202+ with patch ("builtins.open" , mock_open (read_data = json .dumps (config_data ))):
203+ with patch ("os.path.isfile" ) as mock_isfile :
204+ mock_isfile .return_value = True
205+ with patch ("weaviate.connect_to_custom" ) as mock_connect :
206+ config = ConfigManager (config_file = "test_config.json" )
207+ config .get_client ()
208+
209+ mock_connect .assert_called_once ()
210+ call_kwargs = mock_connect .call_args .kwargs
211+ assert call_kwargs ["http_host" ] == "85.10.20.30"
212+ assert call_kwargs ["grpc_host" ] == "85.10.20.31"
213+ assert call_kwargs ["http_port" ] == 443
214+ assert call_kwargs ["grpc_port" ] == 443
215+ assert call_kwargs ["http_secure" ] == True
216+ assert call_kwargs ["grpc_secure" ] == True
217+
218+
219+ def test_get_client_with_host_and_custom ():
220+ config_data = {
221+ "host" : "https://weaviate.google.my-cloud.com" ,
222+ "grpc_host" : "https://grpc.weaviate.google.my-cloud.com" ,
223+ }
224+
225+ with patch ("builtins.open" , mock_open (read_data = json .dumps (config_data ))):
226+ with patch ("os.path.isfile" ) as mock_isfile :
227+ mock_isfile .return_value = True
228+ with patch ("weaviate.connect_to_custom" ) as mock_connect :
229+ config = ConfigManager (config_file = "test_config.json" )
230+ config .get_client ()
231+
232+ mock_connect .assert_called_once ()
233+ call_kwargs = mock_connect .call_args .kwargs
234+ assert call_kwargs ["http_host" ] == "weaviate.google.my-cloud.com"
235+ assert call_kwargs ["grpc_host" ] == "grpc.weaviate.google.my-cloud.com"
236+ assert call_kwargs ["http_port" ] == 443
237+ assert call_kwargs ["grpc_port" ] == 443
238+ assert call_kwargs ["http_secure" ] == True
239+ assert call_kwargs ["grpc_secure" ] == True
240+
241+
242+ def test_get_client_with_host_and_custom_with_ports ():
243+ config_data = {
244+ "host" : "https://weaviate.google.my-cloud.com" ,
245+ "grpc_host" : "https://grpc.weaviate.google.my-cloud.com" ,
246+ "http_port" : 8080 ,
247+ "grpc_port" : 8080 ,
248+ }
249+
250+ with patch ("builtins.open" , mock_open (read_data = json .dumps (config_data ))):
251+ with patch ("os.path.isfile" ) as mock_isfile :
252+ mock_isfile .return_value = True
253+ with patch ("weaviate.connect_to_custom" ) as mock_connect :
254+ config = ConfigManager (config_file = "test_config.json" )
255+ config .get_client ()
256+
257+ mock_connect .assert_called_once ()
258+ call_kwargs = mock_connect .call_args .kwargs
259+ assert call_kwargs ["http_host" ] == "weaviate.google.my-cloud.com"
260+ assert call_kwargs ["grpc_host" ] == "grpc.weaviate.google.my-cloud.com"
261+ assert call_kwargs ["http_port" ] == 8080
262+ assert call_kwargs ["grpc_port" ] == 8080
263+ assert call_kwargs ["http_secure" ] == True # URL contains https
264+ assert call_kwargs ["grpc_secure" ] == True # URL contains https
0 commit comments