[CMF-checkins] SVN: CMF/branches/1.6/DCWorkflow/ Merged r41365 from trunk:

Florent Guillaume fg at nuxeo.com
Thu Jan 19 11:23:13 EST 2006


Log message for revision 41366:
  Merged r41365 from trunk:
  Fixed to allow a workflow to be imported twice from an extension
  profile. This should really use the import context's shouldPurge()
  method but that would be a much bigger refactoring.
  

Changed:
  U   CMF/branches/1.6/DCWorkflow/exportimport.py
  U   CMF/branches/1.6/DCWorkflow/tests/test_exportimport.py

-=-
Modified: CMF/branches/1.6/DCWorkflow/exportimport.py
===================================================================
--- CMF/branches/1.6/DCWorkflow/exportimport.py	2006-01-19 16:21:40 UTC (rev 41365)
+++ CMF/branches/1.6/DCWorkflow/exportimport.py	2006-01-19 16:23:13 UTC (rev 41366)
@@ -970,8 +970,9 @@
     for v_info in variables:
 
         id = str( v_info[ 'variable_id' ] ) # no unicode!
-        v = VariableDefinition( id )
-        workflow.variables._setObject( id, v )
+        if not workflow.variables.has_key(id):
+            v = VariableDefinition(id)
+            workflow.variables._setObject(id, v)
         v = workflow.variables._getOb( id )
 
         guard = v_info[ 'guard' ]
@@ -1005,8 +1006,9 @@
     for s_info in states:
 
         id = str( s_info[ 'state_id' ] ) # no unicode!
-        s = StateDefinition( id )
-        workflow.states._setObject( id, s )
+        if not workflow.states.has_key(id):
+            s = StateDefinition(id)
+            workflow.states._setObject(id, s)
         s = workflow.states._getOb( id )
 
         s.setProperties( title = s_info[ 'title' ]
@@ -1042,8 +1044,9 @@
     for t_info in transitions:
 
         id = str( t_info[ 'transition_id' ] ) # no unicode!
-        t = TransitionDefinition( id )
-        workflow.transitions._setObject( id, t )
+        if not workflow.transitions.has_key(id):
+            t = TransitionDefinition(id)
+            workflow.transitions._setObject(id, t)
         t = workflow.transitions._getOb( id )
 
         trigger_type = list( TRIGGER_TYPES ).index( t_info[ 'trigger' ] )
@@ -1081,9 +1084,9 @@
     for w_info in worklists:
 
         id = str( w_info[ 'worklist_id' ] ) # no unicode!
-        w = WorklistDefinition( id )
-        workflow.worklists._setObject( id, w )
-
+        if not workflow.worklists.has_key(id):
+            w = WorklistDefinition(id)
+            workflow.worklists._setObject(id, w)
         w = workflow.worklists._getOb( id )
 
         action = w_info[ 'action' ]
@@ -1134,6 +1137,8 @@
         elif meta_type == DTMLMethod.meta_type:
             script = DTMLMethod( file, __name__=id )
 
+        if workflow.scripts.has_key(id):
+            workflow.scripts._delObject(id)
         workflow.scripts._setObject( id, script )
 
 #

Modified: CMF/branches/1.6/DCWorkflow/tests/test_exportimport.py
===================================================================
--- CMF/branches/1.6/DCWorkflow/tests/test_exportimport.py	2006-01-19 16:21:40 UTC (rev 41365)
+++ CMF/branches/1.6/DCWorkflow/tests/test_exportimport.py	2006-01-19 16:23:13 UTC (rev 41366)
@@ -1877,11 +1877,20 @@
     def _importNormalWorkflow( self, wf_id, wf_title, wf_initial_state ):
         from Products.CMFCore.exportimport.workflow import importWorkflowTool
 
-        site = self._initSite()
-        wf_tool = site.portal_workflow
+        site, context = self._prepareImportNormalWorkflow(
+            wf_id, wf_title, wf_initial_state)
+
+        importWorkflowTool(context)
+
+        return site.portal_workflow
+
+    def _prepareImportNormalWorkflow(self, wf_id, wf_title, wf_initial_state,
+                                     site=None, purge=True):
+        if site is None:
+            site = self._initSite()
         workflow_filename = wf_id.replace(' ', '_')
 
-        context = DummyImportContext( site )
+        context = DummyImportContext(site, purge=purge)
         context._files[ 'workflows.xml'
                       ] = (_NORMAL_TOOL_EXPORT_WITH_FILENAME
                             % { 'workflow_id' : wf_id
@@ -1906,9 +1915,8 @@
         context._files[ 'workflows/%s/scripts/before_open.py' % workflow_filename
                       ] = _BEFORE_OPEN_SCRIPT
 
-        importWorkflowTool( context )
+        return site, context
 
-        return wf_tool
 
     def _importOldWorkflow( self, wf_id, wf_title, wf_initial_state ):
         from Products.CMFCore.exportimport.workflow import importWorkflowTool
@@ -2062,6 +2070,43 @@
                         , ( WF_ID_NON % 3, )
                         )
 
+    def test_import_twice_nopurge(self):
+        from Products.CMFCore.exportimport.workflow import importWorkflowTool
+
+        WF_ID = 'dcworkflow_purge'
+        WF_TITLE = 'DC Workflow testing purge'
+        WF_INITIAL_STATE = 'closed'
+
+        # Import a first time
+        site, context = self._prepareImportNormalWorkflow(
+            WF_ID, WF_TITLE, WF_INITIAL_STATE)
+        importWorkflowTool(context)
+
+        # Now reimport without purge
+        site, context = self._prepareImportNormalWorkflow(
+            WF_ID, WF_TITLE, WF_INITIAL_STATE, site=site, purge=False)
+        importWorkflowTool(context)
+        workflow = site.portal_workflow.objectValues()[1]
+
+        self.assertEqual(workflow.getId(), WF_ID)
+        self.assertEqual(workflow.meta_type, DCWorkflowDefinition.meta_type)
+        self.assertEqual(workflow.title, WF_TITLE)
+        self.assertEqual(workflow.state_var, 'state')
+        self.assertEqual(workflow.initial_state, WF_INITIAL_STATE)
+        self.assertEqual(len(workflow.variables.objectItems()),
+                         len(_WF_VARIABLES))
+        self.assertEqual(len(workflow.states.objectItems()),
+                         len(_WF_STATES))
+        self.assertEqual(len(workflow.transitions.objectItems()),
+                         len(_WF_TRANSITIONS))
+        self.assertEqual(len(workflow.permissions),
+                         len(_WF_PERMISSIONS))
+        self.assertEqual(len(workflow.scripts.objectItems()),
+                         len(_WF_SCRIPTS))
+        self.assertEqual(len(workflow.worklists.objectItems()),
+                         len(_WF_WORKLISTS))
+
+
     def test_from_empty_dcworkflow_top_level( self ):
 
         WF_ID = 'dcworkflow_tool'



More information about the CMF-checkins mailing list