Ignore:
Timestamp:
6 Mar 2015, 23:12:36 (10 years ago)
Author:
uli
Message:

Merge changes from uli-fake-gw-provider back into trunk.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba/payments/tests
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/payments/tests/test_payment.py

    r12461 r12671  
    1717##
    1818import datetime
     19import decimal
    1920import re
    2021import unittest
    21 from zope.component import getUtilitiesFor, getSiteManager
     22from zope.component import getUtilitiesFor, getSiteManager, queryUtility
    2223from zope.interface import implements
    2324from zope.interface.verify import verifyClass, verifyObject
    2425from waeup.ikoba.payments.interfaces import (
    2526    IPayment, STATE_UNPAID, STATE_PAID, STATE_FAILED,
    26     IPaymentGatewayService, IPaymentItem
     27    IPaymentGatewayService, IPaymentItem, IPaymentGatewayServicesLister,
    2728    )
    2829from waeup.ikoba.payments.payment import (
    2930    Payment, get_payment_providers, PaymentItem,
    3031    )
     32from waeup.ikoba.testing import (FunctionalLayer, FunctionalTestCase)
    3133
    3234
     
    5860        assert result.keys() == ['some_name', ]
    5961        assert result['some_name'] is fake_util
     62
     63
     64class FunctionalHelperTests(FunctionalTestCase):
     65
     66    layer = FunctionalLayer
     67
     68    def test_services_lister_is_registered(self):
     69        # a lister of gateway services is registered on startup
     70        util = queryUtility(IPaymentGatewayServicesLister)
     71        assert util is not None
     72
     73    def test_services_are_really_listed(self):
     74        # we can really get locally registered gateways when calling
     75        util = queryUtility(IPaymentGatewayServicesLister)
     76        assert len(util()) > 0
    6077
    6178
     
    113130        assert p1.state == STATE_FAILED
    114131
     132    def test_add_payment_item(self):
     133        # we can add payment items
     134        p1 = Payment()
     135        item1 = PaymentItem()
     136        result = p1.add_payment_item(item1)
     137        assert len(p1) == 1  # do not make assumptions about result content
     138        assert isinstance(result, basestring)
     139
     140    def test_add_payment_item_multiple(self):
     141        # we can add several items
     142        p1 = Payment()
     143        item1 = PaymentItem()
     144        item2 = PaymentItem()
     145        result1 = p1.add_payment_item(item1)
     146        result2 = p1.add_payment_item(item2)
     147        assert len(p1) == 2  # do not make assumptions about result content
     148        assert isinstance(result1, basestring)
     149        assert isinstance(result2, basestring)
     150
     151    def test_amount(self):
     152        # the amount of a payment is the sum of amounts of its items
     153        p1 = Payment()
     154        item1 = PaymentItem()
     155        item2 = PaymentItem()
     156        p1.add_payment_item(item1)
     157        p1.add_payment_item(item2)
     158        item1.amount = decimal.Decimal("12.25")
     159        item2.amount = decimal.Decimal("0.5")
     160        assert p1.amount == decimal.Decimal("12.75")
     161
     162    def test_amount_negative(self):
     163        # we can sum up negative numbers
     164        p1 = Payment()
     165        item1 = PaymentItem()
     166        item2 = PaymentItem()
     167        p1.add_payment_item(item1)
     168        p1.add_payment_item(item2)
     169        item1.amount = decimal.Decimal("2.21")
     170        item2.amount = decimal.Decimal("-3.23")
     171        assert p1.amount == decimal.Decimal("-1.02")
     172
     173    def test_amount_empty(self):
     174        # the amount of zero items is 0.00.
     175        p1 = Payment()
     176        assert p1.amount == decimal.Decimal("0.00")
     177        assert isinstance(p1.amount, decimal.Decimal)
     178
    115179
    116180class PaymentItemTests(unittest.TestCase):
Note: See TracChangeset for help on using the changeset viewer.