def test_spec(spec_id, required_only=False): """Runs a spec through it's paces to see if it results in any errors. Not fool-proof, but a good sanity check. Returns the final data output form the last task if successful. required_only can be set to true, in which case this will run the spec, only completing the required fields, rather than everything. """ workflow_model = WorkflowService.make_test_workflow(spec_id) try: processor = WorkflowProcessor(workflow_model, validate_only=True) except WorkflowException as we: WorkflowService.delete_test_data() raise ApiError.from_workflow_exception( "workflow_validation_exception", str(we), we) while not processor.bpmn_workflow.is_completed(): try: processor.bpmn_workflow.do_engine_steps() tasks = processor.bpmn_workflow.get_tasks(SpiffTask.READY) for task in tasks: if task.task_spec.lane is not None and task.task_spec.lane not in task.data: raise ApiError.from_task( "invalid_role", f"This task is in a lane called '{task.task_spec.lane}', The " f" current task data must have information mapping this role to " f" a unique user id.", task) task_api = WorkflowService.spiff_task_to_api_task( task, add_docs_and_forms=True ) # Assure we try to process the documentation, and raise those errors. WorkflowService.populate_form_with_random_data( task, task_api, required_only) processor.complete_task(task) except WorkflowException as we: WorkflowService.delete_test_data() raise ApiError.from_workflow_exception( "workflow_validation_exception", str(we), we) WorkflowService.delete_test_data() return processor.bpmn_workflow.last_task.data
def cancel_notify(self): try: self.bpmn_workflow.signal('cancel') # generate a cancel signal. self.bpmn_workflow.cancel_notify() # call cancel_notify in except WorkflowTaskExecException as we: raise ApiError.from_workflow_exception("task_error", str(we), we)
def do_engine_steps(self, exit_at=None): try: self.bpmn_workflow.refresh_waiting_tasks() self.bpmn_workflow.do_engine_steps(exit_at=exit_at) except WorkflowTaskExecException as we: raise ApiError.from_workflow_exception("task_error", str(we), we)