[Erp5-report] r31645 leonardo - /erp5/trunk/products/ERP5/tests/

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Jan 7 17:11:14 CET 2010


Author: leonardo
Date: Thu Jan  7 17:11:11 2010
New Revision: 31645

URL: http://svn.erp5.org?rev=31645&view=rev
Log:
Simplify workflow creation in tests (fix testBase for Zope 2.12 in the process)

Modified:
    erp5/trunk/products/ERP5/tests/testBase.py
    erp5/trunk/products/ERP5/tests/testBusinessTemplate.py
    erp5/trunk/products/ERP5/tests/testInteractionWorkflow.py

Modified: erp5/trunk/products/ERP5/tests/testBase.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testBase.py?rev=31645&r1=31644&r2=31645&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testBase.py [utf8] (original)
+++ erp5/trunk/products/ERP5/tests/testBase.py [utf8] Thu Jan  7 17:11:11 2010
@@ -40,6 +40,7 @@
 from zExceptions import BadRequest
 from Products.ERP5Type.tests.backportUnittest import skip
 from Products.ERP5Type.Tool.ClassTool import _aq_reset
+from Products.ERP5Type.Workflow import addWorkflowByType
 
 class TestBase(ERP5TypeTestCase, ZopeTestCase.Functional):
 
@@ -927,8 +928,7 @@
     # Add a non-existent workflow.
     pw = self.getWorkflowTool()
     dummy_worlflow_id = 'never_existent_workflow'
-    pw.manage_addWorkflow('dc_workflow (Web-configurable workflow)',
-                          dummy_worlflow_id)
+    addWorkflowByType(pw, 'erp5_workflow', dummy_worlflow_id)
     cbt = pw._chains_by_type
     props = {}
     for id, wf_ids in cbt.iteritems():
@@ -974,10 +974,8 @@
     dummy_simulation_worlflow_id = 'fake_simulation_workflow'
     dummy_validation_worlflow_id = 'fake_validation_workflow'
     #Assume that erp5_styles workflow Manage permissions with acquired Role by default
-    pw.manage_addWorkflow('erp5_workflow (ERP5-style empty workflow)',
-                          dummy_simulation_worlflow_id)
-    pw.manage_addWorkflow('erp5_workflow (ERP5-style empty workflow)',
-                          dummy_validation_worlflow_id)
+    addWorkflowByType(pw, 'erp5_workflow', dummy_simulation_worlflow_id)
+    addWorkflowByType(pw, 'erp5_workflow', dummy_validation_worlflow_id)
     dummy_simulation_worlflow = pw[dummy_simulation_worlflow_id]
     dummy_validation_worlflow = pw[dummy_validation_worlflow_id]
     dummy_validation_worlflow.variables.setStateVar('validation_state')

Modified: erp5/trunk/products/ERP5/tests/testBusinessTemplate.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testBusinessTemplate.py?rev=31645&r1=31644&r2=31645&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testBusinessTemplate.py [utf8] (original)
+++ erp5/trunk/products/ERP5/tests/testBusinessTemplate.py [utf8] Thu Jan  7 17:11:11 2010
@@ -42,24 +42,14 @@
 from Products.ERP5Type.Globals import PersistentMapping
 from Products.CMFCore.Expression import Expression
 from Products.ERP5Type.tests.utils import LogInterceptor
+from Products.ERP5Type.Workflow import addWorkflowByType
 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)' 
+WORKFLOW_TYPE = 'erp5_workflow' 
 
 class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
   """
@@ -106,21 +96,10 @@
       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."""
+    """Remove objects created in 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 = {}
@@ -1146,9 +1125,10 @@
     """
     Create a workflow
     """
+    wf_id = 'geek_workflow'
     pw = self.getWorkflowTool()
-    pw.manage_addWorkflow(WORKFLOW_TYPE, 'geek_workflow')
-    workflow = pw._getOb('geek_workflow', None)
+    addWorkflowByType(pw, WORKFLOW_TYPE, wf_id)
+    workflow = pw._getOb(wf_id, None)
     self.failUnless(workflow is not None)
     sequence.edit(workflow_id=workflow.getId())
     cbt = pw._chains_by_type
@@ -1156,7 +1136,7 @@
     if cbt is not None:
       for id, wf_ids in cbt.items():
         props['chain_%s' % id] = ','.join(wf_ids)
-    props['chain_Geek Object'] = 'geek_workflow'
+    props['chain_Geek Object'] = wf_id
     pw.manage_changeWorkflows('', props=props)
 
   def stepCheckWorkflowChainRemoved(self, sequence=None, sequence_list=None, **kw):
@@ -4939,9 +4919,10 @@
     """
     Create a custom workflow
     """
+    wf_id = 'custom_geek_workflow'
     pw = self.getWorkflowTool()
-    pw.manage_addWorkflow(WORKFLOW_TYPE, 'custom_geek_workflow')
-    workflow = pw._getOb('custom_geek_workflow', None)
+    addWorkflowByType(pw, WORKFLOW_TYPE, wf_id)
+    workflow = pw._getOb(wf_id, None)
     self.failUnless(workflow is not None)
     sequence.edit(workflow_id=workflow.getId())
     cbt = pw._chains_by_type
@@ -4951,9 +4932,9 @@
         props['chain_%s' % id] = ','.join(wf_ids)
     key = 'chain_Geek Object'
     if props.has_key(key):
-      props[key] = '%s,custom_geek_workflow' % props[key]
+      props[key] = '%s,%s' % (props[key], wf_id)
     else:
-      props['chain_Geek Object'] = 'custom_geek_workflow'
+      props[key] = wf_id
     pw.manage_changeWorkflows('', props=props)
 
   def stepCreateCustomBusinessTemplate(self, sequence=None,

Modified: erp5/trunk/products/ERP5/tests/testInteractionWorkflow.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testInteractionWorkflow.py?rev=31645&r1=31644&r2=31645&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testInteractionWorkflow.py [utf8] (original)
+++ erp5/trunk/products/ERP5/tests/testInteractionWorkflow.py [utf8] Thu Jan  7 17:11:11 2010
@@ -35,6 +35,7 @@
 from AccessControl import ClassSecurityInfo
 from AccessControl.SecurityManagement import newSecurityManager
 import Products.ERP5Type
+from Products.ERP5Type.Workflow import addWorkflowByType
 
 class TestInteractionWorkflow(ERP5TypeTestCase):
 
@@ -83,20 +84,11 @@
 
   def _createInteractionWorkflowWithId(self, wf_id):
     wf_tool = self.getWorkflowTool()
-    # BACKWARD: CMF 1.8. Remove when we move to CMF 2.2
-    manage_addWorkflow = getattr(wf_tool, 'manage_addWorkflow', None)
-    if manage_addWorkflow is not None:
-      wf_type = "interaction_workflow (Web-configurable interaction workflow)"
-      manage_addWorkflow(workflow_type=wf_type, id=wf_id)
-      return wf_tool[wf_id]
-    else:
-      # On CMF 2.2, only this part should remain
-      dispatcher = wf_tool.manage_addProduct['ERP5Type']
-      return dispatcher.addWorkflow_interaction_workflow(wf_id)
+    return addWorkflowByType(wf_tool, "interaction_workflow", wf_id)
 
   def createInteractionWorkflow(self):
     id = 'test_workflow'
-    wf_type = "interaction_workflow (Web-configurable interaction workflow)"
+    wf_type = "interaction_workflow"
     if getattr(self.getWorkflowTool(), id, None) is None:
       self._createInteractionWorkflowWithId(id)
     wf = self.getWorkflowTool()[id]




More information about the Erp5-report mailing list