workflow_tests: do not perform unconfigured action (#87824)

This commit is contained in:
Valentin Deniaud 2024-03-06 10:48:53 +01:00
parent 728afe97b6
commit 58df7bf7bb
2 changed files with 49 additions and 3 deletions

View File

@ -90,6 +90,42 @@ def test_workflow_tests_no_actions(pub):
mocked_run.assert_not_called()
def test_workflow_tests_action_not_configured(pub):
user = pub.user_class(name='test user')
user.store()
workflow = Workflow(name='Workflow One')
workflow.add_status(name='New status')
workflow.store()
formdef = FormDef()
formdef.name = 'test title'
formdef.workflow_id = workflow.id
formdef.store()
formdata = formdef.data_class()()
formdata.just_created()
testdef = TestDef.create_from_formdata(formdef, formdata)
testdef.agent_id = user.id
testdef.workflow_tests.actions = [
workflow_tests.ButtonClick(),
]
with mock.patch('wcs.workflow_tests.ButtonClick.perform') as mocked_perform:
testdef.run(formdef)
mocked_perform.assert_not_called()
testdef.workflow_tests.actions = [
workflow_tests.ButtonClick(button_name='xxx'),
]
with mock.patch('wcs.workflow_tests.ButtonClick.perform') as mocked_perform:
testdef.run(formdef)
mocked_perform.assert_called_once()
def test_workflow_tests_button_click(pub):
role = pub.role_class(name='test role')
role.store()

View File

@ -77,6 +77,9 @@ class WorkflowTests(XmlStorableObject):
for action in self.actions:
status = formdata.get_status()
if not action.is_configured:
continue
if not action.is_assertion:
formdata.sent_emails.clear()
formdata.used_webservice_responses.clear()
@ -162,10 +165,17 @@ class WorkflowTestAction(XmlStorableObject):
def __str__(self):
return str(self.label)
@property
def is_configured(self):
return not any(
field
for field, _ in self.XML_NODES
if field != 'id' and field not in self.optional_fields and not getattr(self, field)
)
def render_as_line(self):
for field, dummy in self.XML_NODES:
if field not in self.optional_fields and not getattr(self, field):
return _('not configured')
if not self.is_configured:
return _('not configured')
return self.details_label