def test_taking_over_yourself_sets_all_to_zero(self): bob_twitter = StubAccount('twitter', '2') Participant('alice').set_tip_to('bob', '1.00') Participant('alice').take_over(bob_twitter, have_confirmation=True) expected = Decimal('0.00') actual = Participant('alice').get_dollars_giving() assert_equals(actual, expected)
def test_get_tip_distribution_handles_a_tip(self): Participant(u'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(u'bob').get_tip_distribution() assert_equals(actual, expected)
def test_bob_ends_up_tipping_alice_two_dollars(self): carl_twitter = StubAccount('twitter', '3') Participant('bob').set_tip_to('alice', '1.00') Participant('carl').set_tip_to('alice', '1.00') Participant('bob').take_over(carl_twitter, have_confirmation=True) expected = Decimal('2.00') actual = Participant('bob').get_tip_to('alice') assert_equals(actual, expected)
def test_get_tip_distribution_ignores_missing_cc(self): self.make_participant('missing_cc', last_bill_result=None) Participant(u'alice').set_tip_to('bob', '1.00') Participant(u'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(u'bob').get_tip_distribution() assert_equals(actual, expected)
def test_get_tip_distribution_handles_multiple_tips(self): self.make_participant('carl', last_bill_result='') Participant(u'alice').set_tip_to('bob', '1.00') Participant(u'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(u'bob').get_tip_distribution() assert_equals(actual, expected)
def setUp(self): super(Harness, self).setUp() now = utcnow() hour_ago = now - datetime.timedelta(hours=1) for username in ['alice', 'bob', 'carl']: self.make_participant(username, claimed_time=hour_ago, last_bill_result='') deadbeef = TwitterAccount('1', {'screen_name': 'deadbeef'}) self.deadbeef_original_username = deadbeef.participant Participant('carl').set_tip_to('bob', '1.00') Participant('alice').set_tip_to(self.deadbeef_original_username, '1.00') Participant('bob').take_over(deadbeef, have_confirmation=True)
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(username).take_over(twitter_account)
def test_ctime_comes_from_the_older_tip(self): carl_twitter = StubAccount('twitter', '3') Participant('alice').set_tip_to('bob', '1.00') Participant('alice').set_tip_to('carl', '1.00') Participant('bob').take_over(carl_twitter, have_confirmation=True) tips = Tip.query.all() first, second = tips[0], tips[1] # sanity checks (these don't count :) assert len(tips) == 4 assert first.tipper, first.tippee == ('alice', 'bob') assert second.tipper, second.tippee == ('alice', 'carl') expected = first.ctime actual = Tip.query.first().ctime assert_equals(actual, expected)
def test_get_tip_distribution_handles_a_non_standard_amount(self): tip = Tip(tipper='alice', tippee='bob', amount='5.37', ctime=utcnow()) self.session.add(tip) self.session.commit() expected = ([[-1, 1, Decimal('5.37'), 1.0, Decimal('1')]], 1.0, Decimal('5.37')) actual = Participant(u'bob').get_tip_distribution() assert_equals(actual, expected)
def genparticipants(self, ts_start, for_payday): """Generator to yield participants with tips and total. We re-fetch participants each time, because the second time through we want to use the total obligations they have for next week, and if we pass a non-False for_payday to get_tips_and_total then we only get unfulfilled tips from prior to that timestamp, which is none of them by definition. If someone changes tips after payout starts, and we crash during payout, then their new tips_and_total will be used on the re-run. That's okay. """ for deets in self.get_participants(ts_start): participant = Participant(deets["username"]) tips, total = participant.get_tips_and_total(for_payday=for_payday, db=self.db) typecheck(total, Decimal) yield (deets, tips, total)
def genparticipants(self, ts_start, for_payday): """Generator to yield participants with tips and total. We re-fetch participants each time, because the second time through we want to use the total obligations they have for next week, and if we pass a non-False for_payday to get_tips_and_total then we only get unfulfilled tips from prior to that timestamp, which is none of them by definition. If someone changes tips after payout starts, and we crash during payout, then their new tips_and_total will be used on the re-run. That's okay. """ for deets in self.get_participants(ts_start): participant = Participant(deets['username']) tips, total = participant.get_tips_and_total(for_payday=for_payday, db=self.db) typecheck(total, Decimal) yield (deets, tips, total)
def test_payday_doesnt_move_money_to_a_suspicious_account(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=True) carl = self.make_participant('carl', claimed_time=day_ago, balanced_account_uri=self.balanced_account_uri, last_bill_result='', is_suspicious=False) Participant(u'carl').set_tip_to('bob', '6.00') # under $10! self.payday.run() assert_equals(bob.balance, Decimal('0.00')) assert_equals(carl.balance, Decimal('0.00'))
def test_bob_has_two_dollars_in_tips(self): expected = Decimal('2.00') actual = Participant('bob').get_dollars_receiving() assert_equals(actual, expected)
def test_get_tip_distribution_handles_no_tips(self): expected = ([], 0.0, Decimal('0.00')) actual = Participant(u'foo').get_tip_distribution() assert_equals(actual, expected)
def test_there_is_no_more_deadbeef(self): actual = Participant('deadbeef').get_details() assert actual is None, actual
def test_cant_take_over_claimed_participant_without_confirmation(self): bob_twitter = StubAccount('twitter', '2') with assert_raises(NeedConfirmation): Participant('alice').take_over(bob_twitter)
def test_connecting_unknown_account_fails(self): unknown_account = StubAccount('github', 'jim') with assert_raises(AssertionError): Participant('bob').take_over(unknown_account)
def test_participant_can_be_instantiated(self): expected = Participant actual = Participant(None).__class__ assert actual is expected, actual
def test_attempts_to_change_archived_deadbeef_fail(self): participant = Participant(self.deadbeef_original_username) with assert_raises(AssertionError): participant.change_username("zombeef")
def test_attempts_to_change_archived_deadbeef_fail(self): participant = Participant(self.deadbeef_original_username) with assert_raises(AssertionError): participant.change_username('zombeef')
def test_alice_doesnt_give_to_whatever_deadbeef_was_archived_as_either(self): expected = Decimal('0.00') actual = Participant('alice').get_tip_to(self.deadbeef_original_username) assert actual == expected, actual
def test_alice_doesnt_gives_to_deadbeef_anymore(self): expected = Decimal('0.00') actual = Participant('alice').get_tip_to(self.deadbeef_original_username) assert actual == expected, actual
def test_alice_gives_to_bob_now(self): expected = Decimal('1.00') actual = Participant('alice').get_tip_to('bob') assert_equals(actual, expected)