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]

test(test_internal_user_endpoints.py): add unit testing to handle user_email=None

Krrish Dholakia1ebdeb852c32
diff --git a/tests/litellm/proxy/management_endpoints/test_internal_user_endpoints.py b/tests/litellm/proxy/management_endpoints/test_internal_user_endpoints.py
new file mode 100644
index 00000000000..697be8b3c9b
--- /dev/null
+++ b/tests/litellm/proxy/management_endpoints/test_internal_user_endpoints.py
@@ -0,0 +1,57 @@
+import json
+import os
+import sys
+
+import pytest
+from fastapi.testclient import TestClient
+
+sys.path.insert(
+ 0, os.path.abspath("../../../..")
+) # Adds the parent directory to the system path
+
+from litellm.proxy._types import LiteLLM_UserTableFiltered, UserAPIKeyAuth
+from litellm.proxy.management_endpoints.internal_user_endpoints import ui_view_users
+from litellm.proxy.proxy_server import app
+
+client = TestClient(app)
+
+
+async def test_ui_view_users_with_null_email(mocker, caplog):
+ """
+ Test that /user/filter/ui endpoint returns users even when they have null email fields
+ """
+ # Mock the prisma client
+ mock_prisma_client = mocker.MagicMock()
+
+ # Create mock user data with null email
+ mock_user = mocker.MagicMock()
+ mock_user.model_dump.return_value = {
+ "user_id": "test-user-null-email",
+ "user_email": None,
+ "user_role": "proxy_admin",
+ "created_at": "2024-01-01T00:00:00Z",
+ }
+
+ # Setup the mock find_many response
+ # Setup the mock find_many response as an async function
+ async def mock_find_many(*args, **kwargs):
+ return [mock_user]
+
+ mock_prisma_client.db.litellm_usertable.find_many = mock_find_many
+
+ # Patch the prisma client import in the endpoint
+ mocker.patch("litellm.proxy.proxy_server.prisma_client", mock_prisma_client)
+
+ # Call ui_view_users function directly
+ response = await ui_view_users(
+ user_api_key_dict=UserAPIKeyAuth(user_id="test_user"),
+ user_id="test_user",
+ user_email=None,
+ page=1,
+ page_size=50,
+ )
+
+ assert response == [
+ LiteLLM_UserTableFiltered(user_id="test-user-null-email", user_email=None)
+ ]