From 6e1fedb704b4c4b30f1f84af18b0862e9153e2ee Mon Sep 17 00:00:00 2001 From: Kelly McDonald Date: Tue, 3 Aug 2021 10:02:22 -0400 Subject: [PATCH] Add tests for libraries, remove an API endpoint that didn't make sense after recent changes and remove some commented out sections that were not needed after some decisions about the api endpoints were made --- crc/api.yml | 50 -------------------------------------- crc/api/workflow.py | 19 --------------- example_data.py | 5 ++-- tests/test_workflow_api.py | 38 +++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 71 deletions(-) diff --git a/crc/api.yml b/crc/api.yml index 0099a6f4..bea7f284 100644 --- a/crc/api.yml +++ b/crc/api.yml @@ -440,26 +440,6 @@ paths: schema: $ref: "#/components/schemas/WorkflowSpec" - /workflow-specification/{spec_id}/libraries: - parameters: - - name: spec_id - in: path - required: true - description: The unique id of an existing workflow specification. - schema: - type: string - get: - operationId: crc.api.workflow.get_workflow_specification_libraries - summary: Returns all libraries that are enabled for a workflow spec - tags: - - Workflow Specifications - responses: - '200': - description: Workflow specification. - content: - application/json: - schema: - $ref: "#/components/schemas/WorkflowSpec" /workflow-specification/{spec_id}/library/{library_id}: parameters: @@ -564,36 +544,6 @@ paths: responses: '204': description: The workflow specification has been removed. -# /workflow-specification/standalone: -# get: -# operationId: crc.api.workflow.standalone_workflow_specs -# summary: Provides a list of workflow specifications that can be run outside a study. -# tags: -# - Workflow Specifications -# responses: -# '200': -# description: A list of workflow specifications -# content: -# application/json: -# schema: -# type: array -# items: -# $ref: "#/components/schemas/WorkflowSpec" -# /workflow-specification/libraries: -# get: -# operationId: crc.api.workflow.library_workflow_specs -# summary: Provides a list of workflow specifications that are considered libraries. -# tags: -# - Workflow Specifications -# responses: -# '200': -# description: A list of workflow specifications -# content: -# application/json: -# schema: -# type: array -# items: -# $ref: "#/components/schemas/WorkflowSpec" /workflow-specification/{spec_id}/validate: parameters: - name: spec_id diff --git a/crc/api/workflow.py b/crc/api/workflow.py index 44305e4c..82c83e23 100644 --- a/crc/api/workflow.py +++ b/crc/api/workflow.py @@ -58,15 +58,6 @@ def get_workflow_specification(spec_id): return WorkflowSpecModelSchema().dump(spec) -def get_workflow_specification_libraries(spec_id): - if spec_id is None: - raise ApiError('unknown_spec', 'Please provide a valid Workflow Specification ID.') - spec: WorkflowSpecModel = session.query(WorkflowSpecModel).filter_by(id=spec_id).first() - libraries: WorkflowLibraryModel = session.query(WorkflowLibraryModel).filter_by(workflow_spec_id=spec_id).all() - if spec is None: - raise ApiError('unknown_spec', 'The Workflow Specification "' + spec_id + '" is not recognized.') - return WorkflowLibraryModelSchema(many=True).dump(libraries) - def validate_spec_and_library(spec_id,library_id): if spec_id is None: raise ApiError('unknown_spec', 'Please provide a valid Workflow Specification ID.') @@ -163,16 +154,6 @@ def get_workflow_from_spec(spec_id): return WorkflowApiSchema().dump(workflow_api_model) -# def standalone_workflow_specs(): -# schema = WorkflowSpecModelSchema(many=True) -# specs = WorkflowService.get_standalone_workflow_specs() -# return schema.dump(specs) - -# def library_workflow_specs(): -# schema = WorkflowSpecModelSchema(many=True) -# specs = WorkflowService.get_library_workflow_specs() -# return schema.dump(specs) - def get_workflow(workflow_id, do_engine_steps=True): """Retrieve workflow based on workflow_id, and return it in the last saved State. If do_engine_steps is False, return the workflow without running any engine tasks or logging any events. """ diff --git a/example_data.py b/example_data.py index 21b4dd12..11751798 100644 --- a/example_data.py +++ b/example_data.py @@ -268,7 +268,7 @@ class ExampleDataLoader: from_tests=True) def create_spec(self, id, name, display_name="", description="", filepath=None, master_spec=False, - category_id=None, display_order=None, from_tests=False, standalone=False): + category_id=None, display_order=None, from_tests=False, standalone=False, library=False): """Assumes that a directory exists in static/bpmn with the same name as the given id. further assumes that the [id].bpmn is the primary file for the workflow. returns an array of data models to be added to the database.""" @@ -281,7 +281,8 @@ class ExampleDataLoader: is_master_spec=master_spec, category_id=category_id, display_order=display_order, - standalone=standalone) + standalone=standalone, + library=library) db.session.add(spec) db.session.commit() if not filepath and not from_tests: diff --git a/tests/test_workflow_api.py b/tests/test_workflow_api.py index 02b5b348..07a5b214 100644 --- a/tests/test_workflow_api.py +++ b/tests/test_workflow_api.py @@ -25,3 +25,41 @@ class TestWorkflowApi(BaseTest): content_type="application/json", headers=self.logged_in_headers()) self.assert_success(rv) + + + def test_library_code(self): + self.load_example_data() + spec1 = ExampleDataLoader().create_spec('hello_world', 'Hello World', category_id=0, library=False, + from_tests=True) + + spec2 = ExampleDataLoader().create_spec('hello_world_lib', 'Hello World Library', category_id=0, library=True, + from_tests=True) + user = session.query(UserModel).first() + self.assertIsNotNone(user) + #WorkflowService.get_workflow_from_spec(spec.id, user) + + rv = self.app.post(f'/v1.0/workflow-specification/%s/library/%s'%(spec1.id,spec2.id), + follow_redirects=True, + content_type="application/json", + headers=self.logged_in_headers()) + self.assert_success(rv) + + rv = self.app.get(f'/v1.0/workflow-specification/%s'%spec1.id,follow_redirects=True, + content_type="application/json", + headers=self.logged_in_headers()) + returned=rv.json + self.assertIsNotNone(returned.get('libraries')) + self.assertEqual(len(returned['libraries']),1) + self.assertEqual(returned['libraries'][0].get('id'),'hello_world_lib') + rv = self.app.delete(f'/v1.0/workflow-specification/%s/library/%s'%(spec1.id,spec2.id),follow_redirects=True, + content_type="application/json", + headers=self.logged_in_headers()) + rv = self.app.get(f'/v1.0/workflow-specification/%s'%spec1.id,follow_redirects=True, + content_type="application/json", + headers=self.logged_in_headers()) + returned=rv.json + self.assertIsNotNone(returned.get('libraries')) + self.assertEqual(len(returned['libraries']),0) + + +