@@ -147,11 +147,15 @@ def test_httpx_client_custom_cert_path(self):
147147 # Verify httpx.Client was called with custom cert path
148148 mock_httpx_client .assert_called_once_with (verify = test_cert_path )
149149
150- @patch .dict (os .environ , {'OPENAI_API_KEY' : 'test-key' } )
150+ @patch .dict (os .environ , {'OPENAI_API_KEY' : 'test-key' , 'OPTILLM_API_KEY' : '' }, clear = False )
151151 def test_openai_client_receives_http_client (self ):
152152 """Test that OpenAI client receives the configured httpx client."""
153153 from optillm .server import get_config
154154
155+ # Ensure OPTILLM_API_KEY is not set (it takes precedence)
156+ if 'OPTILLM_API_KEY' in os .environ :
157+ del os .environ ['OPTILLM_API_KEY' ]
158+
155159 server_config ['ssl_verify' ] = False
156160 server_config ['ssl_cert_path' ] = ''
157161 server_config ['base_url' ] = ''
@@ -168,11 +172,15 @@ def test_openai_client_receives_http_client(self):
168172 self .assertIn ('http_client' , call_kwargs )
169173 self .assertEqual (call_kwargs ['http_client' ], mock_http_client_instance )
170174
171- @patch .dict (os .environ , {'CEREBRAS_API_KEY' : 'test-key' } )
175+ @patch .dict (os .environ , {'CEREBRAS_API_KEY' : 'test-key' , 'OPTILLM_API_KEY' : '' }, clear = False )
172176 def test_cerebras_client_receives_http_client (self ):
173177 """Test that Cerebras client receives the configured httpx client."""
174178 from optillm .server import get_config
175179
180+ # Ensure OPTILLM_API_KEY is not set (it takes precedence)
181+ if 'OPTILLM_API_KEY' in os .environ :
182+ del os .environ ['OPTILLM_API_KEY' ]
183+
176184 server_config ['ssl_verify' ] = False
177185 server_config ['ssl_cert_path' ] = ''
178186 server_config ['base_url' ] = ''
@@ -189,11 +197,15 @@ def test_cerebras_client_receives_http_client(self):
189197 self .assertIn ('http_client' , call_kwargs )
190198 self .assertEqual (call_kwargs ['http_client' ], mock_http_client_instance )
191199
192- @patch .dict (os .environ , {'AZURE_OPENAI_API_KEY' : 'test-key' , 'AZURE_API_VERSION' : '2024-02-15-preview' , 'AZURE_API_BASE' : 'https://test.openai.azure.com' } )
200+ @patch .dict (os .environ , {'AZURE_OPENAI_API_KEY' : 'test-key' , 'AZURE_API_VERSION' : '2024-02-15-preview' , 'AZURE_API_BASE' : 'https://test.openai.azure.com' , 'OPTILLM_API_KEY' : '' }, clear = False )
193201 def test_azure_client_receives_http_client (self ):
194202 """Test that AzureOpenAI client receives the configured httpx client."""
195203 from optillm .server import get_config
196204
205+ # Ensure OPTILLM_API_KEY is not set (it takes precedence)
206+ if 'OPTILLM_API_KEY' in os .environ :
207+ del os .environ ['OPTILLM_API_KEY' ]
208+
197209 server_config ['ssl_verify' ] = False
198210 server_config ['ssl_cert_path' ] = ''
199211
@@ -328,11 +340,15 @@ def test_warning_when_ssl_disabled(self):
328340 self .assertIn ('SSL certificate verification is DISABLED' , warning_message )
329341 self .assertIn ('insecure' , warning_message .lower ())
330342
331- @patch .dict (os .environ , {'OPENAI_API_KEY' : 'test-key' } )
343+ @patch .dict (os .environ , {'OPENAI_API_KEY' : 'test-key' , 'OPTILLM_API_KEY' : '' }, clear = False )
332344 def test_info_when_custom_cert_used (self ):
333345 """Test that an info message is logged when using custom certificate."""
334346 from optillm .server import get_config
335347
348+ # Ensure OPTILLM_API_KEY is not set (it takes precedence)
349+ if 'OPTILLM_API_KEY' in os .environ :
350+ del os .environ ['OPTILLM_API_KEY' ]
351+
336352 # Configure custom certificate path
337353 test_cert_path = '/path/to/custom-ca.pem'
338354 server_config ['ssl_verify' ] = True
@@ -343,11 +359,11 @@ def test_info_when_custom_cert_used(self):
343359 patch ('optillm.server.logger.info' ) as mock_logger_info :
344360 get_config ()
345361
346- # Verify info message was logged
347- mock_logger_info . assert_called ()
348- info_message = mock_logger_info . call_args [ 0 ][0 ]
349- self . assertIn ('custom CA certificate bundle' , info_message )
350- self .assertIn ( test_cert_path , info_message )
362+ # Verify info message was logged about custom cert
363+ # The logger.info is called multiple times, check all calls
364+ all_info_messages = [ call [ 0 ][0 ] for call in mock_logger_info . call_args_list if call [ 0 ] ]
365+ cert_message_found = any ('custom CA certificate bundle' in msg for msg in all_info_messages )
366+ self .assertTrue ( cert_message_found , f"Expected 'custom CA certificate bundle' in one of: { all_info_messages } " )
351367
352368
353369if __name__ == '__main__' :
0 commit comments