diff --git a/tests/test_litellm/proxy/auth/test_multi_budget_windows.py b/tests/test_litellm/proxy/auth/test_multi_budget_windows.py index 7628733754a..ede4a32e5a0 100644 --- a/tests/test_litellm/proxy/auth/test_multi_budget_windows.py +++ b/tests/test_litellm/proxy/auth/test_multi_budget_windows.py @@ -43,7 +43,7 @@ async def test_under_budget_passes(): {"budget_duration": "30d", "max_budget": 100.0, "reset_at": None}, ] ) - with patch( + with patch( # test-quality-ok: get_current_spend is a lazy module import inside the check; no injection seam "litellm.proxy.proxy_server.get_current_spend", new_callable=AsyncMock, return_value=1.0, # well under both windows @@ -71,7 +71,9 @@ async def test_over_first_window_raises(): call_count += 1 return val - with patch("litellm.proxy.proxy_server.get_current_spend", side_effect=fake_get_spend): + with patch( # test-quality-ok: get_current_spend is a lazy module import inside the check + "litellm.proxy.proxy_server.get_current_spend", side_effect=fake_get_spend + ): with pytest.raises(litellm.BudgetExceededError) as exc_info: await _virtual_key_multi_budget_check(valid_token=token) @@ -101,7 +103,9 @@ async def test_over_second_window_raises(): call_count += 1 return val - with patch("litellm.proxy.proxy_server.get_current_spend", side_effect=fake_get_spend): + with patch( # test-quality-ok: get_current_spend is a lazy module import inside the check + "litellm.proxy.proxy_server.get_current_spend", side_effect=fake_get_spend + ): with pytest.raises(litellm.BudgetExceededError) as exc_info: await _virtual_key_multi_budget_check(valid_token=token) @@ -127,7 +131,7 @@ async def test_budget_limit_entry_objects_coerced(): [BudgetLimitEntry(budget_duration="24h", max_budget=10.0)], ) - with patch( + with patch( # test-quality-ok: get_current_spend is a lazy module import inside the check; no injection seam "litellm.proxy.proxy_server.get_current_spend", new_callable=AsyncMock, return_value=1.0, @@ -148,7 +152,7 @@ def _make_user_token(**kwargs) -> UserAPIKeyAuth: @pytest.mark.asyncio async def test_user_with_no_windows_passes(): - await _user_multi_budget_check(valid_token=_make_user_token(), team_object=None, general_settings={}) + assert await _user_multi_budget_check(valid_token=_make_user_token(), team_object=None, general_settings={}) is None @pytest.mark.asyncio @@ -159,7 +163,7 @@ async def test_user_under_all_windows_passes(): {"budget_duration": "30d", "max_budget": 100.0, "reset_at": None}, ] ) - with patch( + with patch( # test-quality-ok: get_current_spend is a lazy module import inside the check; no injection seam "litellm.proxy.proxy_server.get_current_spend", new_callable=AsyncMock, return_value=1.0, @@ -192,7 +196,9 @@ async def test_user_over_any_window_raises(): call_count += 1 return val - with patch("litellm.proxy.proxy_server.get_current_spend", side_effect=fake_get_spend): + with patch( # test-quality-ok: get_current_spend is a lazy module import inside the check + "litellm.proxy.proxy_server.get_current_spend", side_effect=fake_get_spend + ): with pytest.raises(litellm.BudgetExceededError) as exc_info: await _user_multi_budget_check(valid_token=token, team_object=None, general_settings={}) @@ -214,7 +220,7 @@ async def test_jwt_built_token_carries_user_budget_limits_and_is_blocked(): ) assert token.user_budget_limits[0].max_budget == 2.0 - with patch( + with patch( # test-quality-ok: get_current_spend is a lazy module import inside the check; no injection seam "litellm.proxy.proxy_server.get_current_spend", new_callable=AsyncMock, return_value=5.0, @@ -234,7 +240,7 @@ async def test_user_windows_skipped_for_team_key_unless_flag_set(): token = _make_user_token(user_budget_limits=[{"budget_duration": "1d", "max_budget": 2.0, "reset_at": None}]) team = LiteLLM_TeamTable(team_id="team-1") - with patch( + with patch( # test-quality-ok: get_current_spend is a lazy module import inside the check; no injection seam "litellm.proxy.proxy_server.get_current_spend", new_callable=AsyncMock, return_value=100.0, @@ -242,7 +248,7 @@ async def test_user_windows_skipped_for_team_key_unless_flag_set(): await _user_multi_budget_check(valid_token=token, team_object=team, general_settings={}) spend_mock.assert_not_awaited() - with patch( + with patch( # test-quality-ok: get_current_spend is a lazy module import inside the check; no injection seam "litellm.proxy.proxy_server.get_current_spend", new_callable=AsyncMock, return_value=100.0, diff --git a/tests/test_litellm/proxy/management_endpoints/test_internal_user_endpoints.py b/tests/test_litellm/proxy/management_endpoints/test_internal_user_endpoints.py index 40605f29c6b..070af41f644 100644 --- a/tests/test_litellm/proxy/management_endpoints/test_internal_user_endpoints.py +++ b/tests/test_litellm/proxy/management_endpoints/test_internal_user_endpoints.py @@ -4530,20 +4530,24 @@ async def test_new_user_forwards_budget_limits_into_user_persistence(mocker): mock_prisma_client = mocker.MagicMock() mock_prisma_client.db.litellm_usertable.count = mocker.AsyncMock(return_value=5) - mocker.patch("litellm.proxy.proxy_server.prisma_client", mock_prisma_client) - mocker.patch( + mocker.patch( # test-quality-ok: same module-global mocking every test in this file already uses + "litellm.proxy.proxy_server.prisma_client", mock_prisma_client + ) + mocker.patch( # test-quality-ok: same module-global mocking every test in this file already uses "litellm.proxy.management_endpoints.internal_user_endpoints._check_duplicate_user_id", new=mocker.AsyncMock(), ) - mocker.patch( + mocker.patch( # test-quality-ok: same module-global mocking every test in this file already uses "litellm.proxy.management_endpoints.internal_user_endpoints._check_duplicate_user_email", new=mocker.AsyncMock(), ) mock_license = mocker.MagicMock() mock_license.is_over_limit.return_value = False - mocker.patch("litellm.proxy.proxy_server._license_check", mock_license) + mocker.patch( # test-quality-ok: same module-global mocking every test in this file already uses + "litellm.proxy.proxy_server._license_check", mock_license + ) - helper = mocker.patch( + helper = mocker.patch( # test-quality-ok: same module-global mocking every test in this file already uses "litellm.proxy.management_endpoints.internal_user_endpoints.generate_key_helper_fn", new=mocker.AsyncMock(return_value={"user_id": "u-1", "key": "sk-1", "expires": None}), ) @@ -4574,8 +4578,10 @@ async def test_new_user_rejects_malformed_budget_limits(mocker, windows): from litellm.proxy.management_endpoints.internal_user_endpoints import new_user mock_prisma_client = mocker.MagicMock() - mocker.patch("litellm.proxy.proxy_server.prisma_client", mock_prisma_client) - duplicate_check = mocker.patch( + mocker.patch( # test-quality-ok: same module-global mocking every test in this file already uses + "litellm.proxy.proxy_server.prisma_client", mock_prisma_client + ) + duplicate_check = mocker.patch( # test-quality-ok: same module-global mocking every test in this file already uses "litellm.proxy.management_endpoints.internal_user_endpoints._check_duplicate_user_id", new=mocker.AsyncMock(), )