Fixes a bug in get_study_workflows and adds a test covering it

This commit is contained in:
Aaron Louie 2020-03-06 10:52:41 -05:00
parent 5bf0eb33d9
commit acad0023d2
2 changed files with 31 additions and 1 deletions

View File

@ -121,7 +121,7 @@ def get_study_workflows(study_id):
workflow_models = session.query(WorkflowModel).filter_by(study_id=study_id).all()
api_models = []
for workflow_model in workflow_models:
processor = WorkflowProcessor(workflow_model.workflow_spec_id,
processor = WorkflowProcessor(workflow_model,
workflow_model.bpmn_workflow_json)
api_models.append(__get_workflow_api_model(processor))
schema = WorkflowApiSchema(many=True)

View File

@ -155,3 +155,33 @@ class TestStudyApi(BaseTest):
rv = self.app.delete('/v1.0/workflow/%i' % workflow.id)
self.assert_success(rv)
self.assertEqual(0, session.query(WorkflowModel).count())
def test_get_study_workflows(self):
self.load_example_data()
# Should have no workflows to start
study = session.query(StudyModel).first()
response_before = self.app.get('/v1.0/study/%i/workflows' % study.id,
content_type="application/json",
headers=self.logged_in_headers())
self.assert_success(response_before)
json_data_before = json.loads(response_before.get_data(as_text=True))
workflows_before = WorkflowApiSchema(many=True).load(json_data_before)
self.assertEqual(0, len(workflows_before))
# Add a workflow
spec = session.query(WorkflowSpecModel).first()
add_response = self.app.post('/v1.0/study/%i/workflows' % study.id,
content_type="application/json",
headers=self.logged_in_headers(),
data=json.dumps(WorkflowSpecModelSchema().dump(spec)))
self.assert_success(add_response)
# Should have no workflows to start
response_after = self.app.get('/v1.0/study/%i/workflows' % study.id,
content_type="application/json",
headers=self.logged_in_headers())
self.assert_success(response_after)
json_data_after = json.loads(response_after.get_data(as_text=True))
workflows_after = WorkflowApiSchema(many=True).load(json_data_after)
self.assertEqual(1, len(workflows_after))