Beispiel #1
0
    def test_recalc_debt_outcomers(self):
        e, _, participation = generate_participation(list(range(0, 6)))
        users = list(participation.keys())

        print_list(Transaction.objects.all())

        outcomers = [users[4], users[5]]
        u1_old_balance = users[0].balance()
        u2_old_balance = users[1].balance()

        #########################################
        remove_participants(e, outcomers)
        #########################################

        print_list(Transaction.objects.all())

        # event should be closed
        self.assertEqual(e.rest(), 0)
        self.assertGreater(u1_old_balance, users[0].balance())
        self.assertGreater(u2_old_balance, users[1].balance())

        party_pay =\
            self.eprice / (self.parts[0] + self.parts[1]
                           + self.parts[2] + self.parts[3])
        # get from each participant summary only his party-pay
        self.assertEqual(users[0].balance(),
                         self.ubalance - party_pay * self.parts[0])
        self.assertEqual(users[1].balance(),
                         self.ubalance - party_pay * self.parts[1])
        self.assertEqual(users[2].balance(),
                         self.ubalance - party_pay * self.parts[2])
        self.assertEqual(users[3].balance(),
                         self.ubalance - party_pay * self.parts[3])
Beispiel #2
0
    def test_participation_uniquenest(self):
        e, _, participation = generate_participation([0, 1, 2])
        users = list(participation.keys())

        remove_participants(e, [users[0]])

        self.assertEqual(
            e.participation_set.filter(active=False)[0].account, users[0])

        add_participants(e, {users[0]: 1.0})

        # participation count == users in event count
        self.assertEqual(len(e.participation_set.all()), 3)
Beispiel #3
0
    def test_participation_uniquenest(self):
        e, _, participation = generate_participation([0, 1, 2])
        users = list(participation.keys())

        remove_participants(e, [users[0]])

        self.assertEqual(e.participation_set.filter(active=False)[0].account,
                         users[0])

        add_participants(e, {users[0]: 1.0})

        # participation count == users in event count
        self.assertEqual(len(e.participation_set.all()), 3)
Beispiel #4
0
    def test_remove_unparticipated(self):
        e, _, _ = generate_participation([0, 4, 3])
        users = Account.objects.filter(user__username__iregex=r'^P\d$')

        oldts_count = Transaction.objects.all().count()

        #########################################
        remove_participants(e, [users[1], users[2]])
        #########################################

        print_list(Transaction.objects.all(), this_func_name())

        self.assertEqual(get_participants(e).count(), 3)
        self.assertEqual(get_participants(e)[0]['account'], users[0])
        # Transactions should be not changed
        self.assertEqual(oldts_count, Transaction.objects.all().count())
Beispiel #5
0
    def test_remove_unparticipated(self):
        e, _, _ = generate_participation([0, 4, 3])
        users = Account.objects.filter(user__username__iregex=r'^P\d$')

        oldts_count = Transaction.objects.all().count()

        #########################################
        remove_participants(e, [users[1], users[2]])
        #########################################

        print_list(Transaction.objects.all(), this_func_name())

        self.assertEqual(get_participants(e).count(), 3)
        self.assertEqual(get_participants(e)[0]['account'], users[0])
        # Transactions should be not changed
        self.assertEqual(oldts_count, Transaction.objects.all().count())
Beispiel #6
0
    def test_sway_participants(self):
        e, _, participation = generate_participation([0, 1, 2])
        print_list(Transaction.objects.all(), "ADDED users 0, 1, 2")

        users = list(participation.keys())

        #########################################
        # Check that event in balance
        self.assertEqual(e.rest(), 0)

        #########################################
        remove_participants(e, [users[0], users[1]])
        #########################################
        print_list(Transaction.objects.all(), "REMOVE users 0, 1")
        self.assertEqual(e.rest(), 0)

        #########################################
        add_participants(e, {users[0]: self.parts[0]})
        #########################################
        print_list(Transaction.objects.all(), "RETURNED user 0")
        self.assertEqual(e.rest(), 0)

        #########################################
        add_participants(e, {users[1]: self.parts[1]})
        #########################################
        print_list(Transaction.objects.all(), "RETURNED user 1")
        self.assertEqual(e.rest(), 0)

        #########################################
        remove_participants(e, [users[2]])
        #########################################
        print_list(Transaction.objects.all(), "REMOVE users 2")
        self.assertEqual(e.rest(), 0)
        #########################################

        # unparticipated, not lose money
        self.assertEqual(users[2].balance(), self.ubalance)

        # recalc party_pay, because participants changed
        # users debts only on participation list
        party_pay =\
            self.eprice / (self.parts[0] + self.parts[1])
        self.assertEqual(users[0].balance(),
                         self.ubalance - party_pay * self.parts[0])
        self.assertEqual(users[1].balance(),
                         self.ubalance - party_pay * self.parts[1])
Beispiel #7
0
    def test_sway_participants(self):
        e, _, participation = generate_participation([0, 1, 2])
        print_list(Transaction.objects.all(), "ADDED users 0, 1, 2")

        users = list(participation.keys())

        #########################################
        # Check that event in balance
        self.assertEqual(e.rest(), 0)

        #########################################
        remove_participants(e, [users[0], users[1]])
        #########################################
        print_list(Transaction.objects.all(), "REMOVE users 0, 1")
        self.assertEqual(e.rest(), 0)

        #########################################
        add_participants(e, {users[0]: self.parts[0]})
        #########################################
        print_list(Transaction.objects.all(), "RETURNED user 0")
        self.assertEqual(e.rest(), 0)

        #########################################
        add_participants(e, {users[1]: self.parts[1]})
        #########################################
        print_list(Transaction.objects.all(), "RETURNED user 1")
        self.assertEqual(e.rest(), 0)

        #########################################
        remove_participants(e, [users[2]])
        #########################################
        print_list(Transaction.objects.all(), "REMOVE users 2")
        self.assertEqual(e.rest(), 0)
        #########################################

        # unparticipated, not lose money
        self.assertEqual(users[2].balance(), self.ubalance)

        # recalc party_pay, because participants changed
        # users debts only on participation list
        party_pay =\
            self.eprice / (self.parts[0] + self.parts[1])
        self.assertEqual(users[0].balance(),
                         self.ubalance - party_pay * self.parts[0])
        self.assertEqual(users[1].balance(),
                         self.ubalance - party_pay * self.parts[1])
Beispiel #8
0
    def test_recalc_debt_outcomers(self):
        e, _, participation = generate_participation(list(range(0, 6)))
        users = list(participation.keys())

        print_list(Transaction.objects.all())

        outcomers = [
            users[4],
            users[5]
        ]
        u1_old_balance = users[0].balance()
        u2_old_balance = users[1].balance()

        #########################################
        remove_participants(e, outcomers)
        #########################################

        print_list(Transaction.objects.all())

        # event should be closed
        self.assertEqual(e.rest(), 0)
        self.assertGreater(u1_old_balance, users[0].balance())
        self.assertGreater(u2_old_balance, users[1].balance())

        party_pay =\
            self.eprice / (self.parts[0] + self.parts[1]
                           + self.parts[2] + self.parts[3])
        # get from each participant summary only his party-pay
        self.assertEqual(users[0].balance(),
                         self.ubalance - party_pay * self.parts[0])
        self.assertEqual(users[1].balance(),
                         self.ubalance - party_pay * self.parts[1])
        self.assertEqual(users[2].balance(),
                         self.ubalance - party_pay * self.parts[2])
        self.assertEqual(users[3].balance(),
                         self.ubalance - party_pay * self.parts[3])
Beispiel #9
0
 def delete(self, req, event_pk, pk):
     """ Remove participant from event. """
     e = get_event(event_pk)
     p = get_participation(e, pk)
     remove_participants(e, [p['account']])
     return Response(status=status.HTTP_204_NO_CONTENT)
Beispiel #10
0
 def delete(self, req, event_pk, pk):
     """ Remove participant from event. """
     e = get_event(event_pk)
     p = get_participation(e, pk)
     remove_participants(e, [p["account"]])
     return Response(status=status.HTTP_204_NO_CONTENT)