Commit c9ee6406 authored by iv's avatar iv

ERP5Workflow: add test on permissions

parent c8d35a67
...@@ -214,6 +214,72 @@ class TestConvertedWorkflow(TestERP5WorkflowMixin): ...@@ -214,6 +214,72 @@ class TestConvertedWorkflow(TestERP5WorkflowMixin):
self.resetComponentTool() self.resetComponentTool()
self.login() self.login()
def test_permission(self):
"""
test permission/role mapping on states (ERP5 Workflow only)
# XXX(WORKFLOW) move this test to testERP5Workflow?
"""
portal_workflow = self.portal.portal_workflow
self.logMessage(" Save portal type original configuration")
text_portal_type = self.portal.portal_types._getOb('Text')
original_portal_type_workflow = text_portal_type.getTypeWorkflowList()
temporary_workflow_id = 'temporary_edit_workflow'
self.copyWorkflow(portal_workflow, 'edit_workflow',
temporary_workflow_id)
text_portal_type.setTypeWorkflowList(['temporary_edit_workflow'])
# some permission to be added in the test
permission = 'View management screens'
permission_key = '_' + permission.replace(' ', '_') + '_Permission'
self.logMessage(" Create a text document: it will have the usual permissions"
+ " defined by edit_workflow")
text_document = self.portal.document_module.newContent(portal_type='Text')
self.logMessage(" Verify that the permission '" + permission + "' is not " +
"declared on the text document yet")
self.assertFalse(getattr(text_document, permission_key, False))
workflow = portal_workflow._getOb(temporary_workflow_id)
if workflow.getPortalType() != 'Workflow':
self.logMessage(" Converting workflow " + temporary_workflow_id)
portal_workflow.WorkflowTool_convertWorkflow(
batch_mode=True,
workflow_id_list=[temporary_workflow_id]
)
self.tic()
workflow = portal_workflow._getOb(temporary_workflow_id)
self.assertEqual(workflow.getPortalType(), 'Workflow')
self.logMessage(" Changing permission list to: %s" % [permission])
workflow.setWorkflowManagedPermissionList([permission])
self.tic()
self.logMessage(" Verify permission roles dict on 'current' state")
permission_roles_dict = workflow.state_current\
.getStatePermissionRolesDict()
self.tic()
self.assertIn(permission, permission_roles_dict)
self.logMessage(" Change roles for '" + permission +
"' on state and update role list for permission ")
permission_roles_dict[permission] = ['Assignor']
workflow.updateRoleMappingsFor(text_document)
self.tic()
self.logMessage(" Check document permissions/roles mapping was updated")
self.assertEqual(getattr(text_document, permission_key), ['Assignor'])
self.logMessage(" Restore original configuration")
text_portal_type.setTypeWorkflowList(original_portal_type_workflow)
portal_workflow.manage_delObjects(temporary_workflow_id)
self.portal.document_module.manage_delObjects(text_document.getId())
class TestDCWorkflow(TestERP5WorkflowMixin): class TestDCWorkflow(TestERP5WorkflowMixin):
""" """
Check DC Workflow works correctly in new Workflow Tool. Check DC Workflow works correctly in new Workflow Tool.
......
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