Ignore:
Timestamp:
2 Mar 2015, 01:01:10 (10 years ago)
Author:
uli
Message:

More Payment.amount tests.

Location:
main/waeup.ikoba/branches/uli-fake-gw-provider/src/waeup/ikoba/payments
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/branches/uli-fake-gw-provider/src/waeup/ikoba/payments/payment.py

    r12646 r12648  
    6666        Equals the sum of items contained.
    6767        """
    68         return sum([item.amount for item in self.values()])
     68        return sum(
     69            [item.amount for item in self.values()],
     70            decimal.Decimal("0.00")  # default value
     71        )
    6972
    7073    def __init__(self):
  • main/waeup.ikoba/branches/uli-fake-gw-provider/src/waeup/ikoba/payments/tests/test_payment.py

    r12644 r12648  
    1717##
    1818import datetime
     19import decimal
    1920import re
    2021import unittest
     
    129130        assert len(p1) == 2  # do not make assumptions about result content
    130131
     132    def test_amount(self):
     133        # the amount of a payment is the sum of amounts of its items
     134        p1 = Payment()
     135        item1 = PaymentItem()
     136        item2 = PaymentItem()
     137        p1.add_payment_item(item1)
     138        p1.add_payment_item(item2)
     139        item1.amount = decimal.Decimal("12.25")
     140        item2.amount = decimal.Decimal("0.5")
     141        assert p1.amount == decimal.Decimal("12.75")
     142
     143    def test_amount_negative(self):
     144        # we can sum up negative numbers
     145        p1 = Payment()
     146        item1 = PaymentItem()
     147        item2 = PaymentItem()
     148        p1.add_payment_item(item1)
     149        p1.add_payment_item(item2)
     150        item1.amount = decimal.Decimal("2.21")
     151        item2.amount = decimal.Decimal("-3.23")
     152        assert p1.amount == decimal.Decimal("-1.02")
     153
     154    def test_amount_empty(self):
     155        # the amount of zero items is 0.00.
     156        p1 = Payment()
     157        assert p1.amount == decimal.Decimal("0.00")
     158        assert isinstance(p1.amount, decimal.Decimal)
     159
    131160
    132161class PaymentItemTests(unittest.TestCase):
Note: See TracChangeset for help on using the changeset viewer.