Commit 303bb9fc authored by iv's avatar iv Committed by iv

ERP5Workflow: improving testWorklist

parent a81d5b6c
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
class testWorkflowMixin(ERP5TypeTestCase): class testWorkflowMixin(ERP5TypeTestCase):
def getWorklistDocumentCountFromActionName(self, action_name): def countFromActionName(self, action_name):
# action_name look like: "Documents to validate (3)"
self.assertEqual(action_name[-1], ')') self.assertEqual(action_name[-1], ')')
left_parenthesis_offset = action_name.rfind('(') left_parenthesis_offset = action_name.rfind('(')
self.assertNotEquals(left_parenthesis_offset, -1) self.assertNotEquals(left_parenthesis_offset, -1)
return int(action_name[left_parenthesis_offset + 1:-1]) return int(action_name[left_parenthesis_offset + 1:-1])
def checkWorklist(self, action_list, name, count, url_parameter_dict=None, workflow_id=None): def checkWorklist(self, action_list, name, count, url_parameter_dict=None, workflow_id=None,
selection_name=None):
entry_list = [ entry_list = [
x for x in action_list if x['name'].startswith(name) x for x in action_list if x['name'].startswith(name)
and ( and (
...@@ -16,19 +18,22 @@ class testWorkflowMixin(ERP5TypeTestCase): ...@@ -16,19 +18,22 @@ class testWorkflowMixin(ERP5TypeTestCase):
and x['workflow_id'] == workflow_id and x['workflow_id'] == workflow_id
) )
] ]
# ensure there is a single entry in action list
self.assertEqual(len(entry_list), count and 1) self.assertEqual(len(entry_list), count and 1)
if count: if count:
self.assertEqual(count, self.assertEqual(count,
self.getWorklistDocumentCountFromActionName(entry_list[0]['name'])) self.countFromActionName(entry_list[0]['name']))
if entry_list and url_parameter_dict: if entry_list and url_parameter_dict:
url = entry_list[0].get('url') url = entry_list[0].get('url')
self.assertTrue(url, 'Can not check url parameters without url') self.assertTrue(url, 'Can not check url parameters without url')
url = '%s%s' % (self.portal.getId(), url[len(self.portal.absolute_url()):]) url = '%s%s' % (self.portal.getId(), url[len(self.portal.absolute_url()):])
# Touch URL to save worklist parameters in listbox selection # Touch URL to save worklist parameters in listbox selection
self.publish(url, 'manager:') # XXX: troubles running live test, returns HTTP error 500 publish_response = self.publish(url, 'manager:') # XXX: troubles running live test, returns HTTP error 500
self.assertEqual(publish_response.status, 200)
self.commit() self.commit()
selection_parameter_dict = self.portal.portal_selections.getSelectionParamsFor( selection_parameter_dict = self.portal.portal_selections.getSelectionParamsFor(
self.module_selection_name) selection_name)
for parameter, value in url_parameter_dict.iteritems(): for parameter, value in url_parameter_dict.iteritems():
self.assertIn(parameter, selection_parameter_dict) self.assertIn(parameter, selection_parameter_dict)
self.assertEqual(value, selection_parameter_dict[parameter]) self.assertEqual(value, selection_parameter_dict[parameter])
......
...@@ -343,14 +343,12 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -343,14 +343,12 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
portal = self.getPortalObject() portal = self.getPortalObject()
def getPortalTypeListForWorkflow(workflow_id): def getPortalTypeListForWorkflow(workflow_id):
workflow_tool = portal.portal_workflow portal_type_list = []
result = []
append = result.append
for type_info in portal.portal_types.objectValues(): for type_info in portal.portal_types.objectValues():
portal_type = type_info.id portal_type = type_info.id
if workflow_id in type_info.getTypeWorkflowList(): if workflow_id in type_info.getTypeWorkflowList():
append(portal_type) portal_type_list.append(portal_type)
return result return portal_type_list
_getPortalTypeListForWorkflow = CachingMethod(getPortalTypeListForWorkflow, _getPortalTypeListForWorkflow = CachingMethod(getPortalTypeListForWorkflow,
id='_getPortalTypeListForWorkflow', cache_factory = 'erp5_ui_long') id='_getPortalTypeListForWorkflow', cache_factory = 'erp5_ui_long')
......
...@@ -200,7 +200,7 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject): ...@@ -200,7 +200,7 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject):
matches_id = self.getMatchedCausalityState() matches_id = self.getMatchedCausalityState()
matches_ref_list.append(matches_id) matches_ref_list.append(matches_id)
matches = tuple(matches_ref_list) matches = tuple(matches_ref_list)
else: elif id:
# Local dynamic variable: # Local dynamic variable:
dynamic_varible = self._getOb('variable_'+id) dynamic_varible = self._getOb('variable_'+id)
if dynamic_varible.getInitialValue(): if dynamic_varible.getInitialValue():
......
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