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

Commit

Permalink
Increase surface area of process_remainder test
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitpaulk committed Aug 31, 2016
1 parent 53a28f2 commit 174e8fc
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions tests/py/test_billing_payday.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,26 +423,38 @@ def test_process_payment_instructions(self):
assert payment.direction == 'to-team'

def test_process_remainder(self):
alice = self.make_participant('alice', claimed_time='now', balance=1)
picard = self.make_participant('picard', claimed_time='now', last_paypal_result='')
Enterprise = self.make_team('The Enterprise', picard, is_approved=True)
alice.set_payment_instruction(Enterprise, D('0.51'))
alice = self.make_participant('alice', claimed_time='now', balance=100)
picard = self.make_participant('picard', claimed_time='now', last_paypal_result='', verified_in='TT', email_address='[email protected]')
crusher = self.make_participant('crusher', claimed_time='now', verified_in='TT', email_address='[email protected]')

Enterprise = self.make_team('The Enterprise', picard, is_approved=True, available=100)
Enterprise.add_member(crusher, picard)
Enterprise.set_take_for(crusher, 10, crusher)
alice.set_payment_instruction(Enterprise, D('80'))

payday = Payday.start()
with self.db.get_cursor() as cursor:
payday.prepare(cursor)
payday.process_payment_instructions(cursor)
payday.process_takes(cursor, payday.ts_start)
payday.process_remainder(cursor)
assert cursor.one("select new_balance from payday_participants "
"where username='picard'") == D('0.51')
"where username='picard'") == D('70')
assert cursor.one("select balance from payday_teams where slug='TheEnterprise'") == 0
payday.update_balances(cursor)

assert P('alice').balance == D('0.49') # Alice had $1 and gave away $0.51
assert P('picard').balance == D('0.51')
assert P('alice').balance == D('20') # Alice had $100 and gave away $80
assert P('crusher').balance == D('10') # Crusher had set their take to $10
assert P('picard').balance == D('70') # Picard is the owner of the team, recieves what is leftover

payment = self.db.one("SELECT * FROM payments WHERE direction='to-participant'")
assert payment.amount == D('0.51')
payment_to_team = self.db.one("SELECT amount FROM payments WHERE direction='to-team'")
assert payment_to_team == D('80')

payments_to_participant = self.db.all("SELECT participant, amount FROM payments WHERE direction='to-participant' ORDER BY amount DESC")
assert payments_to_participant[0].participant == 'picard'
assert payments_to_participant[0].amount == D('70')
assert payments_to_participant[1].participant == 'crusher'
assert payments_to_participant[1].amount == D('10')

@pytest.mark.xfail(reason="team owners can't be taken over because of #3602")
def test_take_over_during_payin(self):
Expand Down Expand Up @@ -609,19 +621,6 @@ def test_pt_is_NOT_happy_to_deal_the_owner_in(self):
assert P('bruiser').balance == D('250.00')
assert P('picard').balance == D(' 50.00')

def test_process_remainder_only_processes_pt_leftovers(self):
self.make_member('alice', 100)
self.start_payday()
with self.db.get_cursor() as cursor:
self.payday.prepare(cursor)
cursor.run("UPDATE payday_teams SET balance=500")
self.payday.process_takes(cursor, self.payday.ts_start)
self.payday.process_remainder(cursor)
self.payday.update_balances(cursor)

assert P('alice').balance == D('100')
assert P('picard').balance == D('400') # Owner receives whatever is left


class TestNotifyParticipants(EmailHarness):

Expand Down

0 comments on commit 174e8fc

Please sign in to comment.