Commit 621d8e5f authored by Sebastien Robin's avatar Sebastien Robin

* merge two _addPropertySheet methods to a single method

* change the way parameters are passed to _addPropertySheet when
  the unified method is different from the original one

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27859 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent fb404878
...@@ -112,13 +112,6 @@ class TestCalendar(ERP5ReportTestCase): ...@@ -112,13 +112,6 @@ class TestCalendar(ERP5ReportTestCase):
transaction.commit() transaction.commit()
self.tic() 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): def stepCreatePerson(self, sequence=None, sequence_list=None, **kw):
""" """
Create an person Create an person
......
...@@ -46,6 +46,7 @@ from Products.ERP5Type.Utils import getLocalConstraintList, \ ...@@ -46,6 +46,7 @@ from Products.ERP5Type.Utils import getLocalConstraintList, \
removeLocalConstraint, \ removeLocalConstraint, \
importLocalConstraint importLocalConstraint
from Products.DCWorkflow.DCWorkflow import ValidationFailed from Products.DCWorkflow.DCWorkflow import ValidationFailed
from Products.ERP5Type.Base import _aq_reset
from zLOG import LOG, DEBUG from zLOG import LOG, DEBUG
# Quiet messages when installing products # Quiet messages when installing products
...@@ -517,6 +518,39 @@ class ERP5TypeTestCase(PortalTestCase): ...@@ -517,6 +518,39 @@ class ERP5TypeTestCase(PortalTestCase):
return getattr(self.getPortal(), 'currency_module', return getattr(self.getPortal(), 'currency_module',
getattr(self.getPortal(), 'currency', None)) 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): def validateRules(self):
""" """
try to validate all rules in rule_tool. try to validate all rules in rule_tool.
......
...@@ -1270,7 +1270,8 @@ class TestConstraint(PropertySheetTestCase): ...@@ -1270,7 +1270,8 @@ class TestConstraint(PropertySheetTestCase):
self.assertEquals([], constraint.checkConsistency(obj)) self.assertEquals([], constraint.checkConsistency(obj))
# now add a 'local_property' property defined on a property sheet # now add a 'local_property' property defined on a property sheet
self._addPropertySheet(obj.getPortalType(), self._addPropertySheet(obj.getPortalType(),
'''class TestPropertySheet: _categories=('testing_category',)''') property_sheet_code=\
'''class TestPropertySheet: _categories=('testing_category',)''')
# fix consistency # fix consistency
constraint.fixConsistency(obj) constraint.fixConsistency(obj)
# now we can use testing_category as any category accessor # now we can use testing_category as any category accessor
...@@ -1397,6 +1398,7 @@ class TestConstraint(PropertySheetTestCase): ...@@ -1397,6 +1398,7 @@ class TestConstraint(PropertySheetTestCase):
obj = self._makeOne() obj = self._makeOne()
obj.setTitle('b') obj.setTitle('b')
self._addPropertySheet(obj.getPortalType(), self._addPropertySheet(obj.getPortalType(),
property_sheet_code=\
'''class TestPropertySheet: '''class TestPropertySheet:
_constraints = ( _constraints = (
{ 'id': 'testing_constraint', { 'id': 'testing_constraint',
...@@ -1417,6 +1419,7 @@ class TestConstraint(PropertySheetTestCase): ...@@ -1417,6 +1419,7 @@ class TestConstraint(PropertySheetTestCase):
obj = self._makeOne() obj = self._makeOne()
obj.setTitle('b') obj.setTitle('b')
self._addPropertySheet(obj.getPortalType(), self._addPropertySheet(obj.getPortalType(),
property_sheet_code=\
'''class TestPropertySheet: '''class TestPropertySheet:
_constraints = ( _constraints = (
{ 'id': 'testing_constraint', { 'id': 'testing_constraint',
......
...@@ -95,37 +95,8 @@ class %(property_sheet_name)s: ...@@ -95,37 +95,8 @@ class %(property_sheet_name)s:
_properties = ( %(property_definition_code)s, ) _properties = ( %(property_definition_code)s, )
""" % locals() """ % locals()
self._addPropertySheet(portal_type_name, self._addPropertySheet(portal_type_name,
property_sheet_code, property_sheet_code=property_sheet_code,
property_sheet_name) property_sheet_name=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()
class TestERP5Type(PropertySheetTestCase, LogInterceptor): class TestERP5Type(PropertySheetTestCase, LogInterceptor):
"""Tests ERP5TypeInformation and per portal type generated accessors. """Tests ERP5TypeInformation and per portal type generated accessors.
...@@ -622,7 +593,7 @@ class TestPropertySheet: ...@@ -622,7 +593,7 @@ class TestPropertySheet:
) )
""" """
self._addPropertySheet('Organisation', text) self._addPropertySheet('Organisation', property_sheet_code=text)
folder = self.getOrganisationModule() folder = self.getOrganisationModule()
# We check that we raise exception when we create new object # We check that we raise exception when we create new object
from Products.ERP5Type.Utils import ConstraintNotFound from Products.ERP5Type.Utils import ConstraintNotFound
...@@ -2047,7 +2018,7 @@ class TestPropertySheet: ...@@ -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. # Create a new person, and associate it to beta and gamma.
module = self.getPersonModule() module = self.getPersonModule()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment