@@ -54,11 +54,11 @@ async def mock_find_many(*args, **kwargs):
5454
5555 mock_prisma_client .db .litellm_usertable .find_many = mock_find_many
5656
57- # Flag OFF by default — no settings row
58- async def mock_find_unique_settings ( * args , ** kwargs ):
59- return None
60-
61- mock_prisma_client . db . litellm_uisettings . find_unique = mock_find_unique_settings
57+ # Flag OFF by default
58+ mocker . patch (
59+ "litellm.proxy.ui_crud_endpoints.proxy_setting_endpoints.get_ui_settings_cached" ,
60+ return_value = {},
61+ )
6262
6363 mocker .patch ("litellm.proxy.proxy_server.prisma_client" , mock_prisma_client )
6464
@@ -92,10 +92,10 @@ async def mock_find_many(*args, **kwargs):
9292 mock_prisma_client .db .litellm_usertable .find_many = mock_find_many
9393
9494 # Flag OFF by default
95- async def mock_find_unique_settings ( * args , ** kwargs ):
96- return None
97-
98- mock_prisma_client . db . litellm_uisettings . find_unique = mock_find_unique_settings
95+ mocker . patch (
96+ "litellm.proxy.ui_crud_endpoints.proxy_setting_endpoints.get_ui_settings_cached" ,
97+ return_value = {},
98+ )
9999 mocker .patch ("litellm.proxy.proxy_server.prisma_client" , mock_prisma_client )
100100
101101 await ui_view_users (
@@ -132,13 +132,10 @@ async def mock_find_many(*args, **kwargs):
132132 mock_prisma_client .db .litellm_usertable .find_many = mock_find_many
133133
134134 # Flag ON
135- mock_settings_row = mocker .MagicMock ()
136- mock_settings_row .settings = {"scope_user_search_to_org" : True }
137-
138- async def mock_find_unique_settings (* args , ** kwargs ):
139- return mock_settings_row
140-
141- mock_prisma_client .db .litellm_uisettings .find_unique = mock_find_unique_settings
135+ mocker .patch (
136+ "litellm.proxy.ui_crud_endpoints.proxy_setting_endpoints.get_ui_settings_cached" ,
137+ return_value = {"scope_user_search_to_org" : True },
138+ )
142139
143140 mocker .patch ("litellm.proxy.proxy_server.prisma_client" , mock_prisma_client )
144141 mocker .patch ("litellm.proxy.proxy_server.user_api_key_cache" , mocker .MagicMock ())
@@ -185,13 +182,10 @@ async def test_ui_view_users_non_org_admin_returns_403(mocker):
185182 mock_prisma_client = mocker .MagicMock ()
186183
187184 # Flag ON
188- mock_settings_row = mocker .MagicMock ()
189- mock_settings_row .settings = {"scope_user_search_to_org" : True }
190-
191- async def mock_find_unique_settings (* args , ** kwargs ):
192- return mock_settings_row
193-
194- mock_prisma_client .db .litellm_uisettings .find_unique = mock_find_unique_settings
185+ mocker .patch (
186+ "litellm.proxy.ui_crud_endpoints.proxy_setting_endpoints.get_ui_settings_cached" ,
187+ return_value = {"scope_user_search_to_org" : True },
188+ )
195189
196190 mocker .patch ("litellm.proxy.proxy_server.prisma_client" , mock_prisma_client )
197191 mocker .patch ("litellm.proxy.proxy_server.user_api_key_cache" , mocker .MagicMock ())
@@ -237,11 +231,11 @@ async def mock_find_many(*args, **kwargs):
237231
238232 mock_prisma_client .db .litellm_usertable .find_many = mock_find_many
239233
240- # Flag OFF — no settings row
241- async def mock_find_unique_settings ( * args , ** kwargs ):
242- return None
243-
244- mock_prisma_client . db . litellm_uisettings . find_unique = mock_find_unique_settings
234+ # Flag OFF
235+ mocker . patch (
236+ "litellm.proxy.ui_crud_endpoints.proxy_setting_endpoints.get_ui_settings_cached" ,
237+ return_value = {},
238+ )
245239 mocker .patch ("litellm.proxy.proxy_server.prisma_client" , mock_prisma_client )
246240
247241 response = await ui_view_users (
@@ -261,7 +255,7 @@ async def test_ui_view_users_flag_on_team_admin_org_team(mocker):
261255 """
262256 Flag ON, team admin for org-bound team: org filter is applied using team's org.
263257 """
264- from litellm .proxy ._types import LiteLLM_TeamTable , Member
258+ from litellm .proxy ._types import LiteLLM_TeamTableCachedObj
265259
266260 mock_prisma_client = mocker .MagicMock ()
267261 org_id = "org-456"
@@ -278,30 +272,26 @@ async def mock_find_many(*args, **kwargs):
278272 mock_prisma_client .db .litellm_usertable .find_many = mock_find_many
279273
280274 # Flag ON
281- mock_settings_row = mocker .MagicMock ()
282- mock_settings_row .settings = {"scope_user_search_to_org" : True }
283-
284- async def mock_find_unique_settings (* args , ** kwargs ):
285- return mock_settings_row
286-
287- mock_prisma_client .db .litellm_uisettings .find_unique = mock_find_unique_settings
288-
289- # Team lookup
290- mock_team_row = mocker .MagicMock ()
291- mock_team_row .model_dump .return_value = {
292- "team_id" : tid ,
293- "team_alias" : "test-team" ,
294- "organization_id" : org_id ,
295- "members_with_roles" : [{"user_id" : "team-admin-user" , "role" : "admin" }],
296- "admins" : [],
297- "members" : [],
298- "blocked" : False ,
299- }
275+ mocker .patch (
276+ "litellm.proxy.ui_crud_endpoints.proxy_setting_endpoints.get_ui_settings_cached" ,
277+ return_value = {"scope_user_search_to_org" : True },
278+ )
279+
280+ # Mock get_team_object
281+ team_obj = LiteLLM_TeamTableCachedObj (
282+ team_id = tid ,
283+ team_alias = "test-team" ,
284+ organization_id = org_id ,
285+ members_with_roles = [{"user_id" : "team-admin-user" , "role" : "admin" }],
286+ )
300287
301- async def mock_find_unique_team (* args , ** kwargs ):
302- return mock_team_row
288+ async def mock_get_team_object (* args , ** kwargs ):
289+ return team_obj
303290
304- mock_prisma_client .db .litellm_teamtable .find_unique = mock_find_unique_team
291+ mocker .patch (
292+ "litellm.proxy.management_endpoints.internal_user_endpoints.get_team_object" ,
293+ side_effect = mock_get_team_object ,
294+ )
305295
306296 mocker .patch ("litellm.proxy.proxy_server.prisma_client" , mock_prisma_client )
307297 mocker .patch ("litellm.proxy.proxy_server.user_api_key_cache" , mocker .MagicMock ())
@@ -337,35 +327,32 @@ async def test_ui_view_users_flag_on_team_admin_non_org_team_403(mocker):
337327 Flag ON, team admin for non-org team: returns 403.
338328 """
339329 from fastapi import HTTPException
330+ from litellm .proxy ._types import LiteLLM_TeamTableCachedObj
340331
341332 mock_prisma_client = mocker .MagicMock ()
342333 tid = "team-no-org"
343334
344335 # Flag ON
345- mock_settings_row = mocker .MagicMock ()
346- mock_settings_row .settings = {"scope_user_search_to_org" : True }
347-
348- async def mock_find_unique_settings (* args , ** kwargs ):
349- return mock_settings_row
350-
351- mock_prisma_client .db .litellm_uisettings .find_unique = mock_find_unique_settings
352-
353- # Team lookup — no organization_id
354- mock_team_row = mocker .MagicMock ()
355- mock_team_row .model_dump .return_value = {
356- "team_id" : tid ,
357- "team_alias" : "no-org-team" ,
358- "organization_id" : None ,
359- "members_with_roles" : [{"user_id" : "team-admin-user" , "role" : "admin" }],
360- "admins" : [],
361- "members" : [],
362- "blocked" : False ,
363- }
336+ mocker .patch (
337+ "litellm.proxy.ui_crud_endpoints.proxy_setting_endpoints.get_ui_settings_cached" ,
338+ return_value = {"scope_user_search_to_org" : True },
339+ )
364340
365- async def mock_find_unique_team (* args , ** kwargs ):
366- return mock_team_row
341+ # Mock get_team_object — team has no organization_id
342+ team_obj = LiteLLM_TeamTableCachedObj (
343+ team_id = tid ,
344+ team_alias = "no-org-team" ,
345+ organization_id = None ,
346+ members_with_roles = [{"user_id" : "team-admin-user" , "role" : "admin" }],
347+ )
367348
368- mock_prisma_client .db .litellm_teamtable .find_unique = mock_find_unique_team
349+ async def mock_get_team_object (* args , ** kwargs ):
350+ return team_obj
351+
352+ mocker .patch (
353+ "litellm.proxy.management_endpoints.internal_user_endpoints.get_team_object" ,
354+ side_effect = mock_get_team_object ,
355+ )
369356
370357 mocker .patch ("litellm.proxy.proxy_server.prisma_client" , mock_prisma_client )
371358 mocker .patch ("litellm.proxy.proxy_server.user_api_key_cache" , mocker .MagicMock ())
@@ -409,13 +396,10 @@ async def test_ui_view_users_flag_on_non_admin_no_team_id_403(mocker):
409396 mock_prisma_client = mocker .MagicMock ()
410397
411398 # Flag ON
412- mock_settings_row = mocker .MagicMock ()
413- mock_settings_row .settings = {"scope_user_search_to_org" : True }
414-
415- async def mock_find_unique_settings (* args , ** kwargs ):
416- return mock_settings_row
417-
418- mock_prisma_client .db .litellm_uisettings .find_unique = mock_find_unique_settings
399+ mocker .patch (
400+ "litellm.proxy.ui_crud_endpoints.proxy_setting_endpoints.get_ui_settings_cached" ,
401+ return_value = {"scope_user_search_to_org" : True },
402+ )
419403
420404 mocker .patch ("litellm.proxy.proxy_server.prisma_client" , mock_prisma_client )
421405 mocker .patch ("litellm.proxy.proxy_server.user_api_key_cache" , mocker .MagicMock ())
0 commit comments