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

This commit is contained in:
Kelly McDonald 2021-08-03 10:02:22 -04:00
parent 8566fff690
commit 6e1fedb704
4 changed files with 41 additions and 71 deletions

View File

@ -440,26 +440,6 @@ paths:
schema: schema:
$ref: "#/components/schemas/WorkflowSpec" $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}: /workflow-specification/{spec_id}/library/{library_id}:
parameters: parameters:
@ -564,36 +544,6 @@ paths:
responses: responses:
'204': '204':
description: The workflow specification has been removed. 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: /workflow-specification/{spec_id}/validate:
parameters: parameters:
- name: spec_id - name: spec_id

View File

@ -58,15 +58,6 @@ def get_workflow_specification(spec_id):
return WorkflowSpecModelSchema().dump(spec) 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): def validate_spec_and_library(spec_id,library_id):
if spec_id is None: if spec_id is None:
raise ApiError('unknown_spec', 'Please provide a valid Workflow Specification ID.') 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) 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): def get_workflow(workflow_id, do_engine_steps=True):
"""Retrieve workflow based on workflow_id, and return it in the last saved State. """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. """ If do_engine_steps is False, return the workflow without running any engine tasks or logging any events. """

View File

@ -268,7 +268,7 @@ class ExampleDataLoader:
from_tests=True) from_tests=True)
def create_spec(self, id, name, display_name="", description="", filepath=None, master_spec=False, 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. """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. 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.""" returns an array of data models to be added to the database."""
@ -281,7 +281,8 @@ class ExampleDataLoader:
is_master_spec=master_spec, is_master_spec=master_spec,
category_id=category_id, category_id=category_id,
display_order=display_order, display_order=display_order,
standalone=standalone) standalone=standalone,
library=library)
db.session.add(spec) db.session.add(spec)
db.session.commit() db.session.commit()
if not filepath and not from_tests: if not filepath and not from_tests:

View File

@ -25,3 +25,41 @@ class TestWorkflowApi(BaseTest):
content_type="application/json", content_type="application/json",
headers=self.logged_in_headers()) headers=self.logged_in_headers())
self.assert_success(rv) 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)