From 7b7c228a81f785a179d31824bb52e1c82ef33022 Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Mon, 13 Sep 2021 16:15:18 -0400 Subject: [PATCH 1/2] 2 changes - The `all_specifications` method is now explicit in what it returns; either `library`, `standalone`, or `regular` workflow specs - When we add/edit a workflow spec, we make sure that `library` and `standalone` workflow specs do not get a category_id --- crc/api/workflow.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/crc/api/workflow.py b/crc/api/workflow.py index e0091b25..f960ff82 100644 --- a/crc/api/workflow.py +++ b/crc/api/workflow.py @@ -31,11 +31,14 @@ def all_specifications(libraries=False,standalone=False): if standalone: return schema.dump(session.query(WorkflowSpecModel)\ .filter(WorkflowSpecModel.standalone==True).all()) - # this still returns standalone workflow specs as well, but by default - # we do not return specs marked as library - return schema.dump(session.query(WorkflowSpecModel)\ - .filter((WorkflowSpecModel.library==False)|( - WorkflowSpecModel.library==None)).all()) + + # return standard workflows (not library, not standalone) + return schema.dump(session.query(WorkflowSpecModel) + .filter((WorkflowSpecModel.library==False) | ( + WorkflowSpecModel.library==None)) + .filter((WorkflowSpecModel.standalone==False) | ( + WorkflowSpecModel.standalone==None)) + .all()) def add_workflow_specification(body): @@ -43,6 +46,9 @@ def add_workflow_specification(body): WorkflowService.cleanup_workflow_spec_display_order(category_id) count = session.query(WorkflowSpecModel).filter_by(category_id=category_id).count() body['display_order'] = count + # Libraries and standalone workflows don't get a category_id + if body['library'] is True or body['standalone'] is True: + body['category_id'] = None new_spec: WorkflowSpecModel = WorkflowSpecModelSchema().load(body, session=session) session.add(new_spec) session.commit() @@ -119,6 +125,10 @@ def update_workflow_specification(spec_id, body): # There is a separate endpoint for this body['display_order'] = spec.display_order + # Libraries and standalone workflows don't get a category_id + if body['library'] is True or body['standalone'] is True: + body['category_id'] = None + schema = WorkflowSpecModelSchema() spec = schema.load(body, session=session, instance=spec, partial=True) session.add(spec) From 9aadaac0df8a03b9f208b1facb86c367580574e5 Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Mon, 13 Sep 2021 16:16:05 -0400 Subject: [PATCH 2/2] Test to make sure we do not set a category_id for library workflow specs --- tests/workflow/test_workflow_spec_api.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/workflow/test_workflow_spec_api.py b/tests/workflow/test_workflow_spec_api.py index 9c2a8250..fb461fc6 100644 --- a/tests/workflow/test_workflow_spec_api.py +++ b/tests/workflow/test_workflow_spec_api.py @@ -221,3 +221,18 @@ class TestWorkflowSpec(BaseTest): for test_category in categories: self.assertEqual(test_order, test_category.display_order) test_order += 1 + + def test_add_library_with_category_id(self): + self.load_example_data() + category_id = session.query(WorkflowSpecCategoryModel).first().id + spec = WorkflowSpecModel(id='test_spec', name='test_spec', display_name='Test Spec', + description='Library with a category id', category_id=category_id, + standalone=False, library=True) + rv = self.app.post('/v1.0/workflow-specification', + headers=self.logged_in_headers(), + content_type="application/json", + data=json.dumps(WorkflowSpecModelSchema().dump(spec))) + self.assert_success(rv) + # libraries don't get category_ids + # so, the category_id should not get set + self.assertIsNone(rv.json['category_id'])