Changeset 12683
- Timestamp:
- 7 Mar 2015, 04:18:42 (10 years ago)
- Location:
- main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/customers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/customers/contracts.py
r12681 r12683 32 32 IContractSelectProduct, ICustomersUtils, ISampleContract, 33 33 ISampleContractProcess, ISampleContractEdit, ISampleContractOfficialUse) 34 from waeup.ikoba.payments.interfaces import IPaymentItem 35 from waeup.ikoba.payments.payment import PaymentItem 34 36 from waeup.ikoba.utils.helpers import attrs_to_fields 35 37 … … 56 58 57 59 ContractsContainer = attrs_to_fields(ContractsContainer) 60 61 62 def payment_items_from_contract(contract): 63 """Turn contract product options into payment items. 64 """ 65 result = [] 66 for num, option in enumerate(contract.product_options): 67 item = PaymentItem() 68 item.item_id = u'%s' % num 69 item.title = option.title 70 item.amount = option.fee 71 result.append(item) 72 return result 58 73 59 74 -
main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/customers/tests/test_contract.py
r12682 r12683 19 19 Tests for contracts. 20 20 """ 21 import decimal 21 22 from zope.interface.verify import verifyClass, verifyObject 22 23 from zope.component import createObject … … 26 27 IContractsContainer, IContract) 27 28 from waeup.ikoba.customers.contracts import ( 28 ContractsContainer, SampleContract) 29 ContractsContainer, SampleContract, payment_items_from_contract, 30 ) 31 from waeup.ikoba.payments.interfaces import IPaymentItem 32 from waeup.ikoba.products.productoptions import ProductOption 29 33 from waeup.ikoba.testing import (FunctionalLayer, FunctionalTestCase) 30 34 … … 89 93 self.assertTrue('Contract created by system' in messages) 90 94 return 95 96 97 class TestContractHelpers(FunctionalTestCase): 98 99 layer = FunctionalLayer 100 101 def test_payment_items_from_contract(self): 102 # we can turn contracts into lists of payment items 103 contract = SampleContract() 104 option1 = ProductOption(u"Fee 1", decimal.Decimal("31.10"), "USD") 105 option2 = ProductOption(u"Fee 2", decimal.Decimal("12.12"), "USD") 106 contract.product_options = [option1, option2] 107 payment_items = payment_items_from_contract(contract) 108 assert len(payment_items) == 2 109 item1, item2 = payment_items 110 assert IPaymentItem.providedBy(item1) 111 assert IPaymentItem.providedBy(item2) 112 assert item1.item_id == "0" 113 assert item2.item_id == "1" 114 assert item1.title == u'Fee 1' 115 assert item2.title == u'Fee 2' 116 assert item1.amount == decimal.Decimal("31.10") 117 assert item2.amount == decimal.Decimal("12.12") 118 119 def test_payment_item_from_contract_no_options(self): 120 # we cope with empty contracts 121 contract = SampleContract() 122 payment_items = payment_items_from_contract(contract) 123 assert payment_items == []
Note: See TracChangeset for help on using the changeset viewer.