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

Payday fixes #3431

Merged
merged 3 commits into from
May 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sql/payday.sql
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ CREATE TEMPORARY TABLE payday_subscriptions ON COMMIT DROP AS
ORDER BY subscriber, team, mtime DESC
) s
JOIN payday_participants p ON p.username = s.subscriber
JOIN payday_teams t ON t.slug = s.team
WHERE s.amount > 0
AND ( SELECT id
FROM payday_payments_done done
Expand Down
20 changes: 12 additions & 8 deletions tests/py/test_billing_payday.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def test_payday_doesnt_move_money_from_a_suspicious_account(self, fch):
SET is_suspicious = true
WHERE username = 'janet'
""")
self.janet.set_tip_to(self.homer, '6.00') # under $10!
team = self.make_team(owner=self.homer, is_approved=True)
self.janet.set_subscription_to(team, '6.00') # under $10!
fch.return_value = {}
Payday.start().run()

Expand All @@ -55,7 +56,8 @@ def test_payday_doesnt_move_money_to_a_suspicious_account(self, fch):
SET is_suspicious = true
WHERE username = 'homer'
""")
self.janet.set_tip_to(self.homer, '6.00') # under $10!
team = self.make_team(owner=self.homer, is_approved=True)
self.janet.set_subscription_to(team, '6.00') # under $10!
fch.return_value = {}
Payday.start().run()

Expand All @@ -67,7 +69,8 @@ def test_payday_doesnt_move_money_to_a_suspicious_account(self, fch):

@mock.patch.object(Payday, 'fetch_card_holds')
def test_payday_moves_money_with_balanced(self, fch):
self.janet.set_tip_to(self.homer, '15.00')
team = self.make_team(owner=self.homer, is_approved=True)
self.janet.set_subscription_to(team, '15.00')
fch.return_value = {}
Payday.start().run()

Expand Down Expand Up @@ -275,7 +278,8 @@ def test_hold_amount_includes_negative_balance(self, cch, fch):
assert cch.call_args[0][-1] == 35

def test_payin_fetches_and_uses_existing_holds(self):
self.janet.set_tip_to(self.homer, 20)
team = self.make_team(owner=self.homer, is_approved=True)
self.janet.set_subscription_to(team, '20.00')
hold, error = create_card_hold(self.db, self.janet, D(20))
assert hold is not None
assert not error
Expand All @@ -284,10 +288,10 @@ def test_payin_fetches_and_uses_existing_holds(self):
self.create_card_holds()
assert not cch.called, cch.call_args_list

@pytest.mark.xfail(reason="haven't migrated transfer_takes yet")
@mock.patch.object(Payday, 'fetch_card_holds')
def test_payin_cancels_existing_holds_of_insufficient_amounts(self, fch):
self.janet.set_tip_to(self.homer, 30)
team = self.make_team(owner=self.homer, is_approved=True)
self.janet.set_subscription_to(team, '30.00')
hold, error = create_card_hold(self.db, self.janet, D(10))
assert not error
fch.return_value = {self.janet.id: hold}
Expand Down Expand Up @@ -348,11 +352,11 @@ def test_payin_cant_make_balances_more_negative(self):
with self.assertRaises(NegativeBalance):
payday.update_balances(cursor)

@pytest.mark.xfail(reason="haven't migrated transfer_takes yet")
@mock.patch.object(Payday, 'fetch_card_holds')
@mock.patch('gratipay.billing.exchanges.thing_from_href')
def test_card_hold_error(self, tfh, fch):
self.janet.set_tip_to(self.homer, 17)
team = self.make_team(owner=self.homer, is_approved=True)
self.janet.set_subscription_to(team, '17.00')
tfh.side_effect = Foobar
fch.return_value = {}
Payday.start().payin()
Expand Down