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 committed Oct 25, 2014
1 parent 12afeb6 commit 529ba0a
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 @@ -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
Expand Down Expand Up @@ -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
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 @@ -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='')
Expand Down

0 comments on commit 529ba0a

Please sign in to comment.