test.erp5.testUpgrader.py 30.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745
##############################################################################
#
# Copyright (c) 2013 Nexedi SA and Contributors. All Rights Reserved.
#                         Gabriel M. Monnerat <gabriel@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
##############################################################################

import re
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5.Tool.TemplateTool import BusinessTemplateUnknownError
from Products.ERP5Type.tests.Sequence import SequenceList
from Products.ERP5.genbt5list import main as genbt5list
from Products.ERP5 import ERP5Site
import os

DETAIL_PATTERN = re.compile(r"(?P<relative_url>.*)\ \<\>\ " + \
      r"(?P<reference>\w+)\ \-\>\ (?P<new_reference>\w+)")

class TestUpgrader(ERP5TypeTestCase):
  """
    Test one upgrader using constraints
  """

  script_id = "Person_checkPreUpgradeReferenceConsistency_custom"
  property_sheet_id = "TestPersonConstraint"

  def getTitle(self):
    return "Upgrader Tests"

  def getBusinessTemplateList(self):
    return ('erp5_upgrader',)

  def stepCreatePerson(self, sequence):
    module = self.portal.person_module
    person = module.newContent(portal_type="Person", title="User",
      reference="user%s" % module.getLastId())
    sequence.edit(person=person)

  def stepValidatePerson(self, sequence):
    sequence.get("person").validate()

  def afterSetUp(self):
    self.portal.portal_types['Person Module'].setTypePropertySheetList(None)
    self.stepRemoveConstraintFromPersonPortalType()
    for person in self.portal.person_module.searchFolder(
        validation_state='validated', title="User"):
      if person.getValidationState() == "validated":
        person.invalidate()
    # update the bt5list will be updated to the version of the filesystem
    bootstrap_path = os.environ.get('erp5_tests_bootstrap_path') or \
      ERP5Site.getBootstrapDirectory()
    # the path list can contain several directories in projects
    bt5_path_list = os.environ['erp5_tests_bt5_path'].split(',')
    bt5_path_list.append(bootstrap_path)
    genbt5list(dir_list=bt5_path_list)
    self.tic()

  def stepClearCache(self, sequence=None):
    self.portal.portal_caches.clearCache(
      cache_factory_list=('erp5_content_medium',))

  def stepCreatePropertySheetToValidateOrganisation(self, sequence=None):
    portal = self.portal
    skin_folder = portal.portal_skins.custom
    script_id = "Organisation_changeWorkflowFromDraftToValidated"
    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 = "error_list = []\n" + \
        "if context.getValidationState() == 'draft':\n" + \
        "  kw = {'relative_url': context.getRelativeUrl()}\n" + \
        "  error_list.append('%(relative_url)s should be validated' % kw)\n" + \
        "  if fixit:\n" + \
        "    context.validate()\nreturn error_list"
      custom_script.ZPythonScript_edit('fixit=False, **kw', script_body)

    property_sheet_id = "OrganisationDraftConstraint"
    property_sheet = getattr(portal.portal_property_sheets, property_sheet_id, None)
    if property_sheet is None:
      property_sheet = portal.portal_property_sheets.newContent(
        portal_type="Property Sheet", id=property_sheet_id)
    script_constraint_id = "organsation_draft_constraint"
    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="upgrader")

  def stepCreateScriptCheckPreUpgradeReferenceConsistency(self, sequence=None):
    portal = self.portal
    skin_folder = portal.portal_skins.custom
    custom_script = getattr(skin_folder, self.script_id, None)
    if custom_script is None:
      skin_folder.manage_addProduct['PythonScripts'].manage_addPythonScript(self.script_id)
      custom_script = getattr(skin_folder, self.script_id)
      script_body = "error_list = []\n" + \
        "person = context\n" + \
        "reference = person.getReference()\n" + \
        "if reference and not person.getReference().startswith('old_'):\n" + \
        "  kw = {'relative_url': person.getRelativeUrl(), 'reference': person.getReference()}\n" + \
        "  error_list.append('%(relative_url)s <> %(reference)s -> old_%(reference)s' % kw)\n" + \
        "  if fixit:\n" + \
        "    person.setReference('old_%s' % person.getReference())\nreturn error_list"
      custom_script.ZPythonScript_edit('fixit=False, **kw', script_body)
    property_sheet = getattr(portal.portal_property_sheets, self.property_sheet_id, None)
    if property_sheet is None:
      property_sheet = portal.portal_property_sheets.newContent(
        portal_type="Property Sheet", id=self.property_sheet_id)
    script_constraint_id = "person_old_reference_constraint"
    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=self.script_id, constraint_type="pre_upgrade")

  def stepCreatePersonPropertySheet(self, sequence=None):
    portal = self.portal
    property_sheet = getattr(portal.portal_property_sheets, self.property_sheet_id, None)
    if property_sheet is None:
      property_sheet = portal.portal_property_sheets.newContent(
        portal_type="Property Sheet", id=self.property_sheet_id)
    script_constraint_id = "person_old_reference_constraint"
    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=self.script_id, constraint_type="pre_upgrade")

  def stepSetConstraintInOrganisationPortalType(self, sequence=None):
    types_tool = self.portal.portal_types
    portal_type = types_tool['Organisation']
    property_sheet_id = 'OrganisationDraftConstraint'
    if property_sheet_id not in portal_type.getTypePropertySheetList():
      portal_type.setTypePropertySheetList(
        portal_type.getTypePropertySheetList() + [property_sheet_id,])

  def stepRemoveConstraintFromOrganisationPortalType(self, sequence=None):
    types_tool = self.portal.portal_types
    portal_type = types_tool['Organisation']
    property_sheet_id = 'OrganisationDraftConstraint'
    if property_sheet_id not in portal_type.getTypePropertySheetList():
      portal_type.setTypePropertySheetList(
        [i for i in portal_type.getTypePropertySheetList() \
          if i not in [property_sheet_id,]])

  def stepSetConstraintInPersonPortalType(self, sequence=None):
    types_tool = self.portal.portal_types
    portal_type = types_tool['Person']
    if 'TestPersonConstraint' not in portal_type.getTypePropertySheetList():
      portal_type.setTypePropertySheetList(
        portal_type.getTypePropertySheetList() + [self.property_sheet_id,])

  def _checkAlarmSense(self, alarm_id):
    alarm = getattr(self.portal.portal_alarms, alarm_id)
    alarm.activeSense()
    self.tic()
    active_process = alarm.getLastActiveProcess()
    detail_list = [result.detail for result in active_process.getResultList()]
    return alarm.sense(), detail_list

  def _checkEmptyConstraintList(self, alarm_id):
    alarm = getattr(self.portal.portal_alarms, alarm_id)
    active_process = alarm.getLastActiveProcess()
    if active_process is None:
      self.fail("No active process found")
    self.assertEqual(active_process.getResultList(), [])

  def _checkPersonPreUpgradeConstraintList(self):
    alarm = getattr(self.portal.portal_alarms, 'upgrader_check_pre_upgrade')
    active_process = alarm.getLastActiveProcess()
    result_list = active_process.getResultList()
    detail = result_list[0].detail[0]
    group_dict = DETAIL_PATTERN.match(detail).groupdict()
    person = self.portal.restrictedTraverse(group_dict['relative_url'])
    message_list = [m.message for m in person.checkConsistency()]
    self.assertNotEqual(result_list, [])
    self.assertEqual(len(result_list), 1)
    return person, group_dict, detail, message_list

  def stepCheckPersonPreUpgradeConstraintListAfterUpgrade(self, sequence=None):
    person, group_dict, _, message_list = \
      self._checkPersonPreUpgradeConstraintList()
    self.assertEqual(message_list, [])
    self.assertEqual(person.getReference(), group_dict['new_reference'])

  def stepCheckPersonPreUpgradeConstraintList(self, sequence=None):
    _, _, detail, message_list = self._checkPersonPreUpgradeConstraintList()
    self.assertNotEqual(message_list, [])
    self.assertEqual(message_list, [detail,])

  def stepRemoveConstraintFromPersonPortalType(self, sequence=None):
    if 'Person' in self.portal.portal_types.objectIds():
      portal_type = self.portal.portal_types['Person']
      portal_type.setTypePropertySheetList(
        [x for x in portal_type.getTypePropertySheetList() if x != self.property_sheet_id])

  def stepCheckPreUpgradeEmptyConstraintList(self, sequence=None):
    self._checkEmptyConstraintList('upgrader_check_pre_upgrade')

  def stepCheckPostUpgradeEmptyConstraintList(self, sequence=None):
    self._checkEmptyConstraintList('upgrader_check_post_upgrade')

  def stepCheckPosUpgradeWorkflowChainConsistency(self, sequence=None):
    alarm = getattr(self.portal.portal_alarms, 'upgrader_check_post_upgrade')
    active_process = alarm.getLastActiveProcess()
    detail_list = active_process.getResultList()[0].detail
    message = 'Preference - Expected: edit_workflow, preference_workflow <> Found: (Default)'
    self.assertTrue(message in detail_list, detail_list)
    self.assertTrue(detail_list.count(message), 1)

  def stepSetConstraintInPersonModulePortalType(self, sequence=None):
    types_tool = self.portal.portal_types
    portal_type = types_tool['Person Module']
    if 'PersonModulePostUpgraderConstraint' not in portal_type.getTypePropertySheetList():
      portal_type.setTypePropertySheetList(
        portal_type.getTypePropertySheetList() + ['PersonModulePostUpgraderConstraint',])

  def stepSetConstraintInTemplateToolPortalType(self, sequence=None):
    types_tool = self.portal.portal_types
    portal_type = types_tool['Template Tool']
    property_sheet_list = portal_type.getTypePropertySheetList()
    if 'TemplateToolUpgraderConstraint' not in property_sheet_list:
      portal_type.setTypePropertySheetList(
        portal_type.getTypePropertySheetList() + ['TemplateToolUpgraderConstraint',])
    if 'TemplateToolPostUpgradeConstraint' not in property_sheet_list:
      portal_type.setTypePropertySheetList(
        portal_type.getTypePropertySheetList() + ['TemplateToolPostUpgradeConstraint',])

  def stepSetDefaultWorkflowChainToPreference(self, sequence=None):
    workflow_chain_per_type_dict = {}
    for portal_type, workflow_chain_list in self.portal.ERP5Site_dumpWorkflowChainByPortalType().iteritems():
      workflow_chain_per_type_dict['chain_%s' % portal_type] = ",".join(workflow_chain_list)
    workflow_chain_per_type_dict['chain_Preference'] = '(Default)'
    self.portal.portal_workflow.manage_changeWorkflows(default_chain="",
      props=workflow_chain_per_type_dict)

  def _stepSolveAlarm(self, alarm_id):
    getattr(self.portal.portal_alarms, alarm_id).solve()

  def stepActiveSenseUpgradeAlarm(self, sequence=None):
    getattr(self.portal.portal_alarms, "upgrader_check_upgrader").activeSense()

  def stepActiveSensePostUpgradeAlarm(self, sequence=None):
    getattr(self.portal.portal_alarms,
      "upgrader_check_post_upgrade").activeSense()

  def stepActiveSensePreUpgradeAlarm(self, sequence=None):
    getattr(self.portal.portal_alarms,
      "upgrader_check_pre_upgrade").activeSense()

  def stepActiveSensePromiseCheckUpgrade(self, sequence=None):
    getattr(self.portal.portal_alarms,
      "promise_check_upgrade").activeSense()

  def stepRunFullUpgrader(self, sequence=None):
    self._stepSolveAlarm("promise_check_upgrade")

  def stepRunUpgrader(self, sequence=None):
    self._stepSolveAlarm("upgrader_check_upgrader")

  def stepRunPostUpgrade(self, sequence=None):
    self._stepSolveAlarm("upgrader_check_post_upgrade")

  def stepRunPreUpgrade(self, sequence=None):
    self._stepSolveAlarm("upgrader_check_pre_upgrade")

  def stepCheckUpgradeRequired(self, sequence=None):
    sense, detail_list = self._checkAlarmSense(
      alarm_id="upgrader_check_upgrader")
    self.assertTrue(sense, detail_list)

  def stepCheckUpgradeNotRequired(self, sequence=None):
    sense, detail_list = self._checkAlarmSense(
      alarm_id="upgrader_check_upgrader")
    self.assertFalse(sense, detail_list)

  def stepCheckPostUpgradeRequired(self, sequence=None):
    sense, detail_list = self._checkAlarmSense(
      alarm_id="upgrader_check_post_upgrade")
    self.assertTrue(sense, detail_list)

  def stepCheckFullUpgradeRequired(self, sequence=None):
    sense, detail_list = self._checkAlarmSense(
      alarm_id="promise_check_upgrade")
    self.assertTrue(sense, detail_list)

  def stepCheckPostUpgradeNotRequired(self, sequence=None):
    sense, detail_list = self._checkAlarmSense(
      alarm_id="upgrader_check_post_upgrade")
    self.assertFalse(sense, detail_list)

  def stepCheckPreUpgradeRequired(self, sequence=None):
    sense, detail_list = self._checkAlarmSense(
      alarm_id="upgrader_check_pre_upgrade")
    self.assertTrue(sense, detail_list)

  def stepCheckPreUpgradeNotRequired(self, sequence=None):
    sense, detail_list = self._checkAlarmSense(
      alarm_id="upgrader_check_pre_upgrade")
    self.assertFalse(sense, detail_list)

  def stepUninstallERP5Web(self, sequence=None):
    bt5 = self.portal.portal_templates.getInstalledBusinessTemplate('erp5_web')
    if bt5 is not None:
      bt5.uninstall()

  def stepCheckERP5WebBTInstalled(self, sequence=None):
    self.assertTrue('erp5_web' in \
      self.portal.portal_templates.getInstalledBusinessTemplateTitleList())

  def stepCheckNoActivitiesCreated(self, sequence=None):
    portal_activities = self.getActivityTool()
    self.assertEqual({'Alarm_runUpgrader', 'notify'},
      {x.method_id for x in portal_activities.getMessageList()})
    getTitleList = self.getTemplateTool().getInstalledBusinessTemplateTitleList
    self.assertNotIn('erp5_web', getTitleList())
    for message in portal_activities.getMessageList():
      portal_activities.manageInvoke(message.object_path, message.method_id)
    self.assertIn('erp5_web', getTitleList())
    self.commit()
    self.assertEqual({'immediateReindexObject', 'unindexObject'},
      {x.method_id for x in portal_activities.getMessageList()})

  def stepCreateSmallIncosistentData(self, sequence=None):
    for _ in range(4):
      self.portal.organisation_module.newContent(
        portal_type="Organisation",
        title="org_%s" % self.portal.organisation_module.getLastId())

  def stepUninstallERP5UpgraderTestBT(self, sequence=None):
    bt5 = self.portal.portal_templates.getInstalledBusinessTemplate('erp5_web')
    bt5.uninstall()

  def stepInstallERP5UpgraderTestBT(self, sequence=None):
    template_tool = self.portal.portal_templates
    if 'erp5_upgrader_test' not in template_tool.getInstalledBusinessTemplateTitleList():
      template_tool.installBusinessTemplateListFromRepository('erp5_upgrader_test')

  def _getTemplateToolLastTimestampIndexation(self):
    portal = self.portal
    return portal.portal_catalog(select_list=['indexation_timestamp'],
      uid=portal.portal_templates.getUid())[0].indexation_timestamp

  def stepCheckPersonNotInConstraintTypeListPerPortalType(self, sequence=None):
    constraint_type_per_type, _ = \
      self.portal.Base_getConstraintTypeListPerPortalType()
    self.assertFalse("Person" in constraint_type_per_type.keys(), \
      "Person in %s" % constraint_type_per_type.keys())

  def stepRemoveSameConstraintInPersonAndPersonModule(self, sequence=None):
    types_tool = self.portal.portal_types
    person_type = types_tool["Person"]
    constraint_id = "PersonModulePostUpgraderConstraint"
    propery_sheet_list = person_type.getTypePropertySheetList()
    if constraint_id in propery_sheet_list:
      propery_sheet_list.remove(constraint_id)      
      person_type.setTypePropertySheetList(propery_sheet_list)

    person_module_type = types_tool["Person Module"]
    propery_sheet_list = person_module_type.getTypePropertySheetList()
    if constraint_id in propery_sheet_list:
      propery_sheet_list.remove(constraint_id)
      person_module_type.setTypePropertySheetList(propery_sheet_list)

  def stepSameConstraintToPersonAndPersonModule(self, sequence=None):
    types_tool = self.portal.portal_types
    person_type = types_tool["Person"]
    constraint_id = "PersonModulePostUpgraderConstraint"
    propery_sheet_list = person_type.getTypePropertySheetList()
    if constraint_id not in propery_sheet_list:
      person_type.setTypePropertySheetList(
        [constraint_id,] + propery_sheet_list)

    person_module_type = types_tool["Person Module"]
    propery_sheet_list = person_module_type.getTypePropertySheetList()
    if constraint_id not in propery_sheet_list:
      person_module_type.setTypePropertySheetList(
        [constraint_id,] + propery_sheet_list)

    self.assertTrue(constraint_id in person_type.getTypePropertySheetList())
    self.assertTrue(
      constraint_id in person_module_type.getTypePropertySheetList())

  def stepCreateAndInstallBusinessTemplate(self, sequence=None):
    bt5 = self.portal.portal_templates.newContent(
      portal_type='Business Template',
      title=self.id())
    bt5.install()
    sequence.edit(bt5=bt5)

  def stepUninstallBusinessTemplateInstalled(self, sequence=None):
    sequence.get("bt5").uninstall()

  def stepCheckBusinessTemplateInstalled(self, sequence=None):
    self.assertTrue(sequence.get('bt5').getTitle() in \
      self.portal.portal_templates.getInstalledBusinessTemplateTitleList())

  def stepCheckConsistencyInTemplateTool(self, sequence=None):
    try:
      self.portal.portal_templates.checkConsistency()
    except BusinessTemplateUnknownError:
      self.fail("checkConsistency should not raise exception."
        "It means that one Business Template was not found in repositories")

  def stepCreateOrganisationWithActivity(self, sequence=None):
    self.portal.portal_categories.activity.newContent(portal_type="Category",
      id="education", title="Education")
    new_organisation = self.portal.organisation_module.newContent(
      portal_type="Organisation",
      title="Active Organisation",
      activity="education")
    self.tic()
    self.assertEqual(new_organisation.getCategoriesList(),
                     ['activity/education'])
    sequence.set('organisation', new_organisation)

  def stepCreateCustomUpgradeCategoryListForRenaming(self, sequence=None):
    portal = self.portal
    skin_folder = portal.portal_skins.custom
    script_id = "Base_getUpgradeCategoryNameList"
    skin_folder.manage_addProduct['PythonScripts'].manage_addPythonScript(script_id)
    custom_script = getattr(skin_folder, script_id)
    script_body = "return (('activity', 'business_core'),)"
    custom_script.ZPythonScript_edit('', script_body)

  def stepCreateCustomUpgradeCategoryListForMoving(self, sequence=None):
    portal = self.portal
    skin_folder = portal.portal_skins.custom
    script_id = "Base_getUpgradeCategoryNameList"
    skin_folder.manage_addProduct['PythonScripts'].manage_addPythonScript(script_id)
    custom_script = getattr(skin_folder, script_id)
    script_body = "return (('activity/education', 'activity/social/education'),)"
    custom_script.ZPythonScript_edit('', script_body)

  def stepRemoveCustomUpgradeCategoryList(self, sequence=None):
    custom_folder = self.portal.portal_skins.custom
    custom_folder.manage_delObjects("Base_getUpgradeCategoryNameList")

  def stepRenameCategoryActivityToBusinessCore(self, sequence=None):
    """Renames the category 'activity' to 'business_core'"""
    self.portal.portal_categories.activity.edit(
      id="business_core",
      title="Business Core")

  def stepChangeCategoryRelativeUrl(self, sequence=None):
    """Move the category 'activity/education' to 'activity/social/education'"""
    # To move the category we need to delete it, and recreate it
    # because this is what will happen when the bt containing the
    # category will be upgraded
    self.portal.portal_categories.activity.manage_delObjects('education')
    self.portal.portal_categories.activity.newContent(portal_type="Category",
      id="social", title="Social")
    self.portal.portal_categories.activity.social.newContent(
      portal_type="Category", id="education", title="Education")

  def stepUpdateOrganisationPropertySheetManually(self, sequence=None):
    """
    Changes the category property Activity of an Organisation to Business Core.
    This step is made manually in the step, but in a real case the old property
    sheet would be replaced by a new one saved in a business template to upgrade
    """
    activity = self.portal.portal_property_sheets.Organisation.activity_category
    activity.edit(id="business_core_category",
                  title= "business_core",
		  reference="business_core")

  def stepCheckOrganisationObjectUpdatedAfterCategoryRenaming(self, sequence=None):
    self.assertEqual(sequence.get('organisation').getCategoriesList(),
                     ['business_core/education'])

  def stepCheckOrganisationObjectUpdatedAfterCategoryMoving(self, sequence=None):
    self.assertEqual(sequence.get('organisation').getCategoriesList(),
                     ['activity/social/education'])

  def stepCheckPostUpgradeCategoryName(self, sequence=None):
    alarm = getattr(self.portal.portal_alarms, 'upgrader_check_post_upgrade')
    active_process = alarm.getLastActiveProcess()
    detail_list = active_process.getResultList()[0].detail
    message = 'Portal Type Organisation still contains the category activity'
    self.assertTrue(message in detail_list, detail_list)
    self.assertTrue(detail_list.count(message), 1)

  def test_workflow_chain_constraint(self):
    """ Check if Workflow chains is broken, it can be detected and fixed after
    upgrade"""
    sequence_list = SequenceList()
    sequence_string = """
      stepActiveSensePreUpgradeAlarm
      stepTic
      stepRunUpgrader
      stepTic
      stepCheckUpgradeNotRequired
      stepTic
      stepSetConstraintInTemplateToolPortalType
      stepActiveSensePostUpgradeAlarm
      stepTic
      stepCheckPostUpgradeEmptyConstraintList
      stepSetDefaultWorkflowChainToPreference
      stepActiveSensePostUpgradeAlarm
      stepTic
      stepCheckPosUpgradeWorkflowChainConsistency
      stepRunPostUpgrade
      stepTic
      stepActiveSensePostUpgradeAlarm
      stepTic
      stepCheckPostUpgradeEmptyConstraintList
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_not_post_many_active_result_when_upgrade(self):
    """ Check that is possible fix consistency before the upgrade"""
    sequence_list = SequenceList()
    sequence_string = """
      stepCreatePerson
      stepCreatePerson
      stepTic
      stepCreateScriptCheckPreUpgradeReferenceConsistency
      stepCreatePersonPropertySheet
      stepSetConstraintInPersonPortalType
      stepActiveSensePreUpgradeAlarm
      stepTic
      stepCheckPersonPreUpgradeConstraintList
      stepRunPreUpgrade
      stepTic
      stepCheckPersonPreUpgradeConstraintListAfterUpgrade
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_add_pre_upgrade_constraint(self):
    """ Check that is possible fix consistency before the upgrade"""
    sequence_list = SequenceList()
    sequence_string = """
      stepCreatePerson
      stepTic
      stepCreateScriptCheckPreUpgradeReferenceConsistency
      stepCreatePersonPropertySheet
      stepSetConstraintInPersonPortalType
      stepTic
      stepActiveSensePreUpgradeAlarm
      stepTic
      stepCheckPersonPreUpgradeConstraintList
      stepRemoveConstraintFromPersonPortalType
      stepActiveSensePreUpgradeAlarm
      stepTic
      stepCheckPreUpgradeEmptyConstraintList
      stepSetConstraintInPersonPortalType
      stepRunPreUpgrade
      stepTic
      stepCheckPersonPreUpgradeConstraintListAfterUpgrade
      stepActiveSensePreUpgradeAlarm
      stepTic
      stepCheckPreUpgradeEmptyConstraintList
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_can_run_post_upgrade_without_solve_upgrade(self):
    """Check that if there is something to solve in upgrade, it is still possible
    to run the post upgrade step directly."""
    sequence_list = SequenceList()
    sequence_string = """
      stepUninstallERP5Web
      stepSetConstraintInPersonModulePortalType
      stepTic
      stepCheckUpgradeRequired
      stepCheckPostUpgradeNotRequired
      stepCreatePerson
      stepValidatePerson
      stepTic
      stepCheckPostUpgradeRequired
      stepRunPostUpgrade
      stepTic
      stepCheckUpgradeRequired
      stepCheckPostUpgradeNotRequired
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_can_run_upgrade_without_solve_pre_upgrade(self):
    """Check that if there is something to solve in pre_upgrade is still possible
    run only the upgrade step directly (eventhough this does not really make sense)"""
    sequence_list = SequenceList()
    sequence_string = """
      stepCreatePerson
      stepCreateScriptCheckPreUpgradeReferenceConsistency
      stepCreatePersonPropertySheet
      stepSetConstraintInPersonPortalType
      stepUninstallERP5Web
      stepTic
      stepActiveSensePreUpgradeAlarm
      stepTic
      stepRunUpgrader
      stepTic
      stepCheckPreUpgradeRequired
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_upgrade_in_one_transaction(self):
    """Check that all constraints with contraint_type equal upgrade run in the 
    same transaction"""
    sequence_list = SequenceList()
    sequence_string = """
      stepCreatePropertySheetToValidateOrganisation
      stepUninstallERP5Web
      stepInstallERP5UpgraderTestBT
      stepTic
      stepActiveSensePromiseCheckUpgrade
      stepTic
      stepRunPreUpgrade
      stepTic
      stepSetConstraintInOrganisationPortalType
      stepCreateSmallIncosistentData
      stepTic
      stepActiveSenseUpgradeAlarm
      stepTic
      stepRunUpgrader
      stepCheckNoActivitiesCreated
      stepRemoveConstraintFromOrganisationPortalType
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_ignore_allowed_content_type(self):
    """
      Check that allowed content types should be ignored from a give \
      portal type in Base_getConstraintTypeListPerPortalType, \
      because checkConsistency is recursive in folders.
      Then, if not ignored this method will be called twice
    """
    sequence_list = SequenceList()
    sequence_string = """
      stepSameConstraintToPersonAndPersonModule
      stepCheckPersonNotInConstraintTypeListPerPortalType
      stepRemoveSameConstraintInPersonAndPersonModule
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_post_upgrade_with_bt5_that_not_exists_in_repository(self):
    """
      One Business Template installed that not exists in repository, 
      should not block checkConsistency in portal_templates
    """
    sequence_list = SequenceList()
    sequence_string = """
      stepCreateAndInstallBusinessTemplate
      stepTic
      stepCheckBusinessTemplateInstalled
      stepCheckConsistencyInTemplateTool
      stepUninstallBusinessTemplateInstalled
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_upgrade_instance(self):
    """Check that running the alarm the instance is upgraded completely"""
    sequence_list = SequenceList()
    sequence_string = """
      stepUninstallERP5Web
      stepInstallERP5UpgraderTestBT
      stepTic
      stepActiveSensePreUpgradeAlarm
      stepActiveSensePostUpgradeAlarm
      stepActiveSenseUpgradeAlarm
      stepTic
      stepCheckFullUpgradeRequired
      stepRunFullUpgrader
      stepTic
      stepCheckERP5WebBTInstalled
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_rename_category(self):
    """Check that the renaming category feature correctly updates objects"""
    sequence_list = SequenceList()
    sequence_string = """
      stepCreateOrganisationWithActivity
      stepCreateCustomUpgradeCategoryListForRenaming
      stepUpdateOrganisationPropertySheetManually
      stepTic
      stepActiveSensePreUpgradeAlarm
      stepActiveSensePostUpgradeAlarm
      stepTic
      stepRunUpgrader
      stepRenameCategoryActivityToBusinessCore
      stepTic
      stepRunPostUpgrade
      stepTic
      stepCheckOrganisationObjectUpdatedAfterCategoryRenaming
      stepRemoveCustomUpgradeCategoryList
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_move_category(self):
    """
    Check that changing the relative URL of a category
    correctly updates objects.
    For this test, we will move the category "activity/education"
    to "activity/social/education"
    """
    sequence_list = SequenceList()
    sequence_string = """
      stepCreateOrganisationWithActivity
      stepCreateCustomUpgradeCategoryListForMoving
      stepTic
      stepActiveSensePreUpgradeAlarm
      stepActiveSensePostUpgradeAlarm
      stepTic
      stepRunUpgrader
      stepChangeCategoryRelativeUrl
      stepTic
      stepRunPostUpgrade
      stepTic
      stepCheckOrganisationObjectUpdatedAfterCategoryMoving
      stepRemoveCustomUpgradeCategoryList
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)