Null amount validator was broken (#990)

This commit is contained in:
Glandos 2022-01-30 16:33:18 +01:00 committed by GitHub
parent a5452ccee5
commit 07e1eac0a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 1 deletions

View file

@ -382,7 +382,7 @@ class BillForm(FlaskForm):
self.payed_for.data = self.payed_for.default
def validate_amount(self, field):
if field.data == 0:
if field.data == "0":
raise ValidationError(_("Bills can't be null"))

View file

@ -910,6 +910,25 @@ class APITestCase(IhatemoneyTestCase):
self.assertEqual(resp.data.decode("utf-8").count("<td> -- </td>"), 2)
self.assertNotIn("127.0.0.1", resp.data.decode("utf-8"))
def test_amount_is_null(self):
self.api_create("raclette")
# add participants
self.api_add_member("raclette", "zorglub")
# add a bill null amount
req = self.client.post(
"/api/projects/raclette/bills",
data={
"date": "2011-08-10",
"what": "fromage",
"payer": "1",
"payed_for": ["1"],
"amount": "0",
},
headers=self.get_auth("raclette"),
)
self.assertStatus(400, req)
def test_project_creation_with_mixed_case(self):
self.api_create("Raclette")
# get information about it

View file

@ -1531,6 +1531,30 @@ class BudgetTestCase(IhatemoneyTestCase):
]
assert no_currency_bills == [(5.0, 5.0), (10.0, 10.0)]
def test_amount_is_null(self):
self.post_project("raclette")
# add participants
self.client.post("/raclette/members/add", data={"name": "zorglub"})
# null amount
resp = self.client.post(
"/raclette/add",
data={
"date": "2016-12-31",
"what": "fromage à raclette",
"payer": 1,
"payed_for": [1],
"amount": "0",
"original_currency": "EUR",
},
)
assert '<p class="alert alert-danger">' in resp.data.decode("utf-8")
resp = self.client.get("/raclette/")
# No bills, the previous one was not added
assert "No bills" in resp.data.decode("utf-8")
def test_decimals_on_weighted_members_list(self):
self.post_project("raclette")