mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-08 03:08:45 +00:00
test(test_internal_user_endpoints.py): add unit testing to handle user_email=None
This commit is contained in:
parent
2d1082f520
commit
1ebdeb852c
1 changed files with 57 additions and 0 deletions
|
|
@ -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)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
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)
|
||||
]
|
||||
Loading…
Add table
Reference in a new issue