Changeset 12671 for main/waeup.ikoba/trunk/src/waeup/ikoba/payments/tests
- Timestamp:
- 6 Mar 2015, 23:12:36 (10 years ago)
- 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 17 17 ## 18 18 import datetime 19 import decimal 19 20 import re 20 21 import unittest 21 from zope.component import getUtilitiesFor, getSiteManager 22 from zope.component import getUtilitiesFor, getSiteManager, queryUtility 22 23 from zope.interface import implements 23 24 from zope.interface.verify import verifyClass, verifyObject 24 25 from waeup.ikoba.payments.interfaces import ( 25 26 IPayment, STATE_UNPAID, STATE_PAID, STATE_FAILED, 26 IPaymentGatewayService, IPaymentItem 27 IPaymentGatewayService, IPaymentItem, IPaymentGatewayServicesLister, 27 28 ) 28 29 from waeup.ikoba.payments.payment import ( 29 30 Payment, get_payment_providers, PaymentItem, 30 31 ) 32 from waeup.ikoba.testing import (FunctionalLayer, FunctionalTestCase) 31 33 32 34 … … 58 60 assert result.keys() == ['some_name', ] 59 61 assert result['some_name'] is fake_util 62 63 64 class 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 60 77 61 78 … … 113 130 assert p1.state == STATE_FAILED 114 131 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 115 179 116 180 class PaymentItemTests(unittest.TestCase):
Note: See TracChangeset for help on using the changeset viewer.