From acca1523b76f336612afe6e3330e05433c617bdc Mon Sep 17 00:00:00 2001 From: Dan Funk Date: Tue, 28 Jan 2020 10:14:06 -0500 Subject: [PATCH] adding an api call for getting a single workflow spec. --- crc/api.yml | 12 ++++++++++++ crc/api/workflow.py | 7 ++++++- tests/test_api.py | 10 ++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/crc/api.yml b/crc/api.yml index 1cee4439..dab92aa8 100644 --- a/crc/api.yml +++ b/crc/api.yml @@ -247,6 +247,18 @@ paths: description: The unique id of an existing workflow specification to modify. schema: type: string + get: + operationId: crc.api.workflow.get_workflow_specification + summary: Returns a single workflow specification + tags: + - Workflows and Tasks + responses: + '200': + description: Workflow specification. + content: + application/json: + schema: + $ref: "#/components/schemas/WorkflowSpec" put: operationId: crc.api.workflow.update_workflow_specification summary: Modifies an existing workflow specification with the given parameters. diff --git a/crc/api/workflow.py b/crc/api/workflow.py index c3f90cb5..ac4dfd47 100644 --- a/crc/api/workflow.py +++ b/crc/api/workflow.py @@ -21,7 +21,7 @@ def add_workflow_specification(body): return WorkflowSpecModelSchema().dump(new_spec) -def update_workflow_specification(spec_id, body): +def get_workflow_specification(spec_id): if spec_id is None: error = ApiError('unknown_spec', 'Please provide a valid Workflow Specification ID.') return ApiErrorSchema.dump(error), 404 @@ -32,7 +32,12 @@ def update_workflow_specification(spec_id, body): error = ApiError('unknown_spec', 'The Workflow Specification "' + spec_id + '" is not recognized.') return ApiErrorSchema.dump(error), 404 + return WorkflowSpecModelSchema().dump(spec) + + +def update_workflow_specification(spec_id, body): spec = WorkflowSpecModelSchema().load(body, session=session) + spec.id = spec_id session.add(spec) session.commit() return WorkflowSpecModelSchema().dump(spec) diff --git a/tests/test_api.py b/tests/test_api.py index e493059a..de9530cb 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -100,6 +100,16 @@ class TestStudy(BaseTest): num_after = session.query(WorkflowSpecModel).count() self.assertEqual(num_after, num_before + 1) + def test_get_workflow_specification(self): + self.load_example_data() + db_spec = session.query(WorkflowSpecModel).first() + rv = self.app.get('/v1.0/workflow-specification/%s' % db_spec.id) + self.assert_success(rv) + json_data = json.loads(rv.get_data(as_text=True)) + api_spec = WorkflowSpecModelSchema().load(json_data, session=session) + self.assertEqual(db_spec, api_spec) + + def test_modify_workflow_specification(self): self.load_example_data() old_id = 'random_fact'