From b680be27051d7d3dc6c891cdcb18d7d6b28afb17 Mon Sep 17 00:00:00 2001 From: Aniket Jadhav Date: Thu, 15 Oct 2026 20:51:56 +0530 Subject: [PATCH] fix: handle boolean proxy test flag --- litellm/proxy/proxy_cli.py | 2 +- tests/unit/proxy/test_proxy_cli.py | 35 +++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/litellm/proxy/proxy_cli.py b/litellm/proxy/proxy_cli.py index 3c5f55d87a8..c3aebfef67a 100644 --- a/litellm/proxy/proxy_cli.py +++ b/litellm/proxy/proxy_cli.py @@ -253,7 +253,7 @@ class ProxyInitializationHelpers: api_base = f"http://{host}:{port}" if isinstance(test, str): api_base = test - else: + elif test is not True: raise ValueError("Invalid test value") client: Final = openai.OpenAI(api_key="My API Key", base_url=api_base) diff --git a/tests/unit/proxy/test_proxy_cli.py b/tests/unit/proxy/test_proxy_cli.py index 9566b6e30a2..a92ea682f65 100644 --- a/tests/unit/proxy/test_proxy_cli.py +++ b/tests/unit/proxy/test_proxy_cli.py @@ -74,7 +74,16 @@ class TestProxyInitializationHelpers: @patch("openai.OpenAI") @patch("click.echo") @patch("builtins.print") - def test_run_test_chat_completion(self, mock_print, mock_echo, mock_openai): + @pytest.mark.parametrize( + ("test_value", "expected_base_url"), + [ + (True, "http://localhost:8000"), + ("http://test-url", "http://test-url"), + ], + ) + def test_run_test_chat_completion( + self, mock_print, mock_echo, mock_openai, test_value, expected_base_url + ): # Setup mock_client = MagicMock() mock_openai.return_value = mock_client @@ -90,21 +99,27 @@ class TestProxyInitializationHelpers: ] # Execute - with pytest.raises(ValueError, match="Invalid test value"): - ProxyInitializationHelpers._run_test_chat_completion( - "localhost", 8000, "gpt-3.5-turbo", True - ) - - # Test with valid string test value ProxyInitializationHelpers._run_test_chat_completion( - "localhost", 8000, "gpt-3.5-turbo", "http://test-url" + "localhost", 8000, "gpt-3.5-turbo", test_value ) # Assert mock_openai.assert_called_once_with( - api_key="My API Key", base_url="http://test-url" + api_key="My API Key", base_url=expected_base_url ) - mock_client.chat.completions.create.assert_called() + assert mock_client.chat.completions.create.call_count == 2 + mock_client.completions.create.assert_called_once_with( + model="gpt-3.5-turbo", prompt="this is a test request, write a short poem" + ) + + @patch("openai.OpenAI") + def test_run_test_chat_completion_rejects_false(self, mock_openai): + with pytest.raises(ValueError, match="Invalid test value"): + ProxyInitializationHelpers._run_test_chat_completion( + "localhost", 8000, "gpt-3.5-turbo", False + ) + + mock_openai.assert_not_called() def test_get_default_unvicorn_init_args(self): # Test without log_config