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 committed Oct 27, 2014
1 parent 529ba0a commit 57d7dc3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
8 changes: 4 additions & 4 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 @@ -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
Expand Down Expand Up @@ -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
Expand Down
46 changes: 45 additions & 1 deletion tests/py/test_billing_payday.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 57d7dc3

Please sign in to comment.