Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Merge pull request #1554 from gittip/fix-badamount
Browse files Browse the repository at this point in the history
Fix badamount
  • Loading branch information
chadwhitacre committed Oct 8, 2013
2 parents 80cac93 + eb1b79a commit 86b5161
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
20 changes: 20 additions & 0 deletions tests/test_tip_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,23 @@ def test_get_amount_and_total_back_from_api(self):
assert first_data['total_giving'] == "1.00"
assert second_data['amount'] == "3.00"
assert second_data['total_giving'] == "4.00"

def test_set_tip_out_of_range(self):
client = TestClient()
now = datetime.datetime.now(pytz.utc)
self.make_participant("alice", claimed_time=now)
self.make_participant("bob", claimed_time=now)

response = client.get('/')
csrf_token = response.request.context['csrf_token']
response = client.post("/alice/tip.json",
{'amount': "110.00", 'csrf_token': csrf_token},
user='bob')
assert "bad amount" in response.body
assert response.code == 400

response = client.post("/alice/tip.json",
{'amount': "-1.00", 'csrf_token': csrf_token},
user='bob')
assert "bad amount" in response.body
assert response.code == 400
4 changes: 2 additions & 2 deletions www/%username/tip.json.spt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from decimal import InvalidOperation

from aspen import Response
from gittip.models.participant import Participant
from gittip.models.participant import Participant, BadAmount

[-----------------------------------------------------------------------------]

Expand All @@ -30,7 +30,7 @@ if not user.ANON:
amount, first_time_tipper = tipper.set_tip_to( tippee.username
, body['amount']
)
except (InvalidOperation, ValueError):
except (InvalidOperation, ValueError, BadAmount):
raise Response(400, "bad amount")
else:
amount = tipper.get_tip_to(tippee.username)
Expand Down

0 comments on commit 86b5161

Please sign in to comment.