mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-07 02:59:05 +00:00
test(responses): inject a mocked http client instead of patching AsyncHTTPHandler.post
This commit is contained in:
parent
61625723a7
commit
39c5ccaed4
1 changed files with 14 additions and 14 deletions
|
|
@ -12,6 +12,7 @@ import httpx
|
|||
import pytest
|
||||
|
||||
import litellm
|
||||
from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler
|
||||
|
||||
|
||||
def _expected_dir() -> Path:
|
||||
|
|
@ -384,22 +385,21 @@ async def test_aresponses_strips_responses_routing_prefix_from_openai_model(mode
|
|||
/v1/responses and via the /v1/messages adapter (which passes responses/<model>
|
||||
with custom_llm_provider="openai"), so both shapes must hit OpenAI as <model>.
|
||||
"""
|
||||
with patch(
|
||||
"litellm.llms.custom_httpx.http_handler.AsyncHTTPHandler.post",
|
||||
new_callable=AsyncMock,
|
||||
) as mock_post:
|
||||
mock_post.return_value = MockResponse(_minimal_responses_api_payload("resp_prefix_test", "gpt-5.6"), 200)
|
||||
injected_client = AsyncHTTPHandler()
|
||||
mock_post = AsyncMock(return_value=MockResponse(_minimal_responses_api_payload("resp_prefix_test", "gpt-5.6"), 200))
|
||||
injected_client.post = mock_post
|
||||
|
||||
await litellm.aresponses(
|
||||
model=model,
|
||||
custom_llm_provider=custom_llm_provider,
|
||||
input="ping",
|
||||
api_key="sk-test",
|
||||
)
|
||||
await litellm.aresponses(
|
||||
model=model,
|
||||
custom_llm_provider=custom_llm_provider,
|
||||
input="ping",
|
||||
api_key="sk-test",
|
||||
client=injected_client,
|
||||
)
|
||||
|
||||
mock_post.assert_called_once()
|
||||
assert mock_post.call_args.kwargs["url"].endswith("/responses")
|
||||
assert mock_post.call_args.kwargs["json"]["model"] == "gpt-5.6"
|
||||
mock_post.assert_called_once()
|
||||
assert mock_post.call_args.kwargs["url"].endswith("/responses")
|
||||
assert mock_post.call_args.kwargs["json"]["model"] == "gpt-5.6"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue