test(anthropic): use valid response fixtures for strict parsing

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
mateo 2026-10-18 12:59:01 +00:00
parent 638cdc0c82
commit 6f3f9fbe2c
2 changed files with 36 additions and 4 deletions

View file

@ -55,6 +55,22 @@ class TestCustomPromptManagement(CustomPromptManagement):
return model, messages, non_default_params
def _anthropic_chat_response() -> httpx.Response:
return httpx.Response(
200,
json={
"id": "msg_123",
"type": "message",
"role": "assistant",
"content": [{"type": "text", "text": "Hello"}],
"model": "claude-3-5-sonnet",
"stop_reason": "end_turn",
"stop_sequence": None,
"usage": {"input_tokens": 1, "output_tokens": 1},
},
)
@pytest.mark.asyncio
async def test_custom_prompt_management_with_prompt_id(monkeypatch):
custom_prompt_management = TestCustomPromptManagement()
@ -62,7 +78,7 @@ async def test_custom_prompt_management_with_prompt_id(monkeypatch):
# Mock AsyncHTTPHandler.post method
client = AsyncHTTPHandler()
with patch.object(client, "post", return_value=MagicMock()) as mock_post:
with patch.object(client, "post", return_value=_anthropic_chat_response()) as mock_post:
await litellm.acompletion(
model="anthropic/claude-3-5-sonnet",
messages=[{"role": "user", "content": "Hello, how are you?"}],
@ -90,7 +106,7 @@ async def test_custom_prompt_management_with_prompt_id_and_prompt_variables():
# Mock AsyncHTTPHandler.post method
client = AsyncHTTPHandler()
with patch.object(client, "post", return_value=MagicMock()) as mock_post:
with patch.object(client, "post", return_value=_anthropic_chat_response()) as mock_post:
await litellm.acompletion(
model="anthropic/claude-3-5-sonnet",
messages=[],
@ -119,7 +135,7 @@ async def test_custom_prompt_management_without_prompt_id():
# Mock AsyncHTTPHandler.post method
client = AsyncHTTPHandler()
with patch.object(client, "post", return_value=MagicMock()) as mock_post:
with patch.object(client, "post", return_value=_anthropic_chat_response()) as mock_post:
await litellm.acompletion(
model="anthropic/claude-3-5-sonnet",
messages=[{"role": "user", "content": "Hello, how are you?"}],

View file

@ -317,7 +317,23 @@ def test_router_pattern_match_e2e():
]
)
with patch.object(client, "post", new=MagicMock()) as mock_post:
with patch.object(
client,
"post",
return_value=httpx.Response(
200,
json={
"id": "msg_123",
"type": "message",
"role": "assistant",
"content": [{"type": "text", "text": "Hello"}],
"model": "claude-3-5-sonnet",
"stop_reason": "end_turn",
"stop_sequence": None,
"usage": {"input_tokens": 1, "output_tokens": 1},
},
),
) as mock_post:
router.completion(
model="llmengine/my-custom-model",