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(router): type the deployment affinity JWT test helpers
mateo-berri9c7c7a05ac92
diff --git a/tests/test_litellm/router_utils/pre_call_checks/test_deployment_affinity_check.py b/tests/test_litellm/router_utils/pre_call_checks/test_deployment_affinity_check.pyindex 1852d641f0a..b5651062098 100644--- a/tests/test_litellm/router_utils/pre_call_checks/test_deployment_affinity_check.py+++ b/tests/test_litellm/router_utils/pre_call_checks/test_deployment_affinity_check.py@@ -1,11 +1,12 @@import asyncio+import itertools+import json+from collections.abc import Sequence+from typing import Finalfrom unittest.mock import AsyncMock, patchimport pytest--import json-import litellmfrom litellm.caching.dual_cache import DualCachefrom litellm.router_utils.pre_call_checks.deployment_affinity_check import (@@ -102,11 +103,10 @@ async def test_async_user_key_affinity_routes_to_same_deployment():# Deterministic routing: first selection uses seq[0], second selection attempts seq[1]# unless the list has been filtered to length=1 by deployment affinity.- choice_calls = {"count": 0}+ choice_calls: Final = itertools.count(1)- def deterministic_choice(seq):- choice_calls["count"] += 1- if choice_calls["count"] == 1:+ def deterministic_choice(seq: Sequence[dict[str, object]]) -> dict[str, object]:+ if next(choice_calls) == 1:return seq[0]return seq[1] if len(seq) > 1 else seq[0]@@ -1000,7 +1000,7 @@ async def test_model_group_affinity_config_overrides_global():assert len(filtered) == 2-def _jwt_metadata(user_id: str) -> dict:+def _jwt_metadata(user_id: str) -> dict[str, str | None]:return {"user_api_key_hash": None, "user_api_key_user_id": user_id}@@ -1090,7 +1090,7 @@ async def test_proxy_jwt_auth_metadata_pins_per_user():enable_responses_api_affinity=False,)- def proxy_request(user_id: str) -> dict:+ def proxy_request(user_id: str) -> dict[str, object]:return LiteLLMProxyRequestSetup.add_user_api_key_auth_to_request_metadata(data={"model": model_group, "messages": [{"role": "user", "content": "hi"}], "metadata": {}},user_api_key_dict=UserAPIKeyAuth(api_key=None, user_id=user_id),@@ -1098,12 +1098,14 @@ async def test_proxy_jwt_auth_metadata_pins_per_user():)alice_request = proxy_request("jwt-user-alice")- assert alice_request["metadata"]["user_api_key_hash"] is None+ alice_metadata = alice_request["metadata"]+ assert isinstance(alice_metadata, dict)+ assert alice_metadata["user_api_key_hash"] is Noneawait callback.async_pre_call_deployment_hook(kwargs={**alice_request,- "metadata": {**alice_request["metadata"], "deployment_model_name": model_group},+ "metadata": {**alice_metadata, "deployment_model_name": model_group},"model_info": {"id": "openai-deployment-b"},},call_type=None,