Make sure we have a workflow.
Raise an ApiError with the workflow_spec_id if we cannot find a workflow
This commit is contained in:
parent
c1606a20a5
commit
ed0499a573
|
@ -63,8 +63,12 @@ class StartWorkflow(Script):
|
|||
filter(WorkflowModel.workflow_spec_id==workflow_spec_id).\
|
||||
first()
|
||||
|
||||
if workflow:
|
||||
workflow_api = self.get_workflow(workflow.id)
|
||||
return workflow_api
|
||||
else:
|
||||
raise ApiError(code='unknown_workflow',
|
||||
message=f"We could not find a workflow with workflow_spec_id '{workflow_spec_id}'.")
|
||||
|
||||
else:
|
||||
raise ApiError(code='missing_parameter',
|
||||
|
|
|
@ -9,12 +9,7 @@ from crc.services.workflow_spec_service import WorkflowSpecService
|
|||
|
||||
class TestStartWorkflow(BaseTest):
|
||||
|
||||
def test_start_workflow_validation(self):
|
||||
spec_model = self.load_test_spec('start_workflow')
|
||||
rv = self.app.get('/v1.0/workflow-specification/%s/validate' % spec_model.id, headers=self.logged_in_headers())
|
||||
self.assertEqual([], rv.json)
|
||||
|
||||
def test_start_workflow(self):
|
||||
def setup_test_start_workflow(self):
|
||||
self.add_users()
|
||||
self.create_workflow('hello_world')
|
||||
workflow_spec_to_start = WorkflowSpecService().get_spec('hello_world')
|
||||
|
@ -24,6 +19,16 @@ class TestStartWorkflow(BaseTest):
|
|||
study = session.query(StudyModel).filter(StudyModel.id==study_id).first()
|
||||
StudyService.add_all_workflow_specs_to_study(study, [workflow_spec_to_start])
|
||||
|
||||
return workflow
|
||||
|
||||
def test_start_workflow_validation(self):
|
||||
spec_model = self.load_test_spec('start_workflow')
|
||||
rv = self.app.get('/v1.0/workflow-specification/%s/validate' % spec_model.id, headers=self.logged_in_headers())
|
||||
self.assertEqual([], rv.json)
|
||||
|
||||
def test_start_workflow(self):
|
||||
workflow = self.setup_test_start_workflow()
|
||||
|
||||
workflow_before = session.query(WorkflowModel).filter(WorkflowModel.workflow_spec_id=='hello_world').first()
|
||||
self.assertEqual('not_started', workflow_before.status.value)
|
||||
|
||||
|
@ -33,3 +38,10 @@ class TestStartWorkflow(BaseTest):
|
|||
|
||||
workflow_after = session.query(WorkflowModel).filter(WorkflowModel.workflow_spec_id=='hello_world').first()
|
||||
self.assertEqual('user_input_required', workflow_after.status.value)
|
||||
|
||||
def test_bad_workflow_spec_id(self):
|
||||
workflow = self.setup_test_start_workflow()
|
||||
workflow_api = self.get_workflow_api(workflow)
|
||||
task = workflow_api.next_task
|
||||
with self.assertRaises(AssertionError) as e:
|
||||
self.complete_form(workflow, task, {'workflow_spec_to_start': 'bad_spec_id'})
|
||||
|
|
Loading…
Reference in New Issue