Esempio n. 1
0
    def test_data_formaters_payments2(self):

        mgr = DebtManager()
        alice = Person("Alice")
        bob = Person("Bob")
        carl = Person("Carl")

        outlay = Outlay(datetime(2010, 3, 15, 20, 0, 0), "Restaurant le Grizzli")
        outlay.items.add(Item((alice,), "Starter", 500))
        outlay.items.add(Item((alice,), "Course", 2000))
        outlay.items.add(Item((bob,), "Course", 2500))
        outlay.items.add(Item((bob,), "Wine", 1000))
        outlay.payments.add(Payment((carl,), 6000))
        mgr.transactions.add(outlay)

        outlay = Outlay(datetime(2010, 3, 15, 21, 0, 0), "Cinema")
        outlay.addPersons((alice, bob, carl))
        outlay.payments.add(Payment((bob,), 3000))
        mgr.transactions.add(outlay)

        expected = {
            carl: {
                (datetime(2010, 3, 15, 20, 0, 0), "Restaurant le Grizzli", 6000): set((
                    6000,
                )),
            },

            Person("Bob"): {
                (datetime(2010, 3, 15, 21, 0, 0), "Cinema", 3000): set((3000, )),
            },
        }

        result = mgr.getPaymentsPerPerson()
        self.assertEqual(result, expected)
Esempio n. 2
0
    def test_real_example(self):
        mgr = DebtManager()
        alice = Person("Alice")
        bob = Person("Bob")
        cesar = Person("Cesar")
        daniel = Person("Daniel")
        empu = Person("Empu")

        outlay = Outlay(datetime(2010, 3, 15, 20, 0, 0), "T1")
        mgr.transactions.add(outlay)
        outlay.items.add(Item((alice,), "A", 1500))
        outlay.items.add(Item((bob,), "B", 1700))
        outlay.items.add(Item((cesar,), "C", 1600))
        outlay.items.add(Item((daniel,), "D", 1500))
        outlay.items.add(Item((empu,), "E", 1000))
        outlay.items.add(Item((alice, bob, cesar, daniel), "F", 2000))
        outlay.payments.add(Payment((alice,), 9300))

        outlay = Outlay(datetime(2010, 3, 15, 20, 0, 0), "T2")
        mgr.transactions.add(outlay)
        outlay.addPersons((alice, bob, cesar, daniel, empu))
        outlay.payments.add(Payment((bob,), 7500))

        outlay = Outlay(datetime(2010, 3, 15, 20, 0, 0), "T3")
        mgr.transactions.add(outlay)
        outlay.items.add(Item((alice,), "A", 1000))
        outlay.items.add(Item((bob,), "B", 700))
        outlay.items.add(Item((cesar,), "C", 900))
        outlay.payments.add(Payment((cesar,), 2600))

        outlay = Outlay(datetime(2010, 3, 15, 20, 0, 0), "T4")
        mgr.transactions.add(outlay)
        outlay.items.add(Item((alice,), "A", 700))
        outlay.items.add(Item((bob,), "B", 700))
        outlay.items.add(Item((daniel,), "D", 700))
        outlay.items.add(Item((empu,), "E", 700))
        outlay.payments.add(Payment((daniel,), 2800))

        outlay = Outlay(datetime(2010, 3, 15, 20, 0, 0), "T5")
        mgr.transactions.add(outlay)
        outlay.items.add(Item((alice,), "A", 1800))
        outlay.items.add(Item((bob,), "B", 1500))
        outlay.items.add(Item((cesar,), "C", 2000))
        outlay.items.add(Item((daniel,), "D", 2000))
        outlay.items.add(Item((empu,), "E", 1700))
        outlay.payments.add(Payment((bob,), 5300))
        outlay.payments.add(Payment((empu,), 3700))

        result = mgr.computeDebts()

        expected = (
            (cesar, 3900, bob),
            (daniel, 2300, bob),
            (empu, 1200, alice),
            (daniel, 1100, alice),
        )
        self.assertEqual(result, expected)
Esempio n. 3
0
 def test_rounding_bug_when_item_payment_balance_is_not_null(self):
     mgr = DebtManager()
     alice = Person("Alice")
     bob = Person("Bob")
     outlay = Outlay(datetime(2010, 3, 15, 21, 0, 0), "Cinema")
     mgr.transactions.add(outlay)
     outlay.payments.add(Payment((bob,), 3))
     outlay.addPersons((alice,))
     result = mgr.computeDebts()
     expected = ((alice, 1, bob),)
     self.assertEqual(result, expected)
Esempio n. 4
0
 def test_with_missing_items(self):
     mgr = DebtManager()
     alice = Person("Alice")
     bob = Person("Bob")
     outlay = Outlay(datetime(2010, 3, 15, 21, 0, 0), "Cinema")
     mgr.transactions.add(outlay)
     outlay.payments.add(Payment((bob,), 2000))
     outlay.addPersons((alice,))
     result = mgr.computeDebts()
     expected = ((alice, 1000, bob),)
     self.assertEqual(result, expected)