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
test(proxy): forward each method through the typesafe route to a mocked upstream
Yuneng Jiang349e8b93583d
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 07936e7a9e9..9394a13fee4 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@@ -6149,9 +6149,41 @@ class TestTypeSafePassthroughRoute:request.json = AsyncMock(return_value=body)return request- @pytest.mark.parametrize("method", ["GET", "POST", "PUT", "DELETE", "PATCH"])- def test_route_serves_every_method(self, method: str):- assert _resolve_route_name(method, "/typesafe/v1/systemone") == "typesafe_proxy_route"+ @pytest.fixture+ def client(self, monkeypatch: pytest.MonkeyPatch) -> Iterator[TestClient]:+ from litellm.proxy.proxy_server import app++ monkeypatch.setenv("TYPESAFE_API_KEY", "typesafe-test-key")+ monkeypatch.setenv("TYPESAFE_API_BASE", "https://typesafe.example/base")+ monkeypatch.delenv("SERVER_ROOT_PATH", raising=False)+ monkeypatch.setattr(litellm, "disable_aiohttp_transport", True)+ litellm.in_memory_llm_clients_cache.flush_cache()+ monkeypatch.setitem(app.dependency_overrides, user_api_key_auth, lambda: UserAPIKeyAuth(api_key="sk-virtual"))+ yield TestClient(app)++ @pytest.mark.parametrize(+ "method, body",+ [+ ("GET", None),+ ("POST", {"state": "x"}),+ ("PUT", {"state": "x"}),+ ("DELETE", None),+ ("PATCH", {"state": "x"}),+ ],+ )+ def test_forwards_every_method_and_body_upstream(+ self, client: TestClient, method: str, body: dict[str, str] | None+ ) -> None:+ with respx.mock(assert_all_called=True) as upstream:+ route = upstream.request(method, "https://typesafe.example/base/v1/systemone").mock(+ return_value=httpx.Response(200, json={"id": "upstream_123"})+ )+ response = client.request(method, "/typesafe/v1/systemone", json=body)++ assert (response.status_code, response.json()) == (200, {"id": "upstream_123"})+ sent: Final = route.calls.last.request+ assert sent.headers["authorization"] == "Bearer typesafe-test-key"+ assert json.loads(sent.content or b"{}") == (body or {})@pytest.mark.asyncioasync def test_forwards_target_auth_headers_provider_and_query(self, monkeypatch):