Changeset 12738 for main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/customers/tests/test_customer.py
- Timestamp:
- 11 Mar 2015, 22:44:17 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/customers/tests/test_customer.py
r12297 r12738 24 24 from cStringIO import StringIO 25 25 from datetime import tzinfo 26 from zope.component import getUtility, queryUtility, createObject 26 from zope.component import ( 27 getUtility, queryUtility, createObject, getUtilitiesFor, 28 ) 29 from zope.component.hooks import setSite 27 30 from zope.catalog.interfaces import ICatalog 28 31 from zope.component.interfaces import IFactory … … 31 34 from zope.schema.interfaces import RequiredMissing 32 35 from waeup.ikoba.interfaces import IExtFileStore, IFileStoreNameChooser 36 from waeup.ikoba.app import Company 33 37 from waeup.ikoba.customers.customer import ( 34 Customer, CustomerFactory, handle_customer_removed, path_from_custid) 38 Customer, CustomerFactory, handle_customer_removed, path_from_custid, 39 CustomerPayer, CustomerFinder, 40 ) 35 41 from waeup.ikoba.customers.interfaces import ( 36 42 ICustomer, ICustomerNavigation, ICustomersUtils) 37 43 from waeup.ikoba.customers.tests.test_batching import CustomerImportExportSetup 44 from waeup.ikoba.payments.interfaces import IPayer, IPayerFinder 38 45 from waeup.ikoba.testing import FunctionalLayer, FunctionalTestCase 39 46 … … 92 99 93 100 101 class TestCustomerHelpers(FunctionalTestCase): 102 103 layer = FunctionalLayer 104 105 def test_payer_adapter(self): 106 # we can adapt ICustomer to IPayer (i.e. create a payer) 107 customer = Customer() 108 customer.firstname, customer.lastname = u'Anna', u'Tester' 109 result = IPayer(customer) 110 self.assertTrue(isinstance(result, CustomerPayer)) 111 verify.verifyObject(IPayer, result) 112 self.assertEqual(result.first_name, u'Anna') 113 self.assertEqual(result.last_name, u'Tester') 114 self.assertEqual(result.payer_id, customer.customer_id) 115 116 def test_customer_finder_iface(self): 117 # we have a customer finder that returns IPayableFinder data. 118 verify.verifyClass(IPayerFinder, CustomerFinder) 119 120 def test_customer_finder_registered(self): 121 # the customer finder is a utility registered on startup 122 util = getUtility(IPayerFinder, name='customer_finder') 123 self.assertTrue(isinstance(util, CustomerFinder)) 124 utils = [util for name, util in getUtilitiesFor(IPayerFinder) 125 if isinstance(util, CustomerFinder)] 126 self.assertEqual(len(utils), 1) 127 128 def create_customer_and_site(self): 129 customer = Customer() 130 customer.customer_id = u'CUST1' 131 self.getRootFolder()['app'] = Company() 132 app = self.getRootFolder()['app'] 133 setSite(app) 134 return customer, app 135 136 def test_customer_finder(self): 137 # the customer finder can really find customers 138 customer, app = self.create_customer_and_site() 139 app['mycustomer'] = customer # trigger cataloging 140 finder = CustomerFinder() 141 result = finder.get_payer_by_id('CUST1') 142 self.assertTrue(result is customer) 143 144 def test_customer_finder_not_stored(self): 145 # we get none if an id is not stored 146 customer, app = self.create_customer_and_site() 147 app['mycustomer'] = customer # trigger cataloging 148 finder = CustomerFinder() 149 result = finder.get_payer_by_id('Not-a-valid-id') 150 self.assertTrue(result is None) 151 152 def test_customer_finder_no_catalog(self): 153 # customer finder does not complain about missing catalog 154 finder = CustomerFinder() 155 result = finder.get_payer_by_id('CUST1') 156 self.assertTrue(result is None) 157 158 94 159 class CustomerRemovalTests(CustomerImportExportSetup): 95 160 # Test handle_customer_removed
Note: See TracChangeset for help on using the changeset viewer.