From 233ba9d4b88197494fc9100e8c219842bd4fdbca Mon Sep 17 00:00:00 2001 From: Sameer Kankute Date: Fri, 2 Jan 2026 21:40:27 +0530 Subject: [PATCH] fix mock tests --- .../test_budget_endpoints.py | 16 +++---- .../test_key_management_endpoints.py | 33 +++++++------- .../test_team_endpoints.py | 43 +++++++++---------- 3 files changed, 45 insertions(+), 47 deletions(-) diff --git a/tests/test_litellm/proxy/management_endpoints/test_budget_endpoints.py b/tests/test_litellm/proxy/management_endpoints/test_budget_endpoints.py index c22ab523158..d5c3ecae7d6 100644 --- a/tests/test_litellm/proxy/management_endpoints/test_budget_endpoints.py +++ b/tests/test_litellm/proxy/management_endpoints/test_budget_endpoints.py @@ -180,10 +180,10 @@ async def test_new_budget_negative_max_budget(client_and_mocks): "max_budget": -7.0, } resp = client.post("/budget/new", json=payload) - assert resp.status_code == 422, resp.text + assert resp.status_code == 400, resp.text detail = resp.json()["detail"] - assert any("max_budget cannot be negative" in str(error) for error in detail) + assert "max_budget cannot be negative" in str(detail) @pytest.mark.asyncio @@ -198,10 +198,10 @@ async def test_new_budget_negative_soft_budget(client_and_mocks): "soft_budget": -10.0, } resp = client.post("/budget/new", json=payload) - assert resp.status_code == 422, resp.text + assert resp.status_code == 400, resp.text detail = resp.json()["detail"] - assert any("soft_budget cannot be negative" in str(error) for error in detail) + assert "soft_budget cannot be negative" in str(detail) @pytest.mark.asyncio @@ -216,10 +216,10 @@ async def test_update_budget_negative_max_budget(client_and_mocks): "max_budget": -5.0, } resp = client.post("/budget/update", json=payload) - assert resp.status_code == 422, resp.text + assert resp.status_code == 400, resp.text detail = resp.json()["detail"] - assert any("max_budget cannot be negative" in str(error) for error in detail) + assert "max_budget cannot be negative" in str(detail) @pytest.mark.asyncio @@ -234,7 +234,7 @@ async def test_update_budget_negative_soft_budget(client_and_mocks): "soft_budget": -15.0, } resp = client.post("/budget/update", json=payload) - assert resp.status_code == 422, resp.text + assert resp.status_code == 400, resp.text detail = resp.json()["detail"] - assert any("soft_budget cannot be negative" in str(error) for error in detail) + assert "soft_budget cannot be negative" in str(detail) diff --git a/tests/test_litellm/proxy/management_endpoints/test_key_management_endpoints.py b/tests/test_litellm/proxy/management_endpoints/test_key_management_endpoints.py index 689bfcc2397..3e69b4e0caf 100644 --- a/tests/test_litellm/proxy/management_endpoints/test_key_management_endpoints.py +++ b/tests/test_litellm/proxy/management_endpoints/test_key_management_endpoints.py @@ -3522,26 +3522,25 @@ async def test_list_keys_with_expand_user(): @pytest.mark.asyncio async def test_generate_key_negative_max_budget(): """ - Test that GenerateKeyRequest rejects negative max_budget values. + Test that GenerateKeyRequest model allows negative max_budget values. + Validation is done at API level, not model level. - This prevents the issue where negative budgets would always trigger - budget exceeded errors. + This prevents GET requests from breaking when they receive data with negative budgets. """ - with pytest.raises(ValueError) as exc_info: - GenerateKeyRequest(max_budget=-7.0) - - assert "max_budget cannot be negative" in str(exc_info.value) + # Should not raise any errors at model level + request = GenerateKeyRequest(max_budget=-7.0) + assert request.max_budget == -7.0 @pytest.mark.asyncio async def test_generate_key_negative_soft_budget(): """ - Test that GenerateKeyRequest rejects negative soft_budget values. + Test that GenerateKeyRequest model allows negative soft_budget values. + Validation is done at API level, not model level. """ - with pytest.raises(ValueError) as exc_info: - GenerateKeyRequest(soft_budget=-10.0) - - assert "soft_budget cannot be negative" in str(exc_info.value) + # Should not raise any errors at model level + request = GenerateKeyRequest(soft_budget=-10.0) + assert request.soft_budget == -10.0 @pytest.mark.asyncio @@ -3558,9 +3557,9 @@ async def test_generate_key_positive_budgets_accepted(): @pytest.mark.asyncio async def test_update_key_negative_max_budget(): """ - Test that UpdateKeyRequest rejects negative max_budget values. + Test that UpdateKeyRequest model allows negative max_budget values. + Validation is done at API level, not model level. """ - with pytest.raises(ValueError) as exc_info: - UpdateKeyRequest(key="test-key", max_budget=-5.0) - - assert "max_budget cannot be negative" in str(exc_info.value) + # Should not raise any errors at model level + request = UpdateKeyRequest(key="test-key", max_budget=-5.0) + assert request.max_budget == -5.0 diff --git a/tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py b/tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py index 85bb236c716..6cf8f745e07 100644 --- a/tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py +++ b/tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py @@ -3963,56 +3963,55 @@ async def test_update_team_guardrails_with_org_id(): @pytest.mark.asyncio async def test_new_team_negative_max_budget(): """ - Test that NewTeamRequest rejects negative max_budget values. + Test that NewTeamRequest model allows negative max_budget values. + Validation is done at API level, not model level. - This prevents the issue where negative budgets would always trigger - budget exceeded errors. + This prevents GET requests from breaking when they receive data with negative budgets. """ from litellm.proxy._types import NewTeamRequest - with pytest.raises(ValueError) as exc_info: - NewTeamRequest(team_alias="test-team", max_budget=-7.0) - - assert "max_budget cannot be negative" in str(exc_info.value) + # Should not raise any errors at model level + request = NewTeamRequest(team_alias="test-team", max_budget=-7.0) + assert request.max_budget == -7.0 @pytest.mark.asyncio async def test_new_team_negative_team_member_budget(): """ - Test that NewTeamRequest rejects negative team_member_budget values. + Test that NewTeamRequest model allows negative team_member_budget values. + Validation is done at API level, not model level. """ from litellm.proxy._types import NewTeamRequest - with pytest.raises(ValueError) as exc_info: - NewTeamRequest(team_alias="test-team", team_member_budget=-10.0) - - assert "team_member_budget cannot be negative" in str(exc_info.value) + # Should not raise any errors at model level + request = NewTeamRequest(team_alias="test-team", team_member_budget=-10.0) + assert request.team_member_budget == -10.0 @pytest.mark.asyncio async def test_update_team_negative_max_budget(): """ - Test that UpdateTeamRequest rejects negative max_budget values. + Test that UpdateTeamRequest model allows negative max_budget values. + Validation is done at API level, not model level. """ from litellm.proxy._types import UpdateTeamRequest - with pytest.raises(ValueError) as exc_info: - UpdateTeamRequest(team_id="test-team-id", max_budget=-5.0) - - assert "max_budget cannot be negative" in str(exc_info.value) + # Should not raise any errors at model level + request = UpdateTeamRequest(team_id="test-team-id", max_budget=-5.0) + assert request.max_budget == -5.0 @pytest.mark.asyncio async def test_update_team_negative_team_member_budget(): """ - Test that UpdateTeamRequest rejects negative team_member_budget values. + Test that UpdateTeamRequest model allows negative team_member_budget values. + Validation is done at API level, not model level. """ from litellm.proxy._types import UpdateTeamRequest - with pytest.raises(ValueError) as exc_info: - UpdateTeamRequest(team_id="test-team-id", team_member_budget=-15.0) - - assert "team_member_budget cannot be negative" in str(exc_info.value) + # Should not raise any errors at model level + request = UpdateTeamRequest(team_id="test-team-id", team_member_budget=-15.0) + assert request.team_member_budget == -15.0 @pytest.mark.asyncio