This commit is contained in:
Aniket Jadhav 2026-11-07 03:26:08 +00:00 • committed by GitHub
commit 2cfa3479ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 11 deletions

View file

@ -336,7 +336,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)

View file

@ -184,7 +184,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
@ -200,21 +209,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