diff --git a/product/ERP5/tests/testCalendar.py b/product/ERP5/tests/testCalendar.py index 5dd6445efc251a937d0637d4885961739f097a8d..ed5d50a5f103c9718d82336e5faf11ed2bb5595a 100644 --- a/product/ERP5/tests/testCalendar.py +++ b/product/ERP5/tests/testCalendar.py @@ -112,13 +112,6 @@ class TestCalendar(ERP5ReportTestCase): transaction.commit() self.tic() - def _addPropertySheet(self, type_info_name, property_sheet_name): - ti = self.portal.portal_types.getTypeInfo(type_info_name) - if property_sheet_name not in ti.property_sheet_list: - ti.property_sheet_list = tuple(ti.property_sheet_list)\ - + (property_sheet_name,) - _aq_reset() - def stepCreatePerson(self, sequence=None, sequence_list=None, **kw): """ Create an person diff --git a/product/ERP5Type/tests/ERP5TypeTestCase.py b/product/ERP5Type/tests/ERP5TypeTestCase.py index e35fdaf91612f1095eecece48abf922b7d7a97a6..7fd14ef2754d216c734c79bf817ff2fb622d2192 100644 --- a/product/ERP5Type/tests/ERP5TypeTestCase.py +++ b/product/ERP5Type/tests/ERP5TypeTestCase.py @@ -46,6 +46,7 @@ from Products.ERP5Type.Utils import getLocalConstraintList, \ removeLocalConstraint, \ importLocalConstraint from Products.DCWorkflow.DCWorkflow import ValidationFailed +from Products.ERP5Type.Base import _aq_reset from zLOG import LOG, DEBUG # Quiet messages when installing products @@ -517,6 +518,39 @@ class ERP5TypeTestCase(PortalTestCase): return getattr(self.getPortal(), 'currency_module', getattr(self.getPortal(), 'currency', None)) + def _addPropertySheet(self, portal_type_name, + property_sheet_name='TestPropertySheet', + property_sheet_code=None): + """Utility method to add a property sheet to a type information. + You might be interested in the higer level method _addProperty + This method registers all added property sheets, to be able to remove + them in tearDown. + """ + # install the 'real' class tool + class_tool = self.getClassTool() + + if property_sheet_code is not None: + class_tool.newPropertySheet(property_sheet_name) + # XXX need to commit the transaction at this point, because class tool + # files are no longer available to the current transaction. + transaction.commit() + class_tool.editPropertySheet(property_sheet_name, property_sheet_code) + transaction.commit() + class_tool.importPropertySheet(property_sheet_name) + + # We set the property sheet on the portal type + ti = self.getTypesTool().getTypeInfo(portal_type_name) + if property_sheet_name not in ti.property_sheet_list: + ti.property_sheet_list = list(ti.property_sheet_list) +\ + [property_sheet_name] + + # remember that we added a property sheet for tear down + if getattr(self, '_added_property_sheets', None) is not None: + self._added_property_sheets.setdefault( + portal_type_name, []).append(property_sheet_name) + # reset aq_dynamic cache + _aq_reset() + def validateRules(self): """ try to validate all rules in rule_tool. diff --git a/product/ERP5Type/tests/testConstraint.py b/product/ERP5Type/tests/testConstraint.py index 23cbc301d02f0c8a8ccef26e424a4a292eb821b1..0d6883eb9d990a2a87250d4b5e3fe157f802242f 100644 --- a/product/ERP5Type/tests/testConstraint.py +++ b/product/ERP5Type/tests/testConstraint.py @@ -1270,7 +1270,8 @@ class TestConstraint(PropertySheetTestCase): self.assertEquals([], constraint.checkConsistency(obj)) # now add a 'local_property' property defined on a property sheet self._addPropertySheet(obj.getPortalType(), - '''class TestPropertySheet: _categories=('testing_category',)''') + property_sheet_code=\ + '''class TestPropertySheet: _categories=('testing_category',)''') # fix consistency constraint.fixConsistency(obj) # now we can use testing_category as any category accessor @@ -1397,6 +1398,7 @@ class TestConstraint(PropertySheetTestCase): obj = self._makeOne() obj.setTitle('b') self._addPropertySheet(obj.getPortalType(), + property_sheet_code=\ '''class TestPropertySheet: _constraints = ( { 'id': 'testing_constraint', @@ -1417,6 +1419,7 @@ class TestConstraint(PropertySheetTestCase): obj = self._makeOne() obj.setTitle('b') self._addPropertySheet(obj.getPortalType(), + property_sheet_code=\ '''class TestPropertySheet: _constraints = ( { 'id': 'testing_constraint', diff --git a/product/ERP5Type/tests/testERP5Type.py b/product/ERP5Type/tests/testERP5Type.py index cc4c823e19d40052c1fda63d98f248af93571480..fcf557766a73bc91698b908eb8bb55ac22b9cb8a 100644 --- a/product/ERP5Type/tests/testERP5Type.py +++ b/product/ERP5Type/tests/testERP5Type.py @@ -95,37 +95,8 @@ class %(property_sheet_name)s: _properties = ( %(property_definition_code)s, ) """ % locals() self._addPropertySheet(portal_type_name, - property_sheet_code, - property_sheet_name) - - def _addPropertySheet(self, portal_type_name, property_sheet_code, - property_sheet_name='TestPropertySheet'): - """Utility method to add a property sheet to a type information. - You might be interested in the higer level method _addProperty - This method registers all added property sheets, to be able to remove - them in tearDown. - """ - # install the 'real' class tool - class_tool = self.getClassTool() - - class_tool.newPropertySheet(property_sheet_name) - # XXX need to commit the transaction at this point, because class tool - # files are no longer available to the current transaction. - transaction.commit() - class_tool.editPropertySheet(property_sheet_name, property_sheet_code) - transaction.commit() - class_tool.importPropertySheet(property_sheet_name) - - # We set the property sheet on the portal type - ti = self.getTypesTool().getTypeInfo(portal_type_name) - ti.property_sheet_list = list(ti.property_sheet_list) +\ - [property_sheet_name] - # remember that we added a property sheet for tear down - self._added_property_sheets.setdefault( - portal_type_name, []).append(property_sheet_name) - # reset aq_dynamic cache - _aq_reset() - + property_sheet_code=property_sheet_code, + property_sheet_name=property_sheet_name) class TestERP5Type(PropertySheetTestCase, LogInterceptor): """Tests ERP5TypeInformation and per portal type generated accessors. @@ -622,7 +593,7 @@ class TestPropertySheet: ) """ - self._addPropertySheet('Organisation', text) + self._addPropertySheet('Organisation', property_sheet_code=text) folder = self.getOrganisationModule() # We check that we raise exception when we create new object from Products.ERP5Type.Utils import ConstraintNotFound @@ -2047,7 +2018,7 @@ class TestPropertySheet: ) """ - self._addPropertySheet('Person', text) + self._addPropertySheet('Person', property_sheet_code=text) # Create a new person, and associate it to beta and gamma. module = self.getPersonModule()