From 529ba0ab50c2e9bba3d3d2babf2c622c07049526 Mon Sep 17 00:00:00 2001 From: Rohit Paul Kuruvilla Date: Sat, 25 Oct 2014 15:08:55 +0530 Subject: [PATCH] update is_funded in participant.py using both coinbase and cc results. --- gratipay/models/participant.py | 5 ++++- tests/py/test_participant.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/gratipay/models/participant.py b/gratipay/models/participant.py index e09ae0f8d4..7adbf3e815 100644 --- a/gratipay/models/participant.py +++ b/gratipay/models/participant.py @@ -463,6 +463,9 @@ def get_teams(self): def accepts_tips(self): return (self.goal is None) or (self.goal >= 0) + @property + def has_funding(self): + return self.last_bill_result == '' or self.last_coinbase_result == '' def insert_into_communities(self, is_member, name, slug): participant_id = self.id @@ -581,7 +584,7 @@ def update_is_closed(self, is_closed, cursor=None): def update_giving(self, cursor=None): # Update is_funded on tips - if self.last_bill_result == '': + if self.has_funding: (cursor or self.db).run(""" UPDATE current_tips SET is_funded = true diff --git a/tests/py/test_participant.py b/tests/py/test_participant.py index ee5c1cc449..136284efaa 100644 --- a/tests/py/test_participant.py +++ b/tests/py/test_participant.py @@ -524,6 +524,26 @@ def test_only_funded_tips_count(self): funded_tips = self.db.all("SELECT amount FROM tips WHERE is_funded ORDER BY id") assert funded_tips == [3, 6, 5] + def test_coinbase_result_changes_is_funded(self): + alice = self.make_participant('alice', claimed_time='now', last_coinbase_result='') + bob = self.make_participant('bob', claimed_time='now', last_coinbase_result=None) + carl = self.make_participant('carl', claimed_time='now', last_coinbase_result="Fail!") + raj = self.make_participant('raj', claimed_time='now', last_coinbase_result="Fail!", last_bill_result='') + dana = self.make_participant('dana', claimed_time='now') + alice.set_tip_to(dana, '1.00') # Funded + bob.set_tip_to(dana, '2.00') # Not Funded + carl.set_tip_to(dana, '3.00') # Not Funded + raj.set_tip_to(dana, '4.00') # Funded by CC + + assert alice.giving == Decimal('1.00') + assert bob.giving == Decimal('0.00') + assert carl.giving == Decimal('0.00') + assert raj.giving == Decimal('4.00') + assert dana.receiving == Decimal('5.00') + + funded_tips = self.db.all("SELECT amount FROM tips WHERE is_funded ORDER BY id") + assert funded_tips == [1, 4] + def test_only_latest_tip_counts(self): alice = self.make_participant('alice', claimed_time='now', last_bill_result='') bob = self.make_participant('bob', claimed_time='now', last_bill_result='')