Esempio n. 1
0
 def test_total_two_entries(self):
     """Test the total method with one entries."""
     group = Group("Test Group", [
         Entry("Entry 1", 100),
         Entry("Entry 2", "23.5"),
     ])
     self.assertEqual(group.total(), Money("123.5", "EUR"))
Esempio n. 2
0
    def test_total_complex_group_currencies(self):
        """
        Tests the total function with some more complex (sub)-groups and
        multiple currencies.
        """
        rates = Rates()
        rates.add_currency("USD", 2)
        rates.add_currency("CHF", 0.5)

        group = Group("Test Group", [
            Entry("Entry 1", 100),
            Group("Sub Group", [
                Entry("Sub Entry", 100),
                Group(
                    "Sub-Sub Group",
                    [
                        Entry("Sub-Sub Entry 1", 100, currency="CHF"),
                        Entry("Sub-Sub Entry 2", 200, currency="USD"),
                    ],
                    currency="CHF",
                )
            ]),
            Entry("Sub-Sub Entry 2", 100, currency="CHF"),
        ])
        self.assertEqual(group.total(), Money(700, "EUR"))
Esempio n. 3
0
 def set_currency(cls, currency: str):
     """
     Alter the currency for all following budget elements (defaults to EUR).
     Currencies are expressed in a three lettered code as stated in the
     ISO 4217 standard.
     """
     Group._set_currency(currency)
     Entry._set_currency(currency)
     Rates._set_currency(currency)
Esempio n. 4
0
 def test_complex_sum(self):
     """Some more currencies."""
     rates = Rates()
     rates.add_currency("USD", 2)
     rates.add_currency("CHF", 0.5)
     group = Group("Set Design", [
         Entry("Expense 1", 100),
         Entry("Expense 2", 200, currency="USD"),
         Entry("Expense 3", 100, currency="CHF"),
     ])
     self.assertEqual(group.total(), Money(400, "EUR"))
Esempio n. 5
0
 def test_failure_on_no_rates(self):
     """
     Tests if a exception is thrown when multiple currencies are used by no
     Rates object was instantiated.
     """
     group = Group("Test Group", [
         Entry("Entry 1", 100),
         Entry("Entry 2", "23.5"),
     ])
     self.assertEqual(group.total(), Money("123.5", "USD"))
     self.assertNotEqual(group.total(), Money("123.5", "EUR"))
     self.assertNotEqual(group.total(), Money(100, "USD"))
Esempio n. 6
0
 def test_simple_sum(self):
     """
     Tests the total of a group consisting of two entries with different
     currencies.
     """
     rates = Rates()
     rates.add_currency("USD", 2)
     group = Group("Set Design", [
         Entry("Expense 1", 100),
         Entry("Expense 2", 200, currency="USD"),
     ])
     self.assertEqual(group.total(), Money(200, "EUR"))
Esempio n. 7
0
    def test_total_two_entries_usd(self):
        """Test the total method while having one entry in USD."""
        rates = Rates()
        rates.add_currency("USD", 2)

        group = Group("Test Group", [
            Entry("Entry 1", 100),
            Entry("Entry 2", 200, currency="USD"),
        ])
        rsl = group.total()
        self.assertEqual(rsl, Money(200, "EUR"))
        self.assertNotEqual(group.total(), Money(300, "EUR"))
        self.assertNotEqual(group.total(), Money(200, "USD"))
        self.assertNotEqual(group.total(), Money(300, "USD"))
Esempio n. 8
0
 def test_total_complex_group(self):
     """
     Tests the total function with some more complex (sub)-groups.
     """
     group = Group("Test Group", [
         Entry("Entry 1", 100),
         Group("Sub Group", [
             Entry("Sub Entry", 100),
             Group("Sub-Sub Group", [
                 Entry("Sub-Sub Entry 1", 100),
                 Entry("Sub-Sub Entry 2", 300),
             ])
         ]),
         Entry("Entry 2", 50),
     ])
     self.assertEqual(group.total(), Money(650, "EUR"))
Esempio n. 9
0
 def _from_entry(cls, entry: Entry) -> "Group":
     """
     Generates a Group from a single Entry. Used for rendering Groups
     containing sub-Groups and single items at the same time.
     """
     code = entry.code
     entry.code = ""
     return cls(
         entry.name,
         [entry],
         code=code,
         comment="",
         currency=entry.currency,
     )
Esempio n. 10
0
 def test_total_with_different_base_currency(self):
     """Tests the total with a different base currency than EUR."""
     Budget.set_currency("USD")
     group = Group("Test Group", [Entry("Entry 1", 100)])
     self.assertEqual(group.total(), Money(100, "USD"))