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