The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix: add State() to mock requests in http_parsing_utils tests
Ryan Crabbe3275fb09cb62
diff --git a/tests/test_litellm/proxy/common_utils/test_http_parsing_utils.py b/tests/test_litellm/proxy/common_utils/test_http_parsing_utils.pyindex af366b082a0..16f934d8d46 100644--- a/tests/test_litellm/proxy/common_utils/test_http_parsing_utils.py+++ b/tests/test_litellm/proxy/common_utils/test_http_parsing_utils.py@@ -7,6 +7,7 @@ import orjsonimport pytestfrom fastapi import Requestfrom fastapi.testclient import TestClient+from starlette.datastructures import Statesys.path.insert(0, os.path.abspath("../../../..")@@ -36,6 +37,7 @@ async def test_request_body_caching():"""# Create a mock request with a JSON bodymock_request = MagicMock()+ mock_request.state = State()test_data = {"key": "value"}# Use AsyncMock for the body methodmock_request.body = AsyncMock(return_value=orjson.dumps(test_data))@@ -69,6 +71,7 @@ async def test_form_data_parsing():"""# Create a mock request with form datamock_request = MagicMock()+ mock_request.state = State()test_data = {"name": "test_user", "message": "hello world"}# Mock the form method to return the test data as an awaitable@@ -104,7 +107,8 @@ async def test_form_data_with_json_metadata():"""# Create a mock request with form data containing JSON metadatamock_request = MagicMock()-+ mock_request.state = State()+# Metadata is sent as a JSON string in form datametadata_json_string = json.dumps({"user_id": "12345",@@ -152,7 +156,8 @@ async def test_form_data_with_invalid_json_metadata():"""# Create a mock request with form data containing invalid JSON metadatamock_request = MagicMock()-+ mock_request.state = State()+test_data = {"model": "whisper-1","file": "audio.mp3",@@ -178,7 +183,8 @@ async def test_form_data_without_metadata():"""# Create a mock request with form data without metadatamock_request = MagicMock()-+ mock_request.state = State()+test_data = {"model": "whisper-1","file": "audio.mp3",@@ -208,7 +214,8 @@ async def test_form_data_with_empty_metadata():"""# Create a mock request with form data containing empty metadatamock_request = MagicMock()-+ mock_request.state = State()+test_data = {"model": "whisper-1","file": "audio.mp3",@@ -240,7 +247,8 @@ async def test_form_data_with_dict_metadata():"""# Create a mock request with form data where metadata is already a dictmock_request = MagicMock()-+ mock_request.state = State()+metadata_dict = {"user_id": "12345","tags": ["test"]@@ -275,7 +283,8 @@ async def test_form_data_with_none_metadata():"""# Create a mock request with form data where metadata is Nonemock_request = MagicMock()-+ mock_request.state = State()+test_data = {"model": "whisper-1","file": "audio.mp3",@@ -303,6 +312,7 @@ async def test_empty_request_body():"""# Create a mock request with an empty bodymock_request = MagicMock()+ mock_request.state = State()mock_request.body = AsyncMock(return_value=b"") # Empty bytes as an awaitablemock_request.headers = {"content-type": "application/json"}mock_request.scope = {}@@ -327,6 +337,7 @@ async def test_circular_reference_handling():"""# Create a mock request with initial datamock_request = MagicMock()+ mock_request.state = State()initial_body = {"model": "gpt-4","messages": [{"role": "user", "content": "Hello"}],@@ -366,6 +377,7 @@ async def test_json_parsing_error_handling():"""# Test case 1: Trailing comma errormock_request = MagicMock()+ mock_request.state = State()invalid_json_with_trailing_comma = b'''{"model": "gpt-4o","tools": [@@ -394,6 +406,7 @@ async def test_json_parsing_error_handling():# Test case 2: Unquoted property name errormock_request2 = MagicMock()+ mock_request2.state = State()invalid_json_unquoted_property = b'''{"model": "gpt-4o","tools": [@@ -418,6 +431,7 @@ async def test_json_parsing_error_handling():# Test case 3: Valid JSON should work normallymock_request3 = MagicMock()+ mock_request3.state = State()valid_json = b'''{"model": "gpt-4o","tools": [@@ -749,6 +763,7 @@ async def test_request_body_with_html_script_tags():}mock_request = MagicMock()+ mock_request.state = State()mock_request.body = AsyncMock(return_value=orjson.dumps(test_payload))mock_request.headers = {"content-type": "application/json"}mock_request.scope = {}