Commit 1a3d26d1 authored by iv's avatar iv

ERP5Workflow: rename variables + call directly Base_viewDict script

instead of using self.publish()
parent 84a5644f
...@@ -61,51 +61,51 @@ class TestERP5Workflow(ERP5TypeTestCase): ...@@ -61,51 +61,51 @@ class TestERP5Workflow(ERP5TypeTestCase):
workflow.setReference('wf') workflow.setReference('wf')
# state variable # state variable
workflow.setStateVariable('current_state') workflow.setStateVariable('current_state')
s1 = workflow.newContent(portal_type='State', state1 = workflow.newContent(portal_type='State',
title='State 1') title='State 1')
s2 = workflow.newContent(portal_type='State', state2 = workflow.newContent(portal_type='State',
title='State 2') title='State 2')
s1.setReference('s1') state1.setReference('state1')
s2.setReference('s2') state2.setReference('state2')
t1 = workflow.newContent(portal_type='Transition', transition1 = workflow.newContent(portal_type='Transition',
title='Transition 1') title='Transition 1')
t1.setReference('t1') transition1.setReference('transition1')
s1.setDestinationValue(t1) state1.setDestinationValue(transition1)
t1.setDestinationValue(s2) transition1.setDestinationValue(state2)
# set initial state # set initial state
workflow.setSourceValue(s1) workflow.setSourceValue(state1)
# create a document and associate it to this workflow # create a document and associate it to this workflow
self.getPortalObject().portal_types._getOb('Folder')\ self.getPortalObject().portal_types._getOb('Folder')\
.edit(type_workflow_list=('wf')) .edit(type_workflow_list=('wf'))
doc = self.portal.newContent(portal_type='Folder', id='test_doc') doc = self.portal.newContent(portal_type='Folder', id='test_doc')
self.assertEqual('s1', workflow._getWorkflowStateOf(doc, id_only=1)) self.assertEqual('state1', workflow._getWorkflowStateOf(doc, id_only=1))
# pass a transition # pass a transition
workflow._executeTransition(doc, t1) workflow._executeTransition(doc, transition1)
self.assertEqual('s2', workflow._getWorkflowStateOf(doc, id_only=1)) self.assertEqual('state2', workflow._getWorkflowStateOf(doc, id_only=1))
def test_getAvailableTransitionList(self): def test_getAvailableTransitionList(self):
workflow = self.workflow_module.newContent(portal_type='Workflow') workflow = self.workflow_module.newContent(portal_type='Workflow')
workflow.setReference('wf') workflow.setReference('wf')
workflow.setStateVariable('current_state') workflow.setStateVariable('current_state')
s1 = workflow.newContent(portal_type='State', state1 = workflow.newContent(portal_type='State',
title='State 1') title='State 1')
s1.setReference('s1') state1.setReference('state1')
workflow.setSourceValue(s1) workflow.setSourceValue(state1)
t1 = workflow.newContent(portal_type='Transition', transition1 = workflow.newContent(portal_type='Transition',
title='Transition 1') title='Transition 1')
t1.setReference('t1') transition1.setReference('transition1')
t2 = workflow.newContent(portal_type='Transition', transition2 = workflow.newContent(portal_type='Transition',
title='Transition 2', title='Transition 2',
guard_expression='python: False') guard_expression='python: False')
t2.setReference('t2') transition2.setReference('transition2')
s1.setDestinationValueList([t1, t2]) state1.setDestinationValueList([transition1, transition2])
self.getPortalObject().portal_types._getOb('Folder')\ self.getPortalObject().portal_types._getOb('Folder')\
.edit(type_workflow_list=('wf')) .edit(type_workflow_list=('wf'))
doc = self.portal.newContent(portal_type='Folder', id='test_doc') doc = self.portal.newContent(portal_type='Folder', id='test_doc')
self.assertEqual([t1, t2], s1.getDestinationValueList()) self.assertEqual([transition1, transition2], state1.getDestinationValueList())
def test_WorkflowVariables(self): def test_WorkflowVariables(self):
...@@ -113,31 +113,31 @@ class TestERP5Workflow(ERP5TypeTestCase): ...@@ -113,31 +113,31 @@ class TestERP5Workflow(ERP5TypeTestCase):
portal_type='Workflow') portal_type='Workflow')
workflow.setReference('wf') workflow.setReference('wf')
workflow.setStateVariable('current_state') workflow.setStateVariable('current_state')
s1 = workflow.newContent(portal_type='State', state1 = workflow.newContent(portal_type='State',
title='State 1') title='State 1')
s1.setReference('s1') state1.setReference('state1')
workflow.setSourceValue(s1) workflow.setSourceValue(state1)
t1 = workflow.newContent(portal_type='Transition', transition1 = workflow.newContent(portal_type='Transition',
title='Transition 1', title='Transition 1',
destination_value=s1) destination_value=state1)
t1.setReference('t1') transition1.setReference('transition1')
s1.setDestinationValue(t1) state1.setDestinationValue(transition1)
v1 = workflow.newContent(portal_type='Workflow Variable', variable1 = workflow.newContent(portal_type='Workflow Variable',
title='actor') title='actor')
v1.setReference('actor') variable1.setReference('actor')
v1.variable_expression = 'user/getUserName' variable1.variable_expression = 'user/getUserName'
self.getPortalObject().portal_types._getOb('Folder')\ self.getPortalObject().portal_types._getOb('Folder')\
.edit(type_workflow_list=('wf')) .edit(type_workflow_list=('wf'))
doc = self.portal.newContent(portal_type='Folder', id='test_doc') doc = self.portal.newContent(portal_type='Folder', id='test_doc')
workflow._executeTransition(doc,t1) workflow._executeTransition(doc,transition1)
current_state = workflow.getCurrentStatusDict(doc) current_state = workflow.getCurrentStatusDict(doc)
self.assertTrue(isinstance(current_state, dict)) self.assertTrue(isinstance(current_state, dict))
self.assertEqual(s1.getReference(), current_state.get('current_state')) self.assertEqual(state1.getReference(), current_state.get('current_state'))
self.assertEqual('ERP5TypeTestCase', current_state.get('actor')) self.assertEqual('ERP5TypeTestCase', current_state.get('actor'))
history = doc.workflow_history['wf'] history = doc.workflow_history['wf']
self.assertEqual(len(history), 2)# create, t1 self.assertEqual(len(history), 2)# create, transition1
def test_afterScript(self): def test_afterScript(self):
...@@ -146,31 +146,32 @@ class TestERP5Workflow(ERP5TypeTestCase): ...@@ -146,31 +146,32 @@ class TestERP5Workflow(ERP5TypeTestCase):
state_base_category='current_state' state_base_category='current_state'
) )
workflow.setReference('wf') workflow.setReference('wf')
s1 = workflow.newContent(portal_type='State', state1 = workflow.newContent(portal_type='State',
title='State 1') title='State 1')
s2 = workflow.newContent(portal_type='State', state2 = workflow.newContent(portal_type='State',
title='State 2') title='State 2')
s1.setReference('s1') state1.setReference('state1')
s2.setReference('s2') state2.setReference('state2')
t1 = workflow.newContent(portal_type='Transition', title='Transition 1') transition1 = workflow.newContent(portal_type='Transition',
t1.setReference('t1') title='Transition 1')
s1.setDestinationValue(t1) transition1.setReference('transition1')
t1.setDestinationValue(s2) state1.setDestinationValue(transition1)
workflow.setSourceValue(s1) transition1.setDestinationValue(state2)
workflow.setSourceValue(state1)
script = workflow.newContent(portal_type='Workflow Script', script = workflow.newContent(portal_type='Workflow Script',
id='Document_testAfterScript') id='Document_testAfterScript')
script.setParameterSignature("state_change") script.setParameterSignature("state_change")
script.setParameterSignature("state_change") script.setParameterSignature("state_change")
script.setBody("state_change['object'].setDescription('After script was " + script.setBody("state_change['object'].setDescription('After script was " +
"executed.')") "executed.')")
t1.setCategoryList(t1.getCategoryList() + transition1.setCategoryList(transition1.getCategoryList() +
['after_script/' + script.getRelativeUrl()]) ['after_script/' + script.getRelativeUrl()])
self.getPortalObject().portal_types._getOb('Folder')\ self.getPortalObject().portal_types._getOb('Folder')\
.edit(type_workflow_list=('wf')) .edit(type_workflow_list=('wf'))
doc = self.portal.newContent(portal_type='Folder', id='test_doc') doc = self.portal.newContent(portal_type='Folder', id='test_doc')
workflow._executeTransition(doc, t1) workflow._executeTransition(doc, transition1)
self.assertEqual('After script was executed.', doc.getDescription()) self.assertEqual('After script was executed.', doc.getDescription())
# FIXME: not passing parameter to an after script is probably too # FIXME: not passing parameter to an after script is probably too
# restrictive # restrictive
...@@ -179,27 +180,27 @@ class TestERP5Workflow(ERP5TypeTestCase): ...@@ -179,27 +180,27 @@ class TestERP5Workflow(ERP5TypeTestCase):
workflow = self.workflow_module.newContent(portal_type='Workflow') workflow = self.workflow_module.newContent(portal_type='Workflow')
workflow.setReference('wf') workflow.setReference('wf')
workflow.setStateVariable('current_state') workflow.setStateVariable('current_state')
s1 = workflow.newContent(portal_type='State', title='State 1') state1 = workflow.newContent(portal_type='State', title='State 1')
s2 = workflow.newContent(portal_type='State', title='State 2') state2 = workflow.newContent(portal_type='State', title='State 2')
s1.setReference('s1') state1.setReference('state1')
s2.setReference('s2') state2.setReference('state2')
t1 = workflow.newContent(portal_type='Transition', title='Transition 1') transition1 = workflow.newContent(portal_type='Transition', title='Transition 1')
t1.setReference('t1') transition1.setReference('transition1')
s1.setDestinationValue(t1) state1.setDestinationValue(transition1)
t1.setDestinationValue(s2) transition1.setDestinationValue(state2)
workflow.setSourceValue(s1) workflow.setSourceValue(state1)
script = workflow.newContent(portal_type='Workflow Script', script = workflow.newContent(portal_type='Workflow Script',
id='Document_testBeforeScript') id='Document_testBeforeScript')
script.setParameterSignature("state_change") script.setParameterSignature("state_change")
script.setBody("state_change['object'].setDescription('Before script was " + script.setBody("state_change['object'].setDescription('Before script was " +
"executed.')") "executed.')")
t1.setCategoryList(t1.getCategoryList() + transition1.setCategoryList(transition1.getCategoryList() +
['before_script/' + script.getRelativeUrl()]) ['before_script/' + script.getRelativeUrl()])
self.getPortalObject().portal_types._getOb('Folder')\ self.getPortalObject().portal_types._getOb('Folder')\
.edit(type_workflow_list=('wf')) .edit(type_workflow_list=('wf'))
doc = self.portal.newContent(portal_type='Folder', id='test_doc') doc = self.portal.newContent(portal_type='Folder', id='test_doc')
workflow._executeTransition(doc, t1) workflow._executeTransition(doc, transition1)
self.assertEqual('Before script was executed.', doc.getDescription()) self.assertEqual('Before script was executed.', doc.getDescription())
# FIXME: not passing parameter to an before script is probably too # FIXME: not passing parameter to an before script is probably too
# restrictive # restrictive
...@@ -242,10 +243,7 @@ class TestERP5Workflow(ERP5TypeTestCase): ...@@ -242,10 +243,7 @@ class TestERP5Workflow(ERP5TypeTestCase):
transition.setReference('change_something') transition.setReference('change_something')
transition.setGuardRoleList(['Assignee', 'Assignor']) transition.setGuardRoleList(['Assignee', 'Assignor'])
transition.setCategoryList('destination/' + transition.getPath()) transition.setCategoryList('destination/' + transition.getPath())
http_response = self.publish(transition.getPath() + '/Base_viewDict', transition.Base_viewDict()
basic='ERP5TypeTestCase:',)
self.assertEqual(http_response.status, 200)
def test_WorkflowSecurity(self): def test_WorkflowSecurity(self):
""" """
......
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