From a3d7ba8114706ef601d611b744c7cad46a1c5402 Mon Sep 17 00:00:00 2001 From: Dan Funk Date: Tue, 7 Jan 2020 13:23:46 -0500 Subject: [PATCH] WIP --- crc/api.yml | 43 +++++++++++++++---------------------------- crc/api/workflow.py | 5 +++-- tests/test_api.py | 15 ++++++++++++++- 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/crc/api.yml b/crc/api.yml index fde49ff8..43b75840 100644 --- a/crc/api.yml +++ b/crc/api.yml @@ -408,26 +408,26 @@ paths: schema: $ref: "#/components/schemas/Error" # /v1.0/workflow/0/task/0 - /workflow/{workflow_id}/task/{task_id}: + /workflow/{workflow_id}/task/{task_name}: + parameters: + - name: workflow_id + in: path + required: true + description: The id of the workflow + schema: + type: integer + format: int32 + - name: task_name + in: path + required: true + description: The id of the task + schema: + type: string get: operationId: crc.api.workflow.get_task summary: Get details of specific task in specific workflow instance tags: - Workflows and Tasks - parameters: - - name: workflow_id - in: path - required: true - description: The id of the workflow - schema: - type: integer - format: int32 - - name: task_id - in: path - required: true - description: The id of the task - schema: - type: string responses: '200': description: Expected response to a valid request @@ -452,19 +452,6 @@ paths: name: task schema: $ref: '#/components/schemas/Task' - - name: workflow_id - in: path - required: true - description: The id of the workflow - schema: - type: integer - format: int32 - - name: task_id - in: path - required: true - description: The id of the task - schema: - type: string responses: '201': description: Null response diff --git a/crc/api/workflow.py b/crc/api/workflow.py index ae67315d..9515e71c 100644 --- a/crc/api/workflow.py +++ b/crc/api/workflow.py @@ -35,9 +35,10 @@ def get_task(workflow_id, task_id): return workflow.bpmn_workflow().get_task(task_id) -def update_task(workflow_id, task_id, body): +def update_task(workflow_id, task_name, body): workflow = db.session.query(WorkflowModel).filter_by(id=workflow_id).first() - task = workflow.bpmn_workflow().get_task(task_id) + processor = WorkflowProcessor(workflow.workflow_spec_id, workflow.bpmn_workflow_json) + task = processor.bpmn_workflow.get_tasks_from_spec_name(task_name)[0] if workflow and task and body: print('workflow', workflow.id) print('task', task.id) diff --git a/tests/test_api.py b/tests/test_api.py index 31899597..1bb181d0 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -133,6 +133,7 @@ class TestStudy(BaseTest, unittest.TestCase): self.assertEqual(3, len(tasks[0].form["fields"][0]["options"])) def test_two_forms_task(self): + # Set up a new workfllow self.load_example_data() study = db.session.query(StudyModel).first() spec = db.session.query(WorkflowSpecModel).filter_by(id='two_forms').first() @@ -141,13 +142,25 @@ class TestStudy(BaseTest, unittest.TestCase): json_data = json.loads(rv.get_data(as_text=True)) workflow = WorkflowModelSchema().load(json_data, session=db.session) + # get the first from in the two form workflow. rv = self.app.get('/v1.0/workflow/%i/tasks' % workflow.id, content_type="application/json") json_data = json.loads(rv.get_data(as_text=True)) tasks = TaskSchema(many=True).load(json_data) self.assertEqual(1, len(tasks)) self.assertIsNotNone(tasks[0].form) + self.assertEqual("StepOne", tasks[0].name) self.assertEqual(1, len(tasks[0].form['fields'])) + + # Complete the form for Step one and post it. tasks[0].form['fields'][0]['value']="Blue" - rv = self.app.put('/v1.0/workflow/%i/task/%s' % (workflow.id, tasks[0].id), content_type="application/json", + rv = self.app.put('/v1.0/workflow/%i/task/%s' % (workflow.id, tasks[0].name), content_type="application/json", data=json.dumps(TaskSchema().dump(tasks[0]))) self.assert_success(rv) + + # Get the next Task + rv = self.app.get('/v1.0/workflow/%i/tasks' % study.id, content_type="application/json") + self.assert_success(rv) + json_data = json.loads(rv.get_data(as_text=True)) + tasks = TaskSchema(many=True).load(json_data) + self.assertEqual("StepTwo", tasks[0].name) + self.assertEqual(3, len(tasks[0].form["fields"][0]["options"]))