From 309738449f87e13cd347a48bd55264d04d42447e Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Wed, 18 Jun 2025 09:55:58 -0700 Subject: [PATCH] test_scim_v2_endpoints.py --- .../scim/test_scim_v2_endpoints.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/test_litellm/proxy/management_endpoints/scim/test_scim_v2_endpoints.py b/tests/test_litellm/proxy/management_endpoints/scim/test_scim_v2_endpoints.py index 8f7ec1f9b46..4f0740469ae 100644 --- a/tests/test_litellm/proxy/management_endpoints/scim/test_scim_v2_endpoints.py +++ b/tests/test_litellm/proxy/management_endpoints/scim/test_scim_v2_endpoints.py @@ -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()