Merge remote-tracking branch 'origin/master'

This commit is contained in:
Aaron Louie 2019-12-30 15:06:06 -05:00
commit 24ced2e280
7 changed files with 43 additions and 15 deletions

View File

@ -33,4 +33,5 @@ cors = CORS(connexion_app.app)
def load_example_data():
"""Load example data into the database."""
from example_data import ExampleDataLoader
ExampleDataLoader.clean_db()
ExampleDataLoader().load_all()

View File

@ -290,12 +290,7 @@ paths:
example: '<?xml version="1.0" encoding="UTF-8"?><bpmn:definitions></bpmn:definitions>'
# /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:
- Workflows and Tasks
responses:
'204':
description: The workflow was removed
/workflow/{workflow_id}/tasks:
get:
operationId: crc.api.workflow.get_tasks

View File

@ -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)

View File

@ -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()

View File

@ -50,6 +50,13 @@ class ExampleDataLoader:
file = open(filename, "rb")
workflow_data = [FileDataModel(data=file.read(), file_model=workflow_spec_files[0])]
@staticmethod
def clean_db():
db.session.flush() # Clear out any transactions before deleting it all to avoid spurious errors.
for table in reversed(db.metadata.sorted_tables):
db.session.execute(table.delete())
db.session.flush()
def load_all(self):
db.session.bulk_save_objects(ExampleDataLoader.studies)
db.session.bulk_save_objects(ExampleDataLoader.workflow_specs)

View File

@ -5,7 +5,7 @@ import os
os.environ["TESTING"] = "true"
from crc import app, db
from example_data import ExampleDataLoader
# UNCOMMENT THIS FOR DEBUGGING SQL ALCHEMY QUERIES
# import logging
@ -13,11 +13,7 @@ from crc import app, db
# logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
def clean_db():
db.session.flush() # Clear out any transactions before deleting it all to avoid spurious errors.
for table in reversed(db.metadata.sorted_tables):
db.session.execute(table.delete())
db.session.flush()
# Great class to inherit from, as it sets up and tears down
@ -43,13 +39,13 @@ class BaseTest:
self.ctx.push()
def tearDown(self):
clean_db() # This does not seem to work, some colision of sessions.
ExampleDataLoader.clean_db() # This does not seem to work, some colision of sessions.
self.ctx.pop()
self.auths = {}
def load_example_data(self):
clean_db()
from example_data import ExampleDataLoader
ExampleDataLoader.clean_db()
ExampleDataLoader().load_all()
def assert_success(self, rv, msg=""):

View File

@ -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()