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(tests): isolate auth in vertex passthrough and spend logs date range tests (#21824)
Ishaan Jaff494aad4a688a
diff --git a/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py b/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.pyindex 922c374418a..98161402c45 100644--- a/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py+++ b/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py@@ -446,12 +446,16 @@ class TestVertexAIPassThroughHandler:"litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints.create_pass_through_route") as mock_create_route, mock.patch("litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints.get_vertex_pass_through_handler"- ) as mock_get_handler:+ ) as mock_get_handler, mock.patch(+ "litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints.user_api_key_auth",+ new_callable=AsyncMock,+ ) as mock_auth:# Mock credentials object with necessary attributesmock_credentials = Mock()mock_credentials.token = default_credentialsmock_load_auth.return_value = (mock_credentials, default_project)+ mock_auth.return_value = MagicMock()# Mock the vertex handlermock_handler = Mock()diff --git a/tests/test_litellm/proxy/spend_tracking/test_spend_management_endpoints.py b/tests/test_litellm/proxy/spend_tracking/test_spend_management_endpoints.pyindex 6e34d275482..c3639e88f6e 100644--- a/tests/test_litellm/proxy/spend_tracking/test_spend_management_endpoints.py+++ b/tests/test_litellm/proxy/spend_tracking/test_spend_management_endpoints.py@@ -1977,28 +1977,34 @@ async def test_view_spend_logs_with_date_range_summarized(client, monkeypatch):start_date = (datetime.now(timezone.utc) - timedelta(days=2)).strftime("%Y-%m-%d")end_date = datetime.now(timezone.utc).strftime("%Y-%m-%d")- # Call the endpoint with both start and end dates.- # We don't need `summarize=true` as it's the default.- response = client.get(- "/spend/logs",- params={- "start_date": start_date,- "end_date": end_date,- },- headers={"Authorization": "Bearer sk-test"},+ app.dependency_overrides[ps.user_api_key_auth] = lambda: UserAPIKeyAuth(+ user_role=LitellmUserRoles.PROXY_ADMIN)+ try:+ # Call the endpoint with both start and end dates.+ # We don't need `summarize=true` as it's the default.+ response = client.get(+ "/spend/logs",+ params={+ "start_date": start_date,+ "end_date": end_date,+ },+ headers={"Authorization": "Bearer sk-test"},+ )- # ASSERTIONS- assert response.status_code == 200- data = response.json()+ # ASSERTIONS+ assert response.status_code == 200+ data = response.json()- # Check that the response is not empty and has the summarized structure.- assert isinstance(data, list)- assert len(data) > 0- assert "startTime" in data[0]- assert "spend" in data[0]- assert "users" in data[0]- assert "models" in data[0]+ # Check that the response is not empty and has the summarized structure.+ assert isinstance(data, list)+ assert len(data) > 0+ assert "startTime" in data[0]+ assert "spend" in data[0]+ assert "users" in data[0]+ assert "models" in data[0]+ finally:+ app.dependency_overrides.pop(ps.user_api_key_auth, None)@pytest.mark.asyncio