Changeset 12194 for main/waeup.ikoba/trunk/src/waeup
- Timestamp:
- 11 Dec 2014, 08:12:31 (10 years ago)
- Location:
- main/waeup.ikoba/trunk/src/waeup/ikoba
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/documents.py
r12169 r12194 25 25 from zope.component.interfaces import IFactory 26 26 from zope.interface import implementedBy 27 from zope.event import notify 27 28 28 29 from waeup.ikoba.image import IkobaImageFile … … 321 322 file_obj.filename, file_obj.data) 322 323 324 325 @grok.subscribe(ICustomerDocument, grok.IObjectRemovedEvent) 326 def handle_document_removed(document, event): 327 """If a document is deleted, we make sure that also referrers to 328 customer contract objects are removed. 329 """ 330 docid = document.document_id 331 332 # Find all customer contracts that refer to given document... 333 try: 334 contracts = document.customer['contracts'].values() 335 except AttributeError: 336 # customer not available. This might happen during tests. 337 return 338 for contract in contracts: 339 # Remove that referrer... 340 #contract.product = None 341 for key, value in contract.__dict__.items(): 342 if key.endswith('_object') and \ 343 getattr(value, 'document_id', None) == docid: 344 setattr(contract, key, None) 345 notify(grok.ObjectModifiedEvent(contract)) 346 contract.customer.__parent__.logger.info( 347 'ObjectRemovedEvent - %s - %s - removed: %s' % ( 348 contract.customer.customer_id, 349 contract.contract_id, 350 document.document_id)) 351 return 352 -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_catalog.py
r12098 r12194 24 24 from zope.component import queryUtility, createObject 25 25 from zope.component.hooks import setSite 26 from hurry.workflow.interfaces import IWorkflowState 26 27 from waeup.ikoba.app import Company 28 from waeup.ikoba.interfaces import VERIFIED 27 29 from waeup.ikoba.testing import FunctionalLayer, FunctionalTestCase 28 30 from waeup.ikoba.customers.customer import Customer … … 66 68 self.product = self.app['products'][self.product_id] 67 69 70 document = createObject('waeup.CustomerSampleDocument') 71 document.title = u'My Samle Document' 72 IWorkflowState(document).setState(VERIFIED) 73 self.customer['documents'].addDocument(document) 74 self.document_id = document.document_id 75 self.document = self.customer['documents'][self.document_id] 76 68 77 contract = createObject('waeup.SampleContract') 69 78 contract.title = u'My Samle Contract' 70 contract.product = product 79 contract.product_object = product 80 contract.document_object = document 71 81 contract.last_product_id = product.product_id 72 82 self.customer['contracts'].addContract(contract) 73 83 self.contract_id = contract.contract_id 74 84 self.contract = self.customer['contracts'][self.contract_id] 75 76 document = createObject('waeup.CustomerSampleDocument')77 document.title = u'My Samle Document'78 self.customer['documents'].addDocument(document)79 self.document_id = document.document_id80 self.document = self.customer['documents'][self.document_id]81 85 82 86 return … … 167 171 assert len(results) == 1 168 172 assert results[0] is self.customer['contracts'][self.contract_id] 169 assert results[0].product is self.product173 assert results[0].product_object is self.product 170 174 171 175 def test_product_removal(self): 172 176 # This test does not only test catalog components, it also ensures 173 # that the product attribute of ancontract is cleared177 # that the product object attribute of a contract is cleared 174 178 # but the last_product_id is not. 175 179 del self.app['products'][self.product_id] 176 self.assertTrue(self.contract.product is None)180 self.assertTrue(self.contract.product_object is None) 177 181 self.assertEqual(self.contract.last_product_id, 'SAM') 178 182 cat = queryUtility(ICatalog, name='contracts_catalog') … … 181 185 assert len(results) == 1 182 186 assert results[0] is self.customer['contracts'][self.contract_id] 183 assert results[0].product is None187 assert results[0].product_object is None 184 188 # Product removal is being logged in customers.log 185 189 logfile = os.path.join( … … 190 194 in logcontent) 191 195 196 def test_document_removal(self): 197 # Actually, this test does not test catalog components at all. 198 # Tt only ensures that the document object attributes of a contract 199 # are cleared, like in the test_product_removal above. 200 del self.customer['documents'][self.document_id] 201 self.assertTrue(self.contract.document_object is None) 202 # Document removal is being logged in customers.log 203 logfile = os.path.join( 204 self.app['datacenter'].storage, 'logs', 'customers.log') 205 logcontent = open(logfile).read() 206 self.assertTrue( 207 'INFO - system - ObjectRemovedEvent - K1000000 - c101 - removed: d101\n' 208 in logcontent) 209 -
main/waeup.ikoba/trunk/src/waeup/ikoba/products/product.py
r12097 r12194 79 79 for contract in results: 80 80 # Remove that referrer... 81 contract.product = None81 contract.product_object = None 82 82 notify(grok.ObjectModifiedEvent(contract)) 83 83 contract.customer.__parent__.logger.info(
Note: See TracChangeset for help on using the changeset viewer.