mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
test_scim_v2_endpoints.py
This commit is contained in:
parent
718ee12f4e
commit
309738449f
1 changed files with 13 additions and 6 deletions
|
|
@ -1,6 +1,7 @@
|
|||
from unittest.mock import AsyncMock
|
||||
|
||||
import pytest
|
||||
from fastapi import HTTPException
|
||||
|
||||
from litellm.proxy.management_endpoints.scim.scim_errors import ScimUserAlreadyExists
|
||||
from litellm.proxy.management_endpoints.scim.scim_v2 import create_user
|
||||
|
|
@ -22,21 +23,27 @@ async def test_create_user_existing_user_conflict(mocker):
|
|||
emails=[SCIMUserEmail(value="existing@example.com")],
|
||||
)
|
||||
|
||||
mock_prisma = mocker.MagicMock()
|
||||
# Create a properly structured mock for the prisma client
|
||||
mock_prisma_client = mocker.MagicMock()
|
||||
mock_prisma_client.db = mocker.MagicMock()
|
||||
mock_prisma_client.db.litellm_usertable = mocker.MagicMock()
|
||||
mock_prisma_client.db.litellm_usertable.find_unique = AsyncMock(return_value={"user_id": "existing-user"})
|
||||
|
||||
mocker.patch("litellm.proxy.proxy_server.prisma_client", mock_prisma)
|
||||
# Mock the _get_prisma_client_or_raise_exception to return our mock
|
||||
mocker.patch(
|
||||
"litellm.proxy.management_endpoints.scim.scim_v2._check_user_exists",
|
||||
AsyncMock(return_value=True),
|
||||
"litellm.proxy.management_endpoints.scim.scim_v2._get_prisma_client_or_raise_exception",
|
||||
AsyncMock(return_value=mock_prisma_client),
|
||||
)
|
||||
|
||||
mocked_new_user = mocker.patch(
|
||||
"litellm.proxy.management_endpoints.scim.scim_v2.new_user",
|
||||
AsyncMock(),
|
||||
)
|
||||
|
||||
with pytest.raises(ScimUserAlreadyExists) as exc_info:
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
await create_user(user=scim_user)
|
||||
|
||||
# Check that it's an HTTPException with status 409
|
||||
assert exc_info.value.status_code == 409
|
||||
assert "existing-user" in exc_info.value.message
|
||||
assert "existing-user" in str(exc_info.value.detail)
|
||||
mocked_new_user.assert_not_called()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue