Commit 56eafa53 authored by Nicolas Wavrant's avatar Nicolas Wavrant

erp5-upgrader: new test for sequentiality of activities run by upgrader

parent bd656a2e
......@@ -767,4 +767,71 @@ class TestUpgrader(ERP5TypeTestCase):
stepCheckPostUpgradeRequired
"""
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def _setPersonTitleConstraintForUpgraderStep(self, step):
portal = self.portal
skin_folder = portal.portal_skins.custom
script_id = "Person_%s_setTitleConstraint" % step
custom_script = getattr(skin_folder, script_id, None)
if custom_script is None:
skin_folder.manage_addProduct['PythonScripts'].manage_addPythonScript(script_id)
custom_script = getattr(skin_folder, script_id)
script_body = "{step_string}='M. {step_string}'\n" + \
"if context.getTitle() != {step_string}:\n" + \
" if fixit:\n" + \
" context.setTitle({step_string})\n" + \
" else:\n" + \
" return [\"Person's title is wrong\",]\n" + \
"return []"
script_body = script_body.format(step_string=step)
custom_script.ZPythonScript_edit('fixit=False, **kw', script_body)
property_sheet_id = self.property_sheet_id
property_sheet = getattr(portal.portal_property_sheets, property_sheet_id, None)
script_constraint_id = "person_title_%s_constraint" % step
script_constraint = getattr(property_sheet, script_constraint_id, None)
if script_constraint is None:
script_constraint = property_sheet.newContent(
portal_type="Script Constraint",
id=script_constraint_id
)
script_constraint.edit(
script_id=script_id,
constraint_type="%s" % step)
def stepSetPersonTitlePreUpgradeConstraint(self, sequence=None):
self._setPersonTitleConstraintForUpgraderStep('pre_upgrade')
def stepSetPersonTitleUpgradeConstraint(self, sequence=None):
self._setPersonTitleConstraintForUpgraderStep('upgrader')
def stepSetPersonTitlePostUpgradeConstraint(self, sequence=None):
self._setPersonTitleConstraintForUpgraderStep('post_upgrade')
def stepCheckPersonTitleHasBeenSetByPersonTitlePostUpgradeConstraint(self, sequence=None):
person = sequence['person']
title = person.getTitle()
self.assertEqual(title, 'M. post_upgrade')
def test_upgrade_activities_are_run_sequentially(self):
"""
Check that activities spawned by the upgrader are always run in the same
order : pre-upgrade, upgrade, post-upgrade
"""
sequence_list = SequenceList()
sequence_string = """
stepCreatePerson
stepValidatePerson
stepCreatePersonPropertySheet
stepSetConstraintInPersonPortalType
stepSetPersonTitlePreUpgradeConstraint
stepSetPersonTitleUpgradeConstraint
stepSetPersonTitlePostUpgradeConstraint
stepTic
stepRunUpgrader
stepTic
stepCheckPersonTitleHasBeenSetByPersonTitlePostUpgradeConstraint
"""
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
\ No newline at end of file
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