workflow_tests: select correct button on create from formdata (#88473) #1309

Merged
vdeniaud merged 3 commits from wip/88473-workflow-tests-mauvais-bouton-se into main 2024-04-02 10:18:19 +02:00
2 changed files with 81 additions and 3 deletions

View File

@ -636,6 +636,12 @@ def test_workflow_tests_sms(pub):
testdef = TestDef.create_from_formdata(formdef, formdata)
testdef.agent_id = user.id
testdef.workflow_tests.actions = [
workflow_tests.AssertSMS(),
]
testdef.run(formdef)
testdef.workflow_tests.actions = [
workflow_tests.AssertSMS(phone_numbers=['0123456789'], body='Hello'),
]
@ -1108,6 +1114,9 @@ def test_workflow_tests_webservice_status_jump(pub):
def test_workflow_tests_create_from_formdata(pub, http_requests, freezer):
pub.cfg['sms'] = {'sender': 'xxx', 'passerelle_url': 'http://passerelle.invalid/'}
pub.write_cfg()
role = pub.role_class(name='test role')
role.store()
user = create_user(pub, is_admin=True)
@ -1200,6 +1209,7 @@ def test_workflow_tests_create_from_formdata(pub, http_requests, freezer):
assert formdata.status == 'wf-end-status'
testdef = TestDef.create_from_formdata(formdef, formdata, add_workflow_tests=True)
testdef.agent_id = user.id
testdef.run(formdef)
actions = testdef.workflow_tests.actions
@ -1234,3 +1244,70 @@ def test_workflow_tests_create_from_formdata(pub, http_requests, freezer):
assert actions[-1].key == 'assert-status'
assert actions[-1].status_name == 'End status'
def test_workflow_tests_create_from_formdata_multiple_buttons(pub, http_requests):
role = pub.role_class(name='test role')
role.store()
user = create_user(pub, is_admin=True)
user.roles = [role.id]
user.store()
workflow = Workflow(name='Workflow One')
new_status = workflow.add_status('New status', 'new-status')
middle_status = workflow.add_status('Middle status', 'middle-status')
end_status = workflow.add_status('End status', 'end-status')
choice = new_status.add_action('choice')
choice.label = 'Go to middle status'
choice.status = middle_status.id
choice.by = [role.id]
choice = middle_status.add_action('choice')
choice.label = 'Go to end status'
choice.status = end_status.id
choice.by = [role.id]
workflow.store()
formdef = FormDef()
formdef.name = 'test title'
formdef.workflow_id = workflow.id
formdef.store()
formdata = formdef.data_class()()
formdata.user_id = user.id
formdata.just_created()
formdata.store()
formdata.perform_workflow()
formdata.store()
app = login(get_app(pub))
resp = app.get(formdata.get_url())
resp = resp.form.submit('button1').follow()
resp = resp.form.submit('button1').follow()
formdata.refresh_from_storage()
assert formdata.status == 'wf-end-status'
testdef = TestDef.create_from_formdata(formdef, formdata, add_workflow_tests=True)
testdef.agent_id = user.id
testdef.run(formdef)
actions = testdef.workflow_tests.actions
assert len(actions) == 5
assert actions[0].key == 'assert-status'
assert actions[0].status_name == 'New status'
assert actions[1].key == 'button-click'
assert actions[1].button_name == 'Go to middle status'
assert actions[2].key == 'assert-status'
assert actions[2].status_name == 'Middle status'
assert actions[3].key == 'button-click'
assert actions[3].button_name == 'Go to end status'
assert actions[4].key == 'assert-status'
assert actions[4].status_name == 'End status'

View File

@ -140,6 +140,7 @@ class WorkflowTests(XmlStorableObject):
def add_action(self, action_class):
action = action_class(id=self.get_new_action_id())
action.parent = self
self.actions.append(action)
return action
@ -178,7 +179,7 @@ class WorkflowTests(XmlStorableObject):
if workflow_traces:
action = self.add_action(AssertStatus)
action.set_attributes_from_trace(formdata.formdef, workflow_traces[-1])
action.status_name = formdata.get_status().name
def export_actions_to_xml(self, element, attribute_name, **kwargs):
for action in self.actions:
@ -282,7 +283,7 @@ class ButtonClick(WorkflowTestAction):
button_name = [
x.label
for x in self.get_all_choice_actions(formdef)
if x.id == trace.event_args['action_item_id']
if x.id == trace.event_args['action_item_id'] and 'wf-%s' % x.parent.id == trace.status_id
][0]
except IndexError:
return
@ -777,7 +778,7 @@ class AssertSMS(WorkflowTestAction):
details = [_('SMS phone numbers: %s') % ', '.join(sms['phone_numbers'])]
raise WorkflowTestError(_('SMS was not sent to %s.') % recipient, details=details)
if self.body != sms['body']:
if self.body and self.body != sms['body']:
details = [_('SMS body: "%s"') % sms['body']]
raise WorkflowTestError(_('SMS body mismatch.'), details=details)