Commit 08f88c59 authored by Jérome Perrin's avatar Jérome Perrin

SecurityTestCase: update assertion failure message for new workflow API

This test case tries to provide message helpful for debugging in case
of assertion failure for assertUserCanPassWorkflowTransition, but
this was not correctly using new workflow API and in case of failure
there was an error like this:

  File ".../custom/test.py"
    self.assertUserCanPassWorkflowTransition(user, 'stop_action', packing_list)
  File "product/ERP5Type/tests/SecurityTestCase.py", line 237, in failUnlessUserCanPassWorkflowTransition
    if wf_transition.trigger_type == TRIGGER_USER_ACTION:
AttributeError: 'NoneType' object has no attribute 'trigger_type'

The previous implementation was using getGuardSummary, which no
longer exist in new workflow, so we implement similar logic here.

The new message changes a bit, it now look like this:

    AssertionError: User X can NOT pass stop_action transition on Internal Packing List at /erp5/internal_packing_list_module/20220218-22A38 (draft on delivery_causality_workflow, draft on internal_packing_list_notification_workflow, started on packing_list_workflow).
     Roles: [Owner, Member, Authenticated, Associate]
     Available transitions:
              deliver_action[packing_list_workflow]
                    Expression:
                    Permissions:
                    Groups:
            * stop_action[packing_list_workflow]
                    Expression: python: not(state_change['object'].getPortalType() == "Sale Packing List" and state_change['object'].getSimulationState() == "confirmed")
                    Permissions:
                    Groups:
parent eacea55f
......@@ -40,16 +40,6 @@ from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type import Permissions
from Products.ERP5.InteractionWorkflow import InteractionWorkflowDefinition
from Products.DCWorkflow import Guard
def formatNameUnion(names):
names = list(names)
if len(names) == 2:
return ' or '.join(names)
elif len(names) > 2:
names[-1] = ' or ' + names[-1]
return '; '.join(names)
Guard.formatNameUnion = formatNameUnion
from Products.ERP5Type.Base import Base
from typing import Callable
......@@ -231,15 +221,18 @@ class SecurityTestCase(ERP5TypeTestCase):
continue
if wf.__class__.__name__ in ['InteractionWorkflowDefinition', 'Interaction Workflow'] :
continue
for wf_transition_id in wf._getWorkflowStateOf(
document).getTransitions():
wf_transition = wf.getTransitionValueByReference(wf_transition_id)
if wf_transition.trigger_type == TRIGGER_USER_ACTION:
for wf_transition in wf._getWorkflowStateOf(document).getDestinationValueList():
if wf_transition.getTriggerType() == TRIGGER_USER_ACTION:
workflow_transitions_description.append(
"%s%s[%s]: %s" % (
wf_transition_id == transition and "* " or " ",
wf_transition_id, wf.getId(),
wf_transition.getGuardSummary()))
"%s%s[%s]\n\t\tExpression: %s\n\t\tPermissions: %s\n\t\tGroups: %s" % (
wf_transition.getReference() == transition and "* " or " ",
wf_transition.getReference(),
wf.getId(),
wf_transition.getGuardExpression() or '',
', '.join(wf_transition.getGuardPermissionList()),
', '.join(wf_transition.getGuardGroupList()),
)
)
workflow_states_description.append("%s on %s" % (
wf._getWorkflowStateOf(document, id_only=1), wf.getId()))
......
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