Changeset 12716
- Timestamp:
- 10 Mar 2015, 14:59:34 (10 years ago)
- Location:
- main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/customers/contracts.py
r12698 r12716 20 20 """ 21 21 import grok 22 from zope.catalog.interfaces import ICatalog 22 23 from zope.component import getUtility 23 24 from zope.component.interfaces import IFactory … … 32 33 IContractSelectProduct, ICustomersUtils, ISampleContract, 33 34 ISampleContractProcess, ISampleContractEdit, ISampleContractOfficialUse) 34 from waeup.ikoba.payments.interfaces import IPayer 35 from waeup.ikoba.payments.interfaces import IPayer, IPayableFinder 35 36 from waeup.ikoba.payments.payment import PaymentItem 36 37 from waeup.ikoba.utils.helpers import attrs_to_fields … … 258 259 IWorkflowInfo(contract).fireTransition('create') 259 260 return 261 262 263 class ContractFinder(grok.GlobalUtility): 264 grok.name('contracts_finder') 265 grok.implements(IPayableFinder) 266 267 def get_item_by_id(self, contract_id): 268 catalog = getUtility(ICatalog, 'contracts_catalog') 269 result = catalog.searchResults( 270 contract_id=(contract_id, contract_id)) 271 result = [x for x in result] 272 if not result: 273 return None 274 # there should not be more than one result really. 275 return result[0] -
main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/customers/tests/test_contract.py
r12697 r12716 21 21 import decimal 22 22 from zope.interface.verify import verifyClass, verifyObject 23 from zope.component import createObject 23 from zope.component import createObject, getUtility, getUtilitiesFor 24 from zope.component.hooks import setSite 24 25 from hurry.workflow.interfaces import ( 25 26 IWorkflowInfo, IWorkflowState, InvalidTransitionError) … … 28 29 from waeup.ikoba.customers.contracts import ( 29 30 ContractsContainer, SampleContract, payment_items_from_contract, 30 ContractPayer, 31 ContractPayer, ContractFinder 31 32 ) 33 from waeup.ikoba.app import Company 32 34 from waeup.ikoba.customers.customer import Customer 33 from waeup.ikoba.payments.interfaces import IPaymentItem, IPayer 35 from waeup.ikoba.payments.interfaces import ( 36 IPaymentItem, IPayer, IPayableFinder, 37 ) 34 38 from waeup.ikoba.products.productoptions import ProductOption 35 39 from waeup.ikoba.testing import (FunctionalLayer, FunctionalTestCase) … … 138 142 self.assertEqual(result.last_name, u'Tester') 139 143 self.assertEqual(result.payer_id, customer.customer_id) 144 145 def test_contract_finder_iface(self): 146 # we have a contract finder that returns IPayableFinder data. 147 verifyClass(IPayableFinder, ContractFinder) 148 149 def test_contract_finder_registered(self): 150 # the contract finder is a utility registered on startup 151 util = getUtility(IPayableFinder, name='contracts_finder') 152 self.assertTrue(isinstance(util, ContractFinder)) 153 utils = [util for name, util in getUtilitiesFor(IPayableFinder) 154 if isinstance(util, ContractFinder)] 155 self.assertEqual(len(utils), 1) 156 157 def create_contract_and_site(self): 158 contract = SampleContract() 159 option1 = ProductOption(u"Fee 1", decimal.Decimal("31.10"), "USD") 160 option2 = ProductOption(u"Fee 2", decimal.Decimal("12.12"), "USD") 161 contract.product_options = [option1, option2] 162 contract.contract_id = u'CON1234' 163 self.getRootFolder()['app'] = Company() 164 app = self.getRootFolder()['app'] 165 setSite(app) 166 return contract, app 167 168 def test_contract_finder(self): 169 # the contract finder can really find contracts 170 contract, app = self.create_contract_and_site() 171 app['mycontract'] = contract # trigger cataloging 172 finder = ContractFinder() 173 result = finder.get_item_by_id('CON1234') 174 self.assertTrue(result is contract) 175 176 def test_contract_finder_not_stored(self): 177 # we get none if an id is not stored 178 contract, app = self.create_contract_and_site() 179 app['mycontract'] = contract # trigger cataloging 180 finder = ContractFinder() 181 result = finder.get_item_by_id('Not-a-valid-id') 182 self.assertTrue(result is None) -
main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/payments/interfaces.py
r12713 r12716 144 144 145 145 146 class IPayableFinder(Interface): 147 """Finds payables. 148 """ 149 def get_item_by_id(item_id): 150 """Get an item by its Id, or none. 151 """ 152 153 146 154 class IPaymentItem(Interface): 147 155 """Something to sell.
Note: See TracChangeset for help on using the changeset viewer.