def test_mark_stage_instance_complete(self): stage_instance = StageInstance() InstanceWorkflowEngine._mark_stage_instance_complete( stage_instance, StatusConstants.SUCCESS) eq_(StatusConstants.SUCCESS, stage_instance.status_id) ok_(stage_instance.end_date is not None)
def test_check_verify_statuses_simple(self): workflow_engine = InstanceWorkflowEngine(Mock(), Mock()) all_complete, all_passed, failed_type = workflow_engine._check_and_verify_statuses( [StageInstance(status_id=StatusConstants.NEW)]) eq_(False, all_complete) eq_(True, all_passed) eq_(None, failed_type)
def _pipeline_helper(self): action_instance = ActionInstance(id=1, order=0) workflow_instance = WorkflowInstance(id=1, actions=[action_instance]) stage_instance = StageInstance(id=1, workflows=[workflow_instance]) pipeline_instance = PipelineInstance( id=1, stages=[stage_instance, stage_instance]) return action_instance, workflow_instance, stage_instance, pipeline_instance
def test_reconciled_stages(self): stage_instance = StageInstance(id=2, status_id=StatusConstants.SUCCESS, stage_id=2) pipeline_instance = PipelineInstance( stage_instances=[ StageInstance(id=1, status_id=StatusConstants.SUCCESS), stage_instance ], pipeline=Pipeline(stages=[Stage(id=1), Stage(id=2)])) instance_workflow_engine = InstanceWorkflowEngine( Mock(), pipeline_instance) instance_workflow_engine._load_pipeline() instance_workflow_engine.complete_a_stage(2, StatusConstants.SUCCESS) eq_(StatusConstants.SUCCESS, pipeline_instance.status_id) ok_(pipeline_instance.end_date is not None)
def test_check_verify_statuses_simple_inprogress(self): self._testing_check_verify( [StageInstance(status_id=StatusConstants.INPROGRESS)], [False, True, None])
def _build_pipeline_instance(self, actions, completed=False): pipeline_instance = PipelineInstance() status_id = StatusConstants.NEW if not completed else StatusConstants.SUCCESS if completed: pipeline_instance.created_date = datetime.datetime.utcnow() pipeline_instance.start_date = datetime.datetime.utcnow() pipeline_instance.end_date = datetime.datetime.utcnow() pipeline_instance.status_id = status_id stage_instances = {} s_idcount = w_idcount = a_idcount = 1 pipeline_instance.pipeline = Mock(stages=[]) for action in actions: sp = action.split(':') stage_instance = StageInstance(id=s_idcount, status_id=status_id) stage_instances[s_idcount] = stage_instance if completed: stage_instance.created_date = datetime.datetime.utcnow() stage_instance.start_date = datetime.datetime.utcnow() stage_instance.end_date = datetime.datetime.utcnow() w_number = int(sp[0]) a_sp = sp[1].split('-') for workflow_id in range(0, w_number): workflow_instance = WorkflowInstance( id=w_idcount, stage_instance_id=stage_instance.id, status_id=status_id) if completed: workflow_instance.created_date = datetime.datetime.utcnow() workflow_instance.start_date = datetime.datetime.utcnow() workflow_instance.end_date = datetime.datetime.utcnow() try: order = 0 for action_count in a_sp[workflow_id].split(','): a_count = int(action_count) for num in range(0, a_count): action_instance = ActionInstance( id=a_idcount, order=order, slice="{}/{}".format(num + 1, a_count), workflow_instance_id=workflow_instance.id, status_id=status_id) if completed: action_instance.created_date = datetime.datetime.utcnow( ) action_instance.start_date = datetime.datetime.utcnow( ) action_instance.end_date = datetime.datetime.utcnow( ) workflow_instance.action_instances.append( action_instance) a_idcount += 1 order += 1 except: action_instance = ActionInstance( id=a_idcount, order=0, workflow_instance_id=workflow_instance.id, status_id=status_id) if completed: action_instance.created_date = datetime.datetime.utcnow( ) action_instance.start_date = datetime.datetime.utcnow() action_instance.end_date = datetime.datetime.utcnow() workflow_instance.action_instances.append() w_idcount += 1 stage_instance.workflow_instances.append(workflow_instance) pipeline_instance.stage_instances.append(stage_instance) pipeline_instance.pipeline.stages.append(stage_instance) s_idcount += 1 return pipeline_instance
def test_get_workflows(self): workflow_engine = InstanceWorkflowEngine(Mock(), Mock()) workflow_instance = WorkflowInstance() stage_instance = StageInstance(workflow_instances=[workflow_instance]) eq_([workflow_instance], workflow_engine._get_workflows(stage_instance))
def test_get_stages(self): workflow_engine = InstanceWorkflowEngine(Mock(), Mock()) stage_instance = StageInstance() pipeline_instance = PipelineInstance(stage_instances=[stage_instance]) eq_([stage_instance], workflow_engine._get_stages(pipeline_instance))
def test_mark_stage_instance_complete_canceled(self): stage_instance = StageInstance(start_date=datetime.datetime.utcnow()) InstanceWorkflowEngine._mark_stage_instance_complete( stage_instance, StatusConstants.CANCELED) eq_(stage_instance.start_date, stage_instance.end_date)