From a78af4eab81b19d1f05baa79bb709a948a2194d2 Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Wed, 4 Nov 2020 14:37:53 -0500 Subject: [PATCH] Run cancel task during interrupt. Currently this uses Signal event. We may change this to the Cancel event. --- crc/api/workflow.py | 3 + tests/data/message_event/message_event.bpmn | 122 ++++++++++++++++++++ tests/test_message_event.py | 34 ++++++ 3 files changed, 159 insertions(+) create mode 100644 tests/data/message_event/message_event.bpmn create mode 100644 tests/test_message_event.py diff --git a/crc/api/workflow.py b/crc/api/workflow.py index 223f280f..74741cb6 100644 --- a/crc/api/workflow.py +++ b/crc/api/workflow.py @@ -147,6 +147,9 @@ def set_current_task(workflow_id, task_id): raise ApiError("invalid_state", "You may not move the token to a task who's state is not " "currently set to COMPLETE or READY.") + # If we have an interrupt task, run it. + processor.bpmn_workflow.signal(message_name='token_reset') + # Only reset the token if the task doesn't already have it. if spiff_task.state == spiff_task.COMPLETED: spiff_task.reset_token(reset_data=True) # Don't try to copy the existing data back into this task. diff --git a/tests/data/message_event/message_event.bpmn b/tests/data/message_event/message_event.bpmn new file mode 100644 index 00000000..ab44b8fc --- /dev/null +++ b/tests/data/message_event/message_event.bpmn @@ -0,0 +1,122 @@ + + + + + Flow_0xym55y + + + + Flow_16q1uec + update_study("title:'my_string'") + + + + + + + + Flow_1rvh899 + Flow_1n1fs6z + + + Flow_07i0gvv + Flow_1c2tudh + [print(formdata) for _ in range(how_many)] +printdata = formdata + + + Flow_1c2tudh + + + + + + Flow_0xym55y + Flow_1rvh899 + print('Hello'); printdata=''; test_message='' + + + + + + + + + Flow_1n1fs6z + Flow_07i0gvv + + + + Flow_16q1uec + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/test_message_event.py b/tests/test_message_event.py new file mode 100644 index 00000000..40188529 --- /dev/null +++ b/tests/test_message_event.py @@ -0,0 +1,34 @@ +from tests.base_test import BaseTest +from crc.models.study import StudyModel +from crc import db + + +class TestMessageEvent(BaseTest): + + def test_message_event(self): + + workflow = self.create_workflow('message_event') + study_id = workflow.study_id + + # Start the workflow. + first_task = self.get_workflow_api(workflow).next_task + self.assertEqual('Activity_GetData', first_task.name) + workflow = self.get_workflow_api(workflow) + self.complete_form(workflow, first_task, {'formdata': 'asdf'}) + workflow = self.get_workflow_api(workflow) + self.assertEqual('Activity_HowMany', workflow.next_task.name) + + # reset the workflow + # this ultimately calls crc.api.workflow.set_current_task + self.app.put('/v1.0/workflow/%i/task/%s/set_token' % ( + workflow.id, + first_task.id), + headers=self.logged_in_headers(), + content_type="application/json") + + # set_current_task should call the interupt (signal) task + # which should run the script in our task + # + # test to see if our changes made it to the DB + study_result = db.session.query(StudyModel).filter(StudyModel.id==study_id).first() + self.assertEqual(study_result.title, 'my_string')