workflow_tests: select correct button on create from formdata (#88473)
gitea/wcs/pipeline/head This commit looks good
Details
gitea/wcs/pipeline/head This commit looks good
Details
This commit is contained in:
parent
95b63ddaff
commit
5c58bac4f1
|
@ -1244,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'
|
||||
|
|
|
@ -179,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:
|
||||
|
@ -283,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
|
||||
|
|
Loading…
Reference in New Issue