Esempio n. 1
0
    def test_iter_payday_events(self):
        Payday.start().run()
        team = self.make_participant('team',
                                     number='plural',
                                     claimed_time='now')
        alice = self.make_participant('alice', claimed_time='now')
        self.make_exchange('bill', 10000, 0, team)
        self.make_exchange('bill', 10000, 0, alice)
        self.make_exchange('bill', -5000, 0, alice)
        self.db.run("""
            UPDATE transfers
               SET timestamp = "timestamp" - interval '1 month'
        """)
        bob = self.make_participant('bob', claimed_time='now')
        carl = self.make_participant('carl', claimed_time='now')
        team.add_member(bob)
        team.set_take_for(bob, Decimal('1.00'), team)
        alice.set_tip_to(bob, Decimal('5.00'))

        assert bob.balance == 0
        for i in range(2):
            with patch.object(Payday, 'fetch_card_holds') as fch:
                fch.return_value = {}
                Payday.start().run()
            self.db.run("""
                UPDATE paydays
                   SET ts_start = ts_start - interval '1 week'
                     , ts_end = ts_end - interval '1 week';
                UPDATE transfers
                   SET timestamp = "timestamp" - interval '1 week';
            """)
        bob = Participant.from_id(bob.id)
        assert bob.balance == 12

        Payday().start()
        events = list(iter_payday_events(self.db, bob))
        assert len(events) == 9
        assert events[0]['kind'] == 'totals'
        assert events[0]['given'] == 0
        assert events[0]['received'] == 12
        assert events[1]['kind'] == 'day-open'
        assert events[1]['payday_number'] == 2
        assert events[2]['balance'] == 12
        assert events[-1]['kind'] == 'day-close'
        assert events[-1]['balance'] == '0.00'

        alice = Participant.from_id(alice.id)
        assert alice.balance == 4990
        events = list(iter_payday_events(self.db, alice))
        assert events[0]['given'] == 10
        assert len(events) == 11

        carl = Participant.from_id(carl.id)
        assert carl.balance == 0
        events = list(iter_payday_events(self.db, carl))
        assert len(events) == 0
Esempio n. 2
0
    def test_iter_payday_events(self):
        now = datetime.now()
        Payday().start().run()

        Enterprise = self.make_team(is_approved=True)
        self.obama.set_payment_instruction(Enterprise,
                                           '10.00')  # >= MINIMUM_CHARGE!
        for i in range(2):
            with patch.object(Payday, 'fetch_card_holds') as fch:
                fch.return_value = {}
                Payday.start().run()
            self.db.run("""
                UPDATE paydays
                   SET ts_start = ts_start - interval '1 week'
                     , ts_end = ts_end - interval '1 week';
                UPDATE payments
                   SET timestamp = "timestamp" - interval '1 week';
                UPDATE transfers
                   SET timestamp = "timestamp" - interval '1 week';
            """)

        obama = Participant.from_username('obama')
        picard = Participant.from_username('picard')

        assert obama.balance == D('0.00')
        assert picard.balance == D('20.00')

        Payday().start()  # to demonstrate that we ignore any open payday?

        # Make all events in the same year.
        delta = '%s days' % (364 - (now - datetime(now.year, 1, 1)).days)
        self.db.run(
            """
            UPDATE paydays
                SET ts_start = ts_start + interval %(delta)s
                  , ts_end = ts_end + interval %(delta)s;
            UPDATE payments
                SET timestamp = "timestamp" + interval %(delta)s;
            UPDATE transfers
                SET timestamp = "timestamp" + interval %(delta)s;
        """, dict(delta=delta))

        events = list(iter_payday_events(self.db, picard, now.year))
        assert len(events) == 7
        assert events[0]['kind'] == 'totals'
        assert events[0]['given'] == 0
        assert events[0]['received'] == 20
        assert events[1]['kind'] == 'day-open'
        assert events[1]['payday_number'] == 2
        assert events[2]['balance'] == 20
        assert events[-1]['kind'] == 'day-close'
        assert events[-1]['balance'] == 0

        events = list(iter_payday_events(self.db, obama))
        assert events[0]['given'] == 20
        assert len(events) == 11
Esempio n. 3
0
    def test_iter_payday_events(self):
        now = datetime.now()
        Payday().start().run()

        Enterprise = self.make_team(is_approved=True)
        self.obama.set_payment_instruction(Enterprise, '10.00')  # >= MINIMUM_CHARGE!
        for i in range(2):
            with patch.object(Payday, 'fetch_card_holds') as fch:
                fch.return_value = {}
                Payday.start().run()
            self.db.run("""
                UPDATE paydays
                   SET ts_start = ts_start - interval '1 week'
                     , ts_end = ts_end - interval '1 week';
                UPDATE payments
                   SET timestamp = "timestamp" - interval '1 week';
                UPDATE transfers
                   SET timestamp = "timestamp" - interval '1 week';
            """)


        obama = P('obama')
        picard = P('picard')

        assert obama.balance == D('0.00')
        assert picard.balance == D('20.00')

        Payday().start()  # to demonstrate that we ignore any open payday?

        # Make all events in the same year.
        delta = '%s days' % (364 - (now - datetime(now.year, 1, 1)).days)
        self.db.run("""
            UPDATE paydays
                SET ts_start = ts_start + interval %(delta)s
                  , ts_end = ts_end + interval %(delta)s;
            UPDATE payments
                SET timestamp = "timestamp" + interval %(delta)s;
            UPDATE transfers
                SET timestamp = "timestamp" + interval %(delta)s;
        """, dict(delta=delta))

        events = list(iter_payday_events(self.db, picard, now.year))
        assert len(events) == 7
        assert events[0]['kind'] == 'totals'
        assert events[0]['given'] == 0
        assert events[0]['received'] == 20
        assert events[1]['kind'] == 'day-open'
        assert events[1]['payday_number'] == 2
        assert events[2]['balance'] == 20
        assert events[-1]['kind'] == 'day-close'
        assert events[-1]['balance'] == 0

        events = list(iter_payday_events(self.db, obama))
        assert events[0]['given'] == 20
        assert len(events) == 11
Esempio n. 4
0
    def test_iter_payday_events(self):
        Payday.start().run()
        team = self.make_participant('team', number='plural', claimed_time='now')
        alice = self.make_participant('alice', claimed_time='now')
        self.make_exchange('balanced-cc', 10000, 0, team)
        self.make_exchange('balanced-cc', 10000, 0, alice)
        self.make_exchange('balanced-cc', -5000, 0, alice)
        self.db.run("""
            UPDATE transfers
               SET timestamp = "timestamp" - interval '1 month'
        """)
        bob = self.make_participant('bob', claimed_time='now')
        carl = self.make_participant('carl', claimed_time='now')
        team.add_member(bob)
        team.set_take_for(bob, Decimal('1.00'), team)
        alice.set_tip_to(bob, Decimal('5.00'))

        assert bob.balance == 0
        for i in range(2):
            with patch.object(Payday, 'fetch_card_holds') as fch:
                fch.return_value = {}
                Payday.start().run()
            self.db.run("""
                UPDATE paydays
                   SET ts_start = ts_start - interval '1 week'
                     , ts_end = ts_end - interval '1 week';
                UPDATE transfers
                   SET timestamp = "timestamp" - interval '1 week';
            """)
        bob = Participant.from_id(bob.id)
        assert bob.balance == 12

        Payday().start()
        events = list(iter_payday_events(self.db, bob))
        assert len(events) == 9
        assert events[0]['kind'] == 'totals'
        assert events[0]['given'] == 0
        assert events[0]['received'] == 12
        assert events[1]['kind'] == 'day-open'
        assert events[1]['payday_number'] == 2
        assert events[2]['balance'] == 12
        assert events[-1]['kind'] == 'day-close'
        assert events[-1]['balance'] == 0

        alice = Participant.from_id(alice.id)
        assert alice.balance == 4990
        events = list(iter_payday_events(self.db, alice))
        assert events[0]['given'] == 10
        assert len(events) == 11

        carl = Participant.from_id(carl.id)
        assert carl.balance == 0
        events = list(iter_payday_events(self.db, carl))
        assert len(events) == 0
Esempio n. 5
0
    def test_iter_payday_events(self):
        now = datetime.now()
        self.run_payday()
        self.shift_all_paydays_by('-1 week')

        Enterprise = self.make_team(is_approved=True)
        self.obama.set_payment_instruction(Enterprise,
                                           '10.00')  # >= MINIMUM_CHARGE!
        for i in range(2):
            with patch.object(Payday, 'fetch_card_holds') as fch:
                fch.return_value = {}
                self.run_payday()
            self.shift_all_paydays_by('-1 week')

        obama = P('obama')
        picard = P('picard')

        assert obama.balance == D('0.00')
        assert picard.balance == D('20.00')

        self.start_payday()  # to demonstrate that we ignore any open payday?

        # Make all events in the same year.
        if now.month < 2:

            # Above, we created four paydays in sequential weeks, with the
            # latest being today. We don't want them to go back into the
            # previous year, so let's shift them forward if it's close.

            self.shift_all_paydays_by('3 months')

        events = list(iter_payday_events(self.db, picard, now.year))
        assert len(events) == 7
        assert events[0]['kind'] == 'totals'
        assert events[0]['given'] == 0
        assert events[0]['received'] == 20
        assert events[1]['kind'] == 'day-open'
        assert events[1]['payday_number'] == 2
        assert events[2]['balance'] == 20
        assert events[-1]['kind'] == 'day-close'
        assert events[-1]['balance'] == 0

        events = list(iter_payday_events(self.db, obama))
        assert events[0]['given'] == 20
        assert len(events) == 9
Esempio n. 6
0
    def test_iter_payday_events(self):
        now = datetime.now()
        self.run_payday()
        self.shift_all_paydays_by('-1 week')

        Enterprise = self.make_team(is_approved=True)
        self.obama.set_payment_instruction(Enterprise, '10.00')  # >= MINIMUM_CHARGE!
        for i in range(2):
            with patch.object(Payday, 'fetch_card_holds') as fch:
                fch.return_value = {}
                self.run_payday()
            self.shift_all_paydays_by('-1 week')

        obama = P('obama')
        picard = P('picard')

        assert obama.balance == D('0.00')
        assert picard.balance == D('20.00')

        self.start_payday()  # to demonstrate that we ignore any open payday?

        # Make all events in the same year.
        if now.month < 2:

            # Above, we created four paydays in sequential weeks, with the
            # latest being today. We don't want them to go back into the
            # previous year, so let's shift them forward if it's close.

            self.shift_all_paydays_by('3 months')

        events = list(iter_payday_events(self.db, picard, now.year))
        assert len(events) == 7
        assert events[0]['kind'] == 'totals'
        assert events[0]['given'] == 0
        assert events[0]['received'] == 20
        assert events[1]['kind'] == 'day-open'
        assert events[1]['payday_number'] == 2
        assert events[2]['balance'] == 20
        assert events[-1]['kind'] == 'day-close'
        assert events[-1]['balance'] == 0

        events = list(iter_payday_events(self.db, obama))
        assert events[0]['given'] == 20
        assert len(events) == 9
Esempio n. 7
0
    def test_iter_payday_events(self):
        Payday().start().run()

        Enterprise = self.make_team(is_approved=True)
        self.obama.set_payment_instruction(Enterprise, '10.00')  # >= MINIMUM_CHARGE!
        for i in range(2):
            with patch.object(Payday, 'fetch_card_holds') as fch:
                fch.return_value = {}
                Payday.start().run()
            self.db.run("""
                UPDATE paydays
                   SET ts_start = ts_start - interval '1 week'
                     , ts_end = ts_end - interval '1 week';
                UPDATE payments
                   SET timestamp = "timestamp" - interval '1 week';
                UPDATE transfers
                   SET timestamp = "timestamp" - interval '1 week';
            """)


        obama = Participant.from_username('obama')
        picard = Participant.from_username('picard')

        assert obama.balance == D('0.00')
        assert picard.balance == D('20.00')

        Payday().start()  # to demonstrate that we ignore any open payday?

        events = list(iter_payday_events(self.db, picard))
        assert len(events) == 7
        assert events[0]['kind'] == 'totals'
        assert events[0]['given'] == 0
        assert events[0]['received'] == 20
        assert events[1]['kind'] == 'day-open'
        assert events[1]['payday_number'] == 2
        assert events[2]['balance'] == 20
        assert events[-1]['kind'] == 'day-close'
        assert events[-1]['balance'] == 0

        events = list(iter_payday_events(self.db, obama))
        assert events[0]['given'] == 20
        assert len(events) == 11
Esempio n. 8
0
    def test_iter_payday_events(self):
        Payday().start().run()

        Enterprise = self.make_team(is_approved=True)
        self.obama.set_payment_instruction(Enterprise, '6.00')  # under $10!
        for i in range(2):
            with patch.object(Payday, 'fetch_card_holds') as fch:
                fch.return_value = {}
                Payday.start().run()
            self.db.run("""
                UPDATE paydays
                   SET ts_start = ts_start - interval '1 week'
                     , ts_end = ts_end - interval '1 week';
                UPDATE payments
                   SET timestamp = "timestamp" - interval '1 week';
                UPDATE transfers
                   SET timestamp = "timestamp" - interval '1 week';
            """)

        obama = Participant.from_username('obama')
        picard = Participant.from_username('picard')

        assert obama.balance == D('6.82')
        assert picard.balance == D('12.00')

        Payday().start()  # to demonstrate that we ignore any open payday?

        events = list(iter_payday_events(self.db, picard))
        assert len(events) == 7
        assert events[0]['kind'] == 'totals'
        assert events[0]['given'] == 0
        assert events[0]['received'] == 12
        assert events[1]['kind'] == 'day-open'
        assert events[1]['payday_number'] == 2
        assert events[2]['balance'] == 12
        assert events[-1]['kind'] == 'day-close'
        assert events[-1]['balance'] == 0

        events = list(iter_payday_events(self.db, obama))
        assert events[0]['given'] == 12
        assert len(events) == 11
Esempio n. 9
0
    def test_iter_payday_events(self):
        Payday().start().run()

        A = self.make_team(is_approved=True)
        self.obama.set_subscription_to(A, '6.00')  # under $10!
        for i in range(2):
            with patch.object(Payday, 'fetch_card_holds') as fch:
                fch.return_value = {}
                Payday.start().run()
            self.db.run("""
                UPDATE paydays
                   SET ts_start = ts_start - interval '1 week'
                     , ts_end = ts_end - interval '1 week';
                UPDATE payments
                   SET timestamp = "timestamp" - interval '1 week';
                UPDATE transfers
                   SET timestamp = "timestamp" - interval '1 week';
            """)

        obama = Participant.from_username('obama')
        hannibal = Participant.from_username('hannibal')

        assert obama.balance == D('6.82')
        assert hannibal.balance == D('12.00')

        Payday().start()  # to demonstrate that we ignore any open payday?

        events = list(iter_payday_events(self.db, hannibal))
        assert len(events) == 7
        assert events[0]['kind'] == 'totals'
        assert events[0]['given'] == 0
        assert events[0]['received'] == 12
        assert events[1]['kind'] == 'day-open'
        assert events[1]['payday_number'] == 2
        assert events[2]['balance'] == 12
        assert events[-1]['kind'] == 'day-close'
        assert events[-1]['balance'] == 0

        events = list(iter_payday_events(self.db, obama))
        assert events[0]['given'] == 12
        assert len(events) == 11
Esempio n. 10
0
 def test_iter_payday_events_with_failed_exchanges(self):
     alice = self.make_participant('alice', claimed_time='now')
     self.make_exchange('balanced-cc', 50, 0, alice)
     self.make_exchange('balanced-cc', 12, 0, alice, status='failed')
     self.make_exchange('balanced-ba', -40, 0, alice, status='failed')
     events = list(iter_payday_events(self.db, alice))
     assert len(events) == 5
     assert events[0]['kind'] == 'day-open'
     assert events[0]['balance'] == 50
     assert events[1]['kind'] == 'credit'
     assert events[1]['balance'] == 50
     assert events[2]['kind'] == 'charge'
     assert events[2]['balance'] == 50
     assert events[3]['kind'] == 'charge'
     assert events[3]['balance'] == 50
     assert events[4]['kind'] == 'day-close'
     assert events[4]['balance'] == 0
Esempio n. 11
0
 def test_iter_payday_events_with_failed_exchanges(self):
     alice = self.make_participant('alice', claimed_time='now')
     self.make_exchange('bill', 50, 0, alice)
     self.make_exchange('bill', 12, 0, alice, status='failed')
     self.make_exchange('ach', -40, 0, alice, status='failed')
     events = list(iter_payday_events(self.db, alice))
     assert len(events) == 5
     assert events[0]['kind'] == 'day-open'
     assert events[0]['balance'] == 50
     assert events[1]['kind'] == 'credit'
     assert events[1]['balance'] == 50
     assert events[2]['kind'] == 'charge'
     assert events[2]['balance'] == 50
     assert events[3]['kind'] == 'charge'
     assert events[3]['balance'] == 50
     assert events[4]['kind'] == 'day-close'
     assert events[4]['balance'] == '0.00'