Beispiel #1
0
 def test_subtract_fail(self):
     """
     An exception is thrown when subtracting money with different currencies
     """
     eur = Money(0, Currency('eur'))
     usd = Money(0, Currency('usd'))
     with self.assertRaises(ValueError):
         eur - usd
    def test_return_currencies_not_equals(self):
        """
        It returns currency minor unit
        """
        currency1 = Currency('EUR')
        currency2 = Currency('USD')

        self.assertFalse(currency1.equals(currency2))
Beispiel #3
0
    def test_not_equals(self):
        """
        It returns false when two money objects are not equal
        """
        money1 = Money(0, self.currency)
        money2 = Money(10, self.currency)

        self.assertFalse(money1 == money2)

        money1 = Money(0, Currency('EUR'))
        money2 = Money(0, Currency('USD'))

        self.assertFalse(money1 == money2)
 def test_return_currency_minor_unit(self):
     code = 'EUR'
     """
     It returns currency minor unit
     """
     currency = Currency(code)
     self.assertEqual(2, currency.minor_unit)
 def test_return_currency_iso_code(self):
     code = 'EUR'
     """
     It returns currency iso code
     """
     currency = Currency(code)
     self.assertEqual(978, currency.iso_code)
 def test_return_currency_name(self):
     code = 'EUR'
     """
     It returns currency name
     """
     currency = Currency(code)
     self.assertEqual('Euro', currency.name)
 def test_return_currency_code(self):
     code = 'EUR'
     """
     It returns currency alphabetic code
     """
     currency = Currency(code)
     self.assertEqual(code, currency.code)
Beispiel #8
0
    def test_not_less__or_equal_than(self):
        """
        It returns false when money amount is not less or equal than given money object
        """
        money1 = Money(10, self.currency)
        money2 = Money(0, self.currency)

        self.assertFalse(money1 <= money2)

        """
        An exception is thrown when comparing money objects with different currencies
        """
        money1 = Money(0, Currency('EUR'))
        money2 = Money(0, Currency('USD'))

        with self.assertRaises(ValueError):
            self.assertFalse(money1 <= money2)
Beispiel #9
0
        def deserialize(self, node, cstruct):
            r = super().deserialize(node, cstruct)
            if r in (schema.types.Null, None):
                return r
            try:
                currency = Currency(r[0])
            except ValueError:
                raise schema.Invalid(node, f'Invalid currency token in {r}',
                                     cstruct)

            try:
                rv = Money(r[1], currency)
            except:
                raise schema.Invalid(node, f'Invalid amount in {r}', cstruct)

            return rv
Beispiel #10
0
 def __to_proposal(self, obj: dict) -> Proposal:
     return Proposal(
         flexibility_level=obj["flexibility"],
         price=Money(str(obj["price"]["value"]),
                     Currency(obj["price"]["currency"])),
     )
Beispiel #11
0
 def setUp(self):
     """
     Prepare default currency object for test cases
     """
     self.currency = Currency('EUR')
 def test_creates_currency(self):
     """
     It creates a new currency object
     """
     Currency('EUR')
 def test_fails_to_create_currency(self):
     """
     An exception is thrown when currency is invalid
     """
     with self.assertRaises(ValueError):
         Currency('foo')