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

Commit

Permalink
added check for last_coinbase_result in fake_payday.sql
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitpaulk authored and Changaco committed Jan 3, 2015
1 parent ac99f0a commit 9a01298
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
6 changes: 3 additions & 3 deletions fake_payday.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CREATE TEMPORARY TABLE temp_participants ON COMMIT DROP AS
, 0::numeric(35,2) AS receiving
, 0 as npatrons
, goal
, COALESCE(last_bill_result = '', false) AS credit_card_ok
, COALESCE(last_bill_result = '' OR last_coinbase_result = '', false) AS has_funding
FROM participants
WHERE is_suspicious IS NOT true;

Expand Down Expand Up @@ -47,7 +47,7 @@ CREATE OR REPLACE FUNCTION fake_tip() RETURNS trigger AS $$
FROM temp_participants p
WHERE username = NEW.tipper
);
IF (NEW.amount > tipper.fake_balance AND NOT tipper.credit_card_ok) THEN
IF (NEW.amount > tipper.fake_balance AND NOT tipper.has_funding) THEN
RETURN NULL;
END IF;
IF (NEW.claimed) THEN
Expand Down Expand Up @@ -143,7 +143,7 @@ UPDATE temp_tips t
SET is_funded = true
FROM temp_participants p
WHERE p.username = t.tipper
AND p.credit_card_ok;
AND p.has_funding;

SELECT settle_tip_graph();

Expand Down
44 changes: 44 additions & 0 deletions tests/py/test_billing_payday.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,50 @@ def check():
Payday.start().update_cached_amounts()
check()

def test_update_cached_amounts_considers_coinbase(self):
alice = self.make_participant('alice', claimed_time='now', last_bill_result='')
bob = self.make_participant('bob', claimed_time='now', last_bill_result=None,
last_coinbase_result='')
carl = self.make_participant('carl', claimed_time='now', last_bill_result="Fail!",
last_coinbase_result='Fail!')
dana = self.make_participant('dana', claimed_time='now')
alice.set_tip_to(dana, '1.00')
bob.set_tip_to(dana, '2.00')
carl.set_tip_to(dana, '3.00')

def check():
alice = Participant.from_username('alice')
bob = Participant.from_username('bob')
carl = Participant.from_username('carl')
dana = Participant.from_username('dana')
assert alice.giving == D('1.00')
assert bob.giving == D('2.00')
assert carl.giving == D('0.00')
assert dana.receiving == D('3.00')
assert dana.npatrons == 2
funded_tips = self.db.all("SELECT amount FROM tips WHERE is_funded ORDER BY id")
assert funded_tips == [1, 2]

# Pre-test check
check()

# Check that update_cached_amounts doesn't mess anything up
Payday.start().update_cached_amounts()
check()

# Check that update_cached_amounts actually updates amounts
self.db.run("""
UPDATE tips SET is_funded = false;
UPDATE participants
SET giving = 0
, npatrons = 0
, pledging = 0
, receiving = 0
, taking = 0;
""")
Payday.start().update_cached_amounts()
check()

@mock.patch('gratipay.billing.payday.log')
def test_start_prepare(self, log):
self.clear_tables()
Expand Down

0 comments on commit 9a01298

Please sign in to comment.