From dcfc625a5f767cfdf45a6a92a73ab85627b59848 Mon Sep 17 00:00:00 2001 From: abrekhov Date: Mon, 24 Aug 2026 10:50:45 +0000 Subject: [PATCH] test(guardrails): inject AIDR HTTP client --- .../guardrail_hooks/test_crowdstrike_aidr.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_crowdstrike_aidr.py b/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_crowdstrike_aidr.py index e0163d27ca7..abf865bd3a7 100644 --- a/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_crowdstrike_aidr.py +++ b/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_crowdstrike_aidr.py @@ -93,16 +93,13 @@ async def test_apply_guardrail_fails_open_on_4xx() -> None: "structured_messages": [{"role": "user", "content": "core dump: raw bytes"}], } request_data = {"messages": inputs["structured_messages"]} - endpoint = f"{guardrail.api_base}/v1/guard_chat_completions" - with patch( - "litellm.llms.custom_httpx.http_handler.AsyncHTTPHandler.post", - return_value=httpx.Response( - status_code=400, - json={"error": "guard api error"}, - request=httpx.Request(method="POST", url=endpoint), - ), - ): + transport = httpx.MockTransport( + lambda request: httpx.Response(status_code=400, json={"error": "guard api error"}, request=request) + ) + async with httpx.AsyncClient(transport=transport) as client: + await guardrail.async_handler.close() + guardrail.async_handler.client = client result = await guardrail.apply_guardrail( inputs=inputs, request_data=request_data,