fix the issue from the tests for pr review

This commit is contained in:
Henry Wang 2025-09-30 18:15:25 +08:00
parent cce05ac2b4
commit fcd539af33

View File

@ -1059,7 +1059,6 @@ async def test_google_generate_content_with_openai():
"""
import unittest.mock
from litellm.google_genai.adapters.transformation import GoogleGenAIAdapter
from litellm.types.llms.openai import ChatCompletionAssistantMessage
from litellm.types.router import GenericLiteLLMParams
from litellm.types.utils import Choices, ModelResponse, Usage
@ -1092,9 +1091,9 @@ async def test_google_generate_content_with_openai():
)
# Use AsyncMock for proper async function mocking
with unittest.mock.patch.object(GoogleGenAIAdapter, 'translate_completion_to_generate_content', new_callable=unittest.mock.AsyncMock) as mock_translate:
# Set the return value directly on the AsyncMock
mock_translate.return_value = {"candidates": []}
with unittest.mock.patch("litellm.completion", new_callable=unittest.mock.MagicMock) as mock_completion:
# Set the return value directly on the MagicMock
mock_completion.return_value = mock_response
response = await agenerate_content(
model="openai/gpt-4o-mini",
@ -1110,11 +1109,23 @@ async def test_google_generate_content_with_openai():
]
)
# Print the request args sent to litellm.completion
call_args, call_kwargs = mock_completion.call_args
print("Arguments sent to litellm.completion:")
print(f"Args: {call_args}")
print(f"Kwargs: {call_kwargs}")
# Verify the mock was called
mock_translate.assert_called_once()
mock_completion.assert_called_once()
# Print the response for verification
print(f"Response: {response}")
#########################################################
# validate only expected fields were sent to litellm.completion
passed_fields = set(call_kwargs.keys())
# remove any GenericLiteLLMParams fields
passed_fields = passed_fields - set(GenericLiteLLMParams.model_fields.keys())
assert passed_fields == set(["model", "messages"]), f"Expected only model and messages to be passed through, got {passed_fields}"
@pytest.mark.asyncio
async def test_agenerate_content_x_goog_api_key_header():
"""