diff --git a/product/ERP5/tests/testBusinessTemplate.py b/product/ERP5/tests/testBusinessTemplate.py index d91bca6534f6b01349259e9a1d72760479b10f0c..59898010e707ea8a5ee0fbcd4877fc3435a46698 100644 --- a/product/ERP5/tests/testBusinessTemplate.py +++ b/product/ERP5/tests/testBusinessTemplate.py @@ -44,6 +44,22 @@ from Products.CMFCore.tests.base.testcase import LogInterceptor import shutil import os +from MethodObject import Method +from Persistence import Persistent + +class Fake_manage_addWorkflow(Method, Persistent): + + isFake = True # flag to allow removal of this method. + + def __call__(self, context, workflow_type, workflow_id): + workflow_factory_id, _workflow_type_title = workflow_type.split(' ', 1) + dispatcher = context.manage_addProduct['ERP5Type'] + factory = getattr(dispatcher, + 'addWorkflow_' + workflow_factory_id) + return factory(workflow_id) + +WORKFLOW_TYPE = 'erp5_workflow (ERP5-style empty workflow)' + class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor): """ Test these operations: @@ -88,10 +104,23 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor): 'any' in content_type_registry.predicate_ids): content_type_registry.removePredicate('any') transaction.commit() + pw = self.getWorkflowTool() + if getattr(pw, 'manage_addWorkflow', None) is None: + # CMF 2.2 no longer has manage_addWorkflow, and workflows should be added + # using manage_addProduct['ERP5Type'].manage_addWorkflow_<factory-id>, + # but this doesn't work on CMF 1.5 + # BACK: stop using this hack when we drop Zope 2.8, CMF 2.2 + pw.manage_addWorkflow = Fake_manage_addWorkflow() def beforeTearDown(self): """Remove objects created tests.""" pw = self.getWorkflowTool() + if getattr(aq_base(pw.manage_addWorkflow), + 'isFake', False): + # remove fake method which was added to make tests compatible with CMF 2.2 + # BACK: remove this hack when we've abandoned Zope 2.8 + del pw.manage_addWorkflow + cbt = pw._chains_by_type props = {} if cbt is not None: @@ -1099,7 +1128,7 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor): Create a workflow """ pw = self.getWorkflowTool() - pw.manage_addWorkflow('dc_workflow (Web-configurable workflow)', 'geek_workflow') + pw.manage_addWorkflow(WORKFLOW_TYPE, 'geek_workflow') workflow = pw._getOb('geek_workflow', None) self.failUnless(workflow is not None) sequence.edit(workflow_id=workflow.getId()) @@ -4763,8 +4792,7 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor): Create a custom workflow """ pw = self.getWorkflowTool() - pw.manage_addWorkflow('dc_workflow (Web-configurable workflow)', - 'custom_geek_workflow') + pw.manage_addWorkflow(WORKFLOW_TYPE, 'custom_geek_workflow') workflow = pw._getOb('custom_geek_workflow', None) self.failUnless(workflow is not None) sequence.edit(workflow_id=workflow.getId())