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

Commit

Permalink
update is_funded in participant.py using both coinbase and cc results.
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitpaulk authored and Changaco committed Jan 3, 2015
1 parent c291996 commit ac99f0a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion gratipay/models/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,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
Expand Down Expand Up @@ -785,7 +788,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
Expand Down
20 changes: 20 additions & 0 deletions tests/py/test_participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,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='')
Expand Down

0 comments on commit ac99f0a

Please sign in to comment.