Skip to content

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]

[Fix] Use correct Redis env vars and fix Azure AD token test mocking

Yuneng Jiang05ecfa3470f6
diff --git a/tests/local_testing/test_caching_ssl.py b/tests/local_testing/test_caching_ssl.py
index 523976f1237..f94b7024736 100644
--- a/tests/local_testing/test_caching_ssl.py
+++ b/tests/local_testing/test_caching_ssl.py
@@ -69,10 +69,10 @@ def test_caching_router():
]
litellm.cache = Cache(
type="redis",
- host="os.environ/REDIS_HOST_2",
- port="os.environ/REDIS_PORT_2",
- password="os.environ/REDIS_PASSWORD_2",
- ssl="os.environ/REDIS_SSL_2",
+ host="os.environ/REDIS_HOST",
+ port="os.environ/REDIS_PORT",
+ password="os.environ/REDIS_PASSWORD",
+ ssl="os.environ/REDIS_SSL",
)
router = Router(
model_list=model_list,
diff --git a/tests/local_testing/test_router_client_init.py b/tests/local_testing/test_router_client_init.py
index f2541601c3b..f53ca1ced86 100644
--- a/tests/local_testing/test_router_client_init.py
+++ b/tests/local_testing/test_router_client_init.py
@@ -71,9 +71,7 @@ def test_router_init_with_neither_api_key_nor_azure_service_principal_with_secre
@patch("azure.identity.get_bearer_token_provider")
@patch("azure.identity.ClientSecretCredential")
-@patch("litellm.secret_managers.get_azure_ad_token_provider.os")
def test_router_init_azure_service_principal_with_secret_with_environment_variables(
- mocked_os_lib: MagicMock,
mocked_credential: MagicMock,
mocked_get_bearer_token_provider: MagicMock,
monkeypatch,
@@ -86,21 +84,17 @@ def test_router_init_azure_service_principal_with_secret_with_environment_variab
and environment variables.
"""
monkeypatch.delenv("AZURE_API_KEY", raising=False)
+ monkeypatch.delenv("AZURE_OPENAI_API_KEY", raising=False)
litellm.enable_azure_ad_token_refresh = True
# mock the token provider function
mocked_func_generating_token = MagicMock(return_value="test_token")
mocked_get_bearer_token_provider.return_value = mocked_func_generating_token
- # mock the environment variables with mocked credentials
- environment_variables_expected_to_use = {
- "AZURE_CLIENT_ID": "test_client_id",
- "AZURE_CLIENT_SECRET": "test_client_secret",
- "AZURE_TENANT_ID": "test_tenant_id",
- }
- mocked_environ = PropertyMock(return_value=environment_variables_expected_to_use)
- # Because of the way mock attributes are stored you can’t directly attach a PropertyMock to a mock object.
- # https://docs.python.org/3.11/library/unittest.mock.html#unittest.mock.PropertyMock
- type(mocked_os_lib).environ = mocked_environ
+ # set environment variables with mocked credentials using monkeypatch
+ # so both common_utils._resolve_env_var and get_azure_ad_token_provider see them
+ monkeypatch.setenv("AZURE_CLIENT_ID", "test_client_id")
+ monkeypatch.setenv("AZURE_CLIENT_SECRET", "test_client_secret")
+ monkeypatch.setenv("AZURE_TENANT_ID", "test_tenant_id")
# define the model list
model_list = [