From 57d7dc3c7ab204e5b06a25f838d666bbc8d5b67b Mon Sep 17 00:00:00 2001 From: Rohit Paul Kuruvilla Date: Mon, 27 Oct 2014 23:31:20 +0530 Subject: [PATCH] added check for last_coinbase_result in fake_payday.sql --- fake_payday.sql | 8 +++--- tests/py/test_billing_payday.py | 46 ++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/fake_payday.sql b/fake_payday.sql index a2b90b9237..33a4aafd0d 100644 --- a/fake_payday.sql +++ b/fake_payday.sql @@ -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; @@ -54,7 +54,7 @@ CREATE OR REPLACE FUNCTION fake_tip() RETURNS trigger AS $$ WHERE participant = NEW.tippee LIMIT 1 ); - 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 @@ -118,12 +118,12 @@ CREATE TRIGGER fake_take AFTER INSERT ON temp_takes -- Start fake payday --- Step 1: tips that are backed by a credit card +-- Step 1: tips that are backed by a credit card or coinbase 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; -- Step 2: tips that are covered by the user's balance UPDATE temp_tips t diff --git a/tests/py/test_billing_payday.py b/tests/py/test_billing_payday.py index e10ba738fa..df90890946 100644 --- a/tests/py/test_billing_payday.py +++ b/tests/py/test_billing_payday.py @@ -119,7 +119,7 @@ def check(): bob = Participant.from_username('bob') carl = Participant.from_username('carl') dana = Participant.from_username('dana') - emma = AccountElsewhere.from_user_name('github','emma').participant + emma = AccountElsewhere.from_user_name('github', 'emma').participant assert alice.giving == D('13.00') assert alice.pledging == D('1.00') assert alice.receiving == D('5.00') @@ -155,6 +155,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()