fix mock tests

This commit is contained in:
Sameer Kankute 2026-01-02 21:40:27 +05:30
parent 05e37e0600
commit 233ba9d4b8
3 changed files with 45 additions and 47 deletions

View file

@ -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)

View file

@ -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

View file

@ -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