def test_taking_over_yourself_sets_all_to_zero(self): bob_twitter = self.make_elsewhere("twitter", "2", "bob") Participant.from_username("alice").set_tip_to("bob", "1.00") Participant.from_username("alice").take_over(bob_twitter, have_confirmation=True) expected = Decimal("0.00") actual = Participant.from_username("alice").get_dollars_giving() assert actual == expected
def test_get_tip_distribution_handles_a_tip(self): Participant.from_username('alice').set_tip_to('bob', '3.00') expected = ([[Decimal('3.00'), 1, Decimal('3.00'), 1.0, Decimal('1')]], 1.0, Decimal('3.00')) actual = Participant.from_username('bob').get_tip_distribution() assert actual == expected
def setUp(self): super(Harness, self).setUp() now = utcnow() for idx, username in enumerate(['alice', 'bob', 'carl'], start=1): self.make_participant(username, claimed_time=now) twitter_account = TwitterAccount(idx, {'screen_name': username}) Participant.from_username(username).take_over(twitter_account)
def test_cpi_clears_personal_information(self): alice = self.make_participant( 'alice' , statement='not forgetting to be awesome!' , goal=100 , anonymous_giving=True , anonymous_receiving=True , number='plural' , avatar_url='img-url' , email=('*****@*****.**', True) , claimed_time='now' , session_token='deadbeef' , session_expires='2000-01-01' , giving=20 , pledging=30 , receiving=40 ) assert Participant.from_username('alice').number == 'plural' # sanity check with self.db.get_cursor() as cursor: alice.clear_personal_information(cursor) new_alice = Participant.from_username('alice') assert alice.statement == new_alice.statement == '' assert alice.goal == new_alice.goal == None assert (alice.anonymous_giving, new_alice.anonymous_giving) == (False, False) assert (alice.anonymous_receiving, new_alice.anonymous_giving) == (False, False) assert alice.number == new_alice.number == 'singular' assert alice.avatar_url == new_alice.avatar_url == None assert alice.email == new_alice.email == None assert alice.claimed_time == new_alice.claimed_time == None assert alice.giving == new_alice.giving == 0 assert alice.pledging == new_alice.pledging == 0 assert alice.receiving == new_alice.receiving == 0 assert alice.session_token == new_alice.session_token == None assert alice.session_expires.year == new_alice.session_expires.year == date.today().year
def test_taking_over_yourself_sets_all_to_zero(self): bob_twitter = StubAccount('twitter', '2') Participant.from_username('alice').set_tip_to('bob', '1.00') Participant.from_username('alice').take_over(bob_twitter, have_confirmation=True) expected = Decimal('0.00') actual = Participant.from_username('alice').get_dollars_giving() assert actual == expected
def test_get_tip_distribution_ignores_missing_cc(self): self.make_participant("missing_cc", last_bill_result=None) Participant.from_username("alice").set_tip_to("bob", "1.00") Participant.from_username("missing_cc").set_tip_to("bob", "3.00") expected = ([[Decimal("1.00"), 1L, Decimal("1.00"), 1, Decimal("1")]], 1.0, Decimal("1.00")) actual = Participant.from_username("bob").get_tip_distribution() assert actual == expected
def test_uic_uses_supplied_cursor(self): alice = self.make_participant('alice') with self.db.get_cursor() as cursor: alice.update_is_closed(True, cursor) assert alice.is_closed assert not Participant.from_username('alice').is_closed assert Participant.from_username('alice').is_closed
def test_update_receiving_amounts_updates_receiving_amounts(self): A = self.make_participant('A') B = self.make_participant('B', claimed_time='now', last_bill_result='') B.set_tip_to(A, D('10.00'), update_tippee=False) assert Participant.from_username('A').receiving == 0 self.payday.update_receiving_amounts() assert Participant.from_username('A').receiving == 10
def test_update_receiving_amounts_updates_receiving_amounts(self): A = self.make_participant("A") B = self.make_participant("B", claimed_time="now", last_bill_result="") B.set_tip_to(A, D("10.00"), update_tippee=False) assert Participant.from_username("A").receiving == 0 self.payday.update_receiving_amounts() assert Participant.from_username("A").receiving == 10
def test_get_tip_distribution_ignores_missing_cc(self): self.make_participant('missing_cc', last_bill_result=None) Participant.from_username('alice').set_tip_to('bob', '1.00') Participant.from_username('missing_cc').set_tip_to('bob', '3.00') expected = ([[Decimal('1.00'), 1L, Decimal('1.00'), 1, Decimal('1')]], 1.0, Decimal('1.00')) actual = Participant.from_username('bob').get_tip_distribution() assert actual == expected
def test_get_tip_distribution_ignores_bad_cc(self): self.make_participant('bad_cc', last_bill_result='Failure!') Participant.from_username('alice').set_tip_to('bob', '1.00') Participant.from_username('bad_cc').set_tip_to('bob', '3.00') expected = ([[Decimal('1.00'), 1L, Decimal('1.00'), 1, Decimal('1')]], 1.0, Decimal('1.00')) actual = Participant.from_username('bob').get_tip_distribution() assert_equals(actual, expected)
def test_payday_moves_money(self, charge_on_balanced): charge_on_balanced.return_value = (D('10.00'), D('0.68'), "") self.janet.set_tip_to(self.homer, '6.00') # under $10! self.payday.run() janet = Participant.from_username('janet') homer = Participant.from_username('homer') assert homer.balance == D('6.00') assert janet.balance == D('3.32')
def test_get_tip_distribution_handles_multiple_tips(self): self.make_participant('carl', last_bill_result='') Participant.from_username('alice').set_tip_to('bob', '1.00') Participant.from_username('carl').set_tip_to('bob', '3.00') expected = ([ [Decimal('1.00'), 1L, Decimal('1.00'), 0.5, Decimal('0.25')], [Decimal('3.00'), 1L, Decimal('3.00'), 0.5, Decimal('0.75')] ], 2.0, Decimal('4.00')) actual = Participant.from_username('bob').get_tip_distribution() assert actual == expected
def test_payday_moves_money(self, fch): self.janet.set_tip_to(self.homer, '6.00') # under $10! fch.return_value = {} Payday.start().run() janet = Participant.from_username('janet') homer = Participant.from_username('homer') assert homer.balance == D('6.00') assert janet.balance == D('3.41')
def test_can_post_to_close_page(self): alice = self.make_participant('alice', claimed_time='now', balance=7) bob = self.make_participant('bob', claimed_time='now') alice.set_tip_to(bob, D('10.00')) data = {'disbursement_strategy': 'downstream'} response = self.client.PxST('/alice/account/close', auth_as='alice', data=data) assert response.code == 302 assert response.headers['Location'] == '/alice/' assert Participant.from_username('alice').balance == 0 assert Participant.from_username('bob').balance == 7
def test_update_receiving_amounts_includes_taking(self): A = self.make_participant('A', claimed_time='now', taking=3) B = self.make_participant('B', claimed_time='now', last_bill_result='') B.set_tip_to(A, D('10.00'), update_tippee=False) assert Participant.from_username('A').receiving == 0 assert Participant.from_username('A').taking == 3 Payday.start().update_receiving_amounts() assert Participant.from_username('A').receiving == 13 assert Participant.from_username('A').taking == 3
def test_dbafg_favors_highest_tippee_in_rounding_errors(self): alice = self.make_participant('alice', claimed_time='now', balance=D('10.00')) bob = self.make_participant('bob', claimed_time='now') carl = self.make_participant('carl', claimed_time='now') alice.set_tip_to(bob, D('3.00')) alice.set_tip_to(carl, D('6.00')) with self.db.get_cursor() as cursor: alice.distribute_balance_as_final_gift(cursor) assert Participant.from_username('bob').balance == D('3.33') assert Participant.from_username('carl').balance == D('6.67') assert Participant.from_username('alice').balance == D('0.00')
def test_dbafg_distributes_balance_as_final_gift(self): alice = self.make_participant('alice', balance=D('10.00')) bob = self.make_participant('bob', claimed_time='now') carl = self.make_participant('carl', claimed_time='now') alice.set_tip_to(bob, D('3.00')) alice.set_tip_to(carl, D('2.00')) with self.db.get_cursor() as cursor: alice.distribute_balance_as_final_gift(cursor) assert Participant.from_username('bob').balance == D('6.00') assert Participant.from_username('carl').balance == D('4.00') assert Participant.from_username('alice').balance == D('0.00')
def test_dbafg_gives_all_to_claimed(self): alice = self.make_participant('alice', claimed_time='now', balance=D('10.00')) bob = self.make_participant('bob', claimed_time='now') carl = self.make_participant('carl') alice.set_tip_to(bob, D('3.00')) alice.set_tip_to(carl, D('2.00')) with self.db.get_cursor() as cursor: alice.distribute_balance_as_final_gift(cursor) assert Participant.from_username('bob').balance == D('10.00') assert Participant.from_username('carl').balance == D('0.00') assert Participant.from_username('alice').balance == D('0.00')
def test_dbafg_needs_claimed_tips(self): alice = self.make_participant('alice', balance=D('10.00')) bob = self.make_participant('bob') carl = self.make_participant('carl') alice.set_tip_to(bob, D('3.00')) alice.set_tip_to(carl, D('2.00')) with self.db.get_cursor() as cursor: with pytest.raises(alice.NoOneToGiveFinalGiftTo): alice.distribute_balance_as_final_gift(cursor) assert Participant.from_username('bob').balance == D('0.00') assert Participant.from_username('carl').balance == D('0.00') assert Participant.from_username('alice').balance == D('10.00')
def test_pachinko_pachinkos(self): a_team = self.make_participant("a_team", claimed_time="now", number="plural", balance=20, pending=0) a_team.add_member(self.make_participant("alice", claimed_time="now", balance=0, pending=0)) a_team.add_member(self.make_participant("bob", claimed_time="now", balance=0, pending=0)) ts_start = self.payday.start() participants = self.payday.genparticipants(ts_start, LOOP_PACHINKO) self.payday.pachinko(ts_start, participants) assert Participant.from_username("alice").pending == D("0.01") assert Participant.from_username("bob").pending == D("0.01")
def test_dbafg_with_zero_balance_is_a_noop(self): alice = self.make_participant('alice', balance=D('0.00')) bob = self.make_participant('bob', claimed_time='now') carl = self.make_participant('carl', claimed_time='now') alice.set_tip_to(bob, D('3.00')) alice.set_tip_to(carl, D('6.00')) with self.db.get_cursor() as cursor: alice.distribute_balance_as_final_gift(cursor) assert self.db.one("SELECT count(*) FROM tips") == 2 assert Participant.from_username('bob').balance == D('0.00') assert Participant.from_username('carl').balance == D('0.00') assert Participant.from_username('alice').balance == D('0.00')
def test_dbafg_needs_claimed_tips(self): alice = self.make_participant('alice', claimed_time='now', balance=D('10.00')) bob = self.make_participant('bob') carl = self.make_participant('carl') alice.set_tip_to(bob, D('3.00')) alice.set_tip_to(carl, D('2.00')) with self.db.get_cursor() as cursor: with pytest.raises(alice.NoOneToGiveFinalGiftTo): alice.distribute_balance_as_final_gift(cursor) assert Participant.from_username('bob').balance == D('0.00') assert Participant.from_username('carl').balance == D('0.00') assert Participant.from_username('alice').balance == D('10.00')
def test_dbafg_with_zero_balance_is_a_noop(self): alice = self.make_participant('alice', claimed_time='now', balance=D('0.00')) bob = self.make_participant('bob', claimed_time='now') carl = self.make_participant('carl', claimed_time='now') alice.set_tip_to(bob, D('3.00')) alice.set_tip_to(carl, D('6.00')) with self.db.get_cursor() as cursor: alice.distribute_balance_as_final_gift(cursor) assert self.db.one("SELECT count(*) FROM tips") == 2 assert Participant.from_username('bob').balance == D('0.00') assert Participant.from_username('carl').balance == D('0.00') assert Participant.from_username('alice').balance == D('0.00')
def test_pachinko_pachinkos(self): a_team = self.make_participant('a_team', claimed_time='now', number='plural', balance=20, \ pending=0) a_team.add_member(self.make_participant('alice', claimed_time='now', balance=0, pending=0)) a_team.add_member(self.make_participant('bob', claimed_time='now', balance=0, pending=0)) ts_start = self.payday.start() participants = self.payday.genparticipants(ts_start, LOOP_PACHINKO) self.payday.pachinko(ts_start, participants) assert Participant.from_username('alice').pending == D('0.01') assert Participant.from_username('bob').pending == D('0.01')
def test_get_tip_distribution_handles_multiple_tips(self): self.make_participant('carl', last_bill_result='') Participant.from_username('alice').set_tip_to('bob', '1.00') Participant.from_username('carl').set_tip_to('bob', '3.00') expected = ([[ Decimal('1.00'), 1L, Decimal('1.00'), 0.5, Decimal('0.25') ], [Decimal('3.00'), 1L, Decimal('3.00'), 0.5, Decimal('0.75')]], 2.0, Decimal('4.00')) actual = Participant.from_username('bob').get_tip_distribution() assert actual == expected
def test_get_tip_distribution_handles_multiple_tips(self): self.make_participant("carl", last_bill_result="") Participant.from_username("alice").set_tip_to("bob", "1.00") Participant.from_username("carl").set_tip_to("bob", "3.00") expected = ( [ [Decimal("1.00"), 1L, Decimal("1.00"), 0.5, Decimal("0.25")], [Decimal("3.00"), 1L, Decimal("3.00"), 0.5, Decimal("0.75")], ], 2.0, Decimal("4.00"), ) actual = Participant.from_username("bob").get_tip_distribution() assert actual == expected
def test_payday_doesnt_move_money_to_a_suspicious_account(self, fch): self.db.run(""" UPDATE participants SET is_suspicious = true WHERE username = '******' """) self.janet.set_tip_to(self.homer, '6.00') # under $10! fch.return_value = {} Payday.start().run() janet = Participant.from_username('janet') homer = Participant.from_username('homer') assert janet.balance == D('0.00') assert homer.balance == D('0.00')
def test_payday_doesnt_move_money_to_a_suspicious_account(self, charge_on_balanced): charge_on_balanced.return_value = (D('10.00'), D('0.68'), "") self.db.run(""" UPDATE participants SET is_suspicious = true WHERE username = '******' """) self.janet.set_tip_to(self.homer, '6.00') # under $10! self.payday.run() janet = Participant.from_username('janet') homer = Participant.from_username('homer') assert janet.balance == D('0.00') assert homer.balance == D('0.00')
def test_record_credit_doesnt_update_balance_if_error(self): self.payday.record_credit(amount=Decimal("-1.00"), fee=Decimal("0.41"), error="SOME ERROR", username="******") alice = Participant.from_username('alice') assert_equals(alice.balance, Decimal("0.00"))
def make_team(self, username=TEAM, **kw): team = self.make_participant(username, number='plural', **kw) if Participant.from_username('Daddy Warbucks') is None: warbucks = self.make_participant('Daddy Warbucks', last_bill_result='') self.warbucks = warbucks self.warbucks.set_tip_to(team, '100') return team
def test_uic_updates_is_closed_False(self): alice = self.make_participant('alice') alice.update_is_closed(True) alice.update_is_closed(False) assert not alice.is_closed assert not Participant.from_username('alice').is_closed
def test_session_cookie_set_in_auth_response(self): self.make_participant("alice") # Make a normal authenticated request. normal = self.client.GET("/", auth_as="alice", HTTP_X_FORWARDED_PROTO="https", HTTP_HOST="www.gittip.com") alice = Participant.from_username("alice") assert normal.headers.cookie["session"].value == alice.session_token
def fake_participant(db, number="singular", is_admin=False, anonymous=False): """Create a fake User. """ username = faker.firstName() + fake_text_id(3) d = _fake_thing( db, "participants", id=fake_int_id(), username=username, username_lower=username.lower(), statement=fake_sentence(), ctime=faker.dateTimeThisYear(), is_admin=is_admin, balance=fake_balance(), anonymous=anonymous, goal=fake_balance(), balanced_account_uri=faker.uri(), last_ach_result='', is_suspicious=False, last_bill_result='' # Needed to not be suspicious , claimed_time=faker.dateTimeThisYear(), number=number) #Call participant constructor to perform other DB initialization return Participant.from_username(username)
def test_changes_to_others_take_can_increase_members_take(self): team = self.make_team() alice = self.make_participant('alice', take_last_week='30.00', claimed_time='now') team.add_member(alice) team.set_take_for(alice, D('42.00'), alice) bob = self.make_participant('bob', take_last_week='60.00', claimed_time='now') team.add_member(bob) team.set_take_for(bob, D('80.00'), bob) alice = Participant.from_username('alice') assert alice.receiving == alice.taking == 20 team.set_take_for(bob, D('30.00'), bob) alice = Participant.from_username('alice') assert alice.receiving == alice.taking == 42
def test_record_credit_updates_balance(self): self.payday.record_credit(amount=D("-1.00"), fee=D("0.41"), error="", username="******") alice = Participant.from_username('alice') assert alice.balance == D("0.59")
def fake_participant(db, number="singular", is_admin=False): """Create a fake User. """ username = faker.first_name() + fake_text_id(3) _fake_thing( db, "participants", id=fake_int_id(), username=username, username_lower=username.lower(), statement=fake_sentence(), ctime=faker.date_time_this_year(), is_admin=is_admin, balance=fake_balance(), anonymous_giving=(random.randrange(5) == 0), anonymous_receiving=(random.randrange(5) == 0), goal=fake_balance(), balanced_customer_href=faker.uri(), last_ach_result='', is_suspicious=False, last_bill_result='' # Needed to not be suspicious , claimed_time=faker.date_time_this_year(), number=number) #Call participant constructor to perform other DB initialization return Participant.from_username(username)
def fake_participant(db, number="singular", is_admin=False): """Create a fake User. """ username = faker.first_name() + fake_text_id(3) d = _fake_thing( db , "participants" , id=fake_int_id() , username=username , username_lower=username.lower() , statement=fake_sentence() , ctime=faker.date_time_this_year() , is_admin=is_admin , balance=fake_balance() , anonymous_giving=(random.randrange(5) == 0) , anonymous_receiving=(random.randrange(5) == 0) , goal=fake_balance() , balanced_account_uri=faker.uri() , last_ach_result='' , is_suspicious=False , last_bill_result='' # Needed to not be suspicious , claimed_time=faker.date_time_this_year() , number=number ) #Call participant constructor to perform other DB initialization return Participant.from_username(username)
def sync_with_balanced(db): """We can get out of sync with Balanced if record_exchange_result was interrupted or wasn't called. This is where we fix that. """ check_db(db) exchanges = db.all(""" SELECT * FROM exchanges WHERE status = 'pre' """) meta_exchange_id = balanced.Transaction.f.meta.exchange_id for e in exchanges: p = Participant.from_username(e.participant) cls = balanced.Debit if e.amount > 0 else balanced.Credit transactions = cls.query.filter(meta_exchange_id == e.id).all() assert len(transactions) < 2 if transactions: t = transactions[0] error = t.failure_reason status = t.status assert (not error) ^ (status == 'failed') record_exchange_result(db, e.id, status, error, p) else: # The exchange didn't happen, remove it db.run("DELETE FROM exchanges WHERE id=%s", (e.id,)) # and restore the participant's balance if it was a credit if e.amount < 0: db.run(""" UPDATE participants SET balance=(balance + %s) WHERE id=%s """, (-e.amount + e.fee, p.id)) check_db(db)
def test_delete_elsewhere_nonsignin(self): g = self.make_elsewhere('bountysource', 1, 'alice') alice = Participant.from_username('alice') alice.take_over(g) accounts = alice.get_accounts_elsewhere() assert accounts['twitter'] and accounts['bountysource'] alice.delete_elsewhere('bountysource', 1) accounts = alice.get_accounts_elsewhere() assert accounts['twitter'] and accounts.get('bountysource') is None
def test_bob_ends_up_tipping_alice_two_dollars(self): carl_twitter = StubAccount('twitter', '3') Participant.from_username('bob').set_tip_to('alice', '1.00') Participant.from_username('carl').set_tip_to('alice', '1.00') Participant.from_username('bob').take_over(carl_twitter, have_confirmation=True) expected = Decimal('2.00') actual = Participant.from_username('bob').get_tip_to('alice') assert actual == expected
def test_session_cookie_set_in_auth_response(self): self.make_participant('alice') # Make a normal authenticated request. normal = self.client.GET("/", auth_as='alice', HTTP_X_FORWARDED_PROTO='https', HTTP_HOST='www.gittip.com') alice = Participant.from_username('alice') assert normal.headers.cookie['session'].value == alice.session_token
def test_associate_bank_account_invalid(self, find): ex = balanced.exc.HTTPError('errrrrror') find.return_value.add_bank_account.side_effect = ex find.return_value.uri = self.balanced_account_uri billing.associate(u"bank account", 'alice', self.balanced_account_uri, self.balanced_destination_uri) # participant in db should be updated alice = Participant.from_username('alice') assert alice.last_ach_result == 'errrrrror'
def test_delete_elsewhere(self): g = self.make_elsewhere('github', 1, 'alice') alice = Participant.from_username('alice') alice.take_over(g) # test preconditions accounts = alice.get_accounts_elsewhere() assert accounts['twitter'] and accounts['github'] # do the thing alice.delete_elsewhere('twitter', 1) # unit test accounts = alice.get_accounts_elsewhere() assert accounts.get('twitter') is None and accounts['github']
def test_pachinko_pachinkos(self): a_team = self.make_participant('a_team', claimed_time='now', number='plural', balance=20, \ pending=0) a_team.add_member( self.make_participant('alice', claimed_time='now', balance=0, pending=0)) a_team.add_member( self.make_participant('bob', claimed_time='now', balance=0, pending=0)) ts_start = self.payday.start() participants = self.payday.genparticipants(ts_start, LOOP_PACHINKO) self.payday.pachinko(ts_start, participants) assert Participant.from_username('alice').pending == D('0.01') assert Participant.from_username('bob').pending == D('0.01')
def test_payday_moves_money(self, charge_on_balanced): charge_on_balanced.return_value = (D('10.00'), D('0.68'), "") day_ago = utcnow() - timedelta(days=1) bob = self.make_participant('bob', claimed_time=day_ago, last_bill_result='', is_suspicious=False) carl = self.make_participant( 'carl', claimed_time=day_ago, balanced_customer_href=self.balanced_customer_href, last_bill_result='', is_suspicious=False) carl.set_tip_to(bob, '6.00') # under $10! self.payday.run() bob = Participant.from_username('bob') carl = Participant.from_username('carl') assert bob.balance == D('6.00') assert carl.balance == D('3.32')
def test_payday_moves_money_with_balanced(self): day_ago = utcnow() - timedelta(days=1) paying_customer = balanced.Customer().save() balanced.Card.fetch(self.card_href)\ .associate_to_customer(paying_customer) balanced.BankAccount.fetch(self.bank_account_href)\ .associate_to_customer(self.balanced_customer_href) bob = self.make_participant( 'bob', claimed_time=day_ago, balanced_customer_href=self.balanced_customer_href, last_bill_result='', is_suspicious=False) carl = self.make_participant( 'carl', claimed_time=day_ago, balanced_customer_href=paying_customer.href, last_bill_result='', is_suspicious=False) carl.set_tip_to(bob, '15.00') self.payday.run() bob = Participant.from_username('bob') carl = Participant.from_username('carl') assert bob.balance == D('0.00') assert carl.balance == D('0.00') bob_customer = balanced.Customer.fetch(bob.balanced_customer_href) carl_customer = balanced.Customer.fetch(carl.balanced_customer_href) bob_credits = bob_customer.credits.all() assert len(bob_credits) == 1 assert bob_credits[0].amount == 1500 assert bob_credits[0].description == 'bob' carl_debits = carl_customer.debits.all() assert len(carl_debits) == 1 assert carl_debits[0].amount == 1576 # base amount + fee assert carl_debits[0].description == 'carl'
def test_payday_moves_money(self, charge_on_balanced): charge_on_balanced.return_value = (Decimal('10.00'), Decimal('0.68'), "") day_ago = utcnow() - timedelta(days=1) bob = self.make_participant('bob', claimed_time=day_ago, last_bill_result='', is_suspicious=False) carl = self.make_participant( 'carl', claimed_time=day_ago, balanced_account_uri=self.balanced_account_uri, last_bill_result='', is_suspicious=False) carl.set_tip_to('bob', '6.00') # under $10! self.payday.run() bob = Participant.from_username('bob') carl = Participant.from_username('carl') assert_equals(bob.balance, Decimal('6.00')) assert_equals(carl.balance, Decimal('3.32'))
def test_associate_bank_account_invalid(self): billing.associate( self.db, u"bank account", 'alice', self.balanced_customer_href, '/bank_accounts/BA123123123123123123' # invalid href ) # participant in db should be updated alice = Participant.from_username('alice') assert alice.last_ach_result == '404 Client Error: NOT FOUND'
def test_pachinko_sees_current_take(self): a_team = self.make_participant('a_team', claimed_time='now', number='plural', balance=20, \ pending=0) alice = self.make_participant('alice', claimed_time='now', balance=0, pending=0) a_team.add_member(alice) a_team.set_take_for(alice, D('1.00'), alice) ts_start = self.payday.start() participants = self.payday.genparticipants(ts_start, LOOP_PACHINKO) self.payday.pachinko(ts_start, participants) assert Participant.from_username('alice').pending == D('1.00')
def test_charge_success_updates_participant(self, cob): cob.return_value = (Decimal('10.00'), Decimal('0.68'), "") bob = self.make_participant( 'bob', last_bill_result="failure", balanced_account_uri=self.balanced_account_uri, is_suspicious=False) self.payday.start() self.payday.charge(bob, Decimal('1.00')) bob = Participant.from_username('bob') expected = {'balance': Decimal('9.32'), 'last_bill_result': ''} actual = { 'balance': bob.balance, 'last_bill_result': bob.last_bill_result } assert_equals(actual, expected)
def test_credit_participant(self): amount = Decimal('1.00') subject = self.make_participant('test_credit_participant', pending=0, balance=1) initial_amount = subject.pending with self.db.get_cursor() as cursor: self.payday.credit_participant(cursor, subject.username, amount) subject = Participant.from_username( 'test_credit_participant') # reload expected = initial_amount + amount actual = subject.pending assert_equals(actual, expected)
def test_pachinko_ignores_take_thats_already_been_processed(self): a_team = self.make_participant('a_team', claimed_time='now', number='plural', balance=20, \ pending=0) alice = self.make_participant('alice', claimed_time='now', balance=0, pending=0) a_team.add_member(alice) a_team.set_take_for(alice, D('0.33'), alice) ts_start = self.payday.start() a_team.set_take_for(alice, D('1.00'), alice) for i in range(4): participants = self.payday.genparticipants(ts_start, LOOP_PACHINKO) self.payday.pachinko(ts_start, participants) assert Participant.from_username('alice').pending == D('0.33')