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

Commit

Permalink
Modify tests per balance constraint (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Aug 4, 2012
1 parent fccfa07 commit ab337b1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions gittip/billing/payday.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def transfer(self, tipper, tippee, amount):

try:
self.debit_participant(cursor, tipper, amount)
except ValueError:
except IntegrityError:
return False

self.credit_participant(cursor, tippee, amount)
Expand All @@ -288,13 +288,13 @@ def debit_participant(self, cursor, participant, amount):
RETURNING balance
"""

# This will fail with IntegrityError if the balanced goes below zero.
# We catch that and return false in our caller.
cursor.execute(DECREMENT, (amount, participant))

rec = cursor.fetchone()
assert rec is not None, (amount, participant) # sanity check
if rec['balance'] < 0:
# User is out of money. Bail. The transaction will be rolled back
# by our context manager.
raise ValueError() # TODO: proper exception type


def credit_participant(self, cursor, participant, amount):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def setUp(self):
super(TestCard, self).setUp()
self.balanced_account_uri = '/v1/marketplaces/M123/accounts/A123'
self.stripe_customer_id = 'deadbeef'

@mock.patch('balanced.Account')
def test_balanced_card(self, ba):
card = mock.Mock()
Expand Down Expand Up @@ -702,7 +702,7 @@ def get_balance_amount(participant):
with self.db.get_connection() as conn:
cur = conn.cursor()

with self.assertRaises(ValueError):
with self.assertRaises(IntegrityError):
self.payday.debit_participant(cur, participant, amount)

def test_credit_participant(self):
Expand Down

0 comments on commit ab337b1

Please sign in to comment.