diff --git a/crc/api.yml b/crc/api.yml index 0e7608a2..80bc9f05 100644 --- a/crc/api.yml +++ b/crc/api.yml @@ -290,12 +290,7 @@ paths: example: '' # /v1.0/workflow/0 /workflow/{workflow_id}: - get: - operationId: crc.api.workflow.get_workflow - summary: Detailed information for a specific workflow instance - tags: - - Workflows and Tasks - parameters: + parameters: - name: workflow_id in: path required: true @@ -303,6 +298,11 @@ paths: schema: type: integer format: int32 + get: + operationId: crc.api.workflow.get_workflow + summary: Detailed information for a specific workflow instance + tags: + - Workflows and Tasks responses: '200': description: Returns details about the workflows state and current task @@ -316,6 +316,14 @@ paths: application/json: schema: $ref: "#/components/schemas/Error" + delete: + operationId: crc.api.workflow.delete + summary: Removes an existing workflow + tags: + - Files + responses: + '204': + description: The workflow was removed /workflow/{workflow_id}/tasks: get: operationId: crc.api.workflow.get_tasks diff --git a/crc/api/study.py b/crc/api/study.py index 46545071..da8d1257 100644 --- a/crc/api/study.py +++ b/crc/api/study.py @@ -50,4 +50,4 @@ def add_workflow_to_study(study_id, body): workflow_spec_id=workflow_spec_model.id) db.session.add(workflow) db.session.commit() - return get_study_workflows(study_id) + return WorkflowSchema().dump(workflow) diff --git a/crc/api/workflow.py b/crc/api/workflow.py index 9bf55965..b9be5e8c 100644 --- a/crc/api/workflow.py +++ b/crc/api/workflow.py @@ -14,6 +14,8 @@ def get_workflow(workflow_id): workflow = db.session.query(WorkflowModel).filter_by(id=workflow_id).first() return schema.dump(workflow) +def delete(workflow_id): + db.session.query(WorkflowModel).filter_by(id=workflow_id).delete() def get_tasks(workflow_id): workflow = db.session.query(WorkflowModel).filter_by(id=workflow_id).first() diff --git a/tests/base_test.py b/tests/base_test.py index a13b2ba8..19c117cf 100644 --- a/tests/base_test.py +++ b/tests/base_test.py @@ -44,8 +44,8 @@ class BaseTest: self.auths = {} def load_example_data(self): - ExampleDataLoader.clean_db() from example_data import ExampleDataLoader + ExampleDataLoader.clean_db() ExampleDataLoader().load_all() def assert_success(self, rv, msg=""): diff --git a/tests/test_api.py b/tests/test_api.py index 5c736864..0ea76d0c 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -68,6 +68,20 @@ class TestStudy(BaseTest, unittest.TestCase): workflows = WorkflowSchema(many=True).load(json_data, session=db.session) self.assertEqual(workflows[0].id, workflow.id) + def test_delete_workflow(self): + self.load_example_data() + study = db.session.query(StudyModel).first() + spec = db.session.query(WorkflowSpecModel).first() + rv = self.app.post('/v1.0/study/%i/workflows' % study.id,content_type="application/json", + data=json.dumps(WorkflowSpecSchema().dump(spec))) + self.assertEqual(1, db.session.query(WorkflowModel).count()) + json_data = json.loads(rv.get_data(as_text=True)) + workflow = WorkflowSchema().load(json_data, session=db.session) + rv = self.app.delete('/v1.0/workflow/%i' % workflow.id) + self.assert_success(rv) + self.assertEqual(0, db.session.query(WorkflowModel).count()) + + def test_get_current_user_tasks(self): self.load_example_data() study = db.session.query(StudyModel).first()