def test_variable_scope(self): wf1_1 = wf1.build() wf1_2 = wf1.build() wf2_1 = wf2.build() for wf in [wf1_1, wf1_2, wf2_1]: wf_proxy.set_workflow(wf) wf.execute() var_pool = defaultdict(dict) n_wf1_1, n_wf1_2, n_wf2_1 = 'wf1_1', 'wf1_2', 'wf2_1' for wf, name_wf in [(wf1_1, n_wf1_1), (wf1_2, n_wf1_2), (wf2_1, n_wf2_1)]: wf_proxy.set_workflow(wf) for var in [var_local, var_wf, var_overall]: value = var.get() self.assertTrue(isinstance(value, int)) var_pool[name_wf][var.name] = value n_local, n_wf, n_overall = var_local.name, var_wf.name, var_overall.name self.assertTrue(var_pool[n_wf1_1][n_local] != var_pool[n_wf1_2][n_local]) self.assertTrue(var_pool[n_wf1_1][n_wf] == var_pool[n_wf1_2][n_wf]) self.assertTrue(var_pool[n_wf1_1][n_wf] != var_pool[n_wf2_1][n_wf]) self.assertTrue(var_pool[n_wf1_1][n_overall] == var_pool[n_wf1_2][n_overall]) self.assertTrue(var_pool[n_wf1_1][n_overall] == var_pool[n_wf2_1][n_overall])
def _run(self, wf): wf_proxy.set_workflow(wf) try: wf.execute() except: wf.log(format_exc()) wf.save() return wf
def test_set_get_prop(self): wf = WorkflowFactory.from_builder() wf_proxy.set_workflow(wf) props = {'p1': 'v1', 'p2': 'v2', 'p3': 'v3', 'p4': 'v4'} for k, v in props.iteritems(): wf.set_prop(k, v) for k in props: v = wf.get_prop(k) self.assertTrue(v == props[k])
def setUp(self): db.connect() self.handler = None self.wf = None self.trace = None self.event = Event(name='test_event', entity='dev', state='warning') self.judgement = Judgement.construct('this is a test to judgement', ['option1', 'option2', 'option3']) self.mode = self.WAIT_EVENT self.event.save() class Trace(object): def __init__(self): self.is_start = False self.is_end = False self.is_timeout = False builder = WorkflowBuilder('test_async_event') trace = Trace() self.trace = trace @builder.task('start', entrance=True) def task_start(): trace.is_start = True self._task() @builder.task('end') def task_end(): trace.is_end = True builder.end() @builder.task('timeout') def task_timeout(): trace.is_timeout = True builder.end() setter = lambda h: setattr(self, 'handler', h) reactor = Mock( **{ 'attach_async_workflow.side_effect': setter, 'attach_judgement.side_effect': setter }) builder.setup(123, reactor) self.builder = builder self.wf = builder.build() wf_proxy.set_workflow(self.wf)
def test_wf_max_depth(self): builder = WorkflowBuilder('TestWorkflow') task_name = 'sole' def func(): builder.goto(task_name) builder.add_task(task_name, func, entrance=True) wf = builder.build() wf_proxy.set_workflow(wf) try: wf.execute() except Exception as e: self.assertTrue('max number' in e.message) else: self.assertTrue(False)
def test_workflow_entrance(self): order, expect = [], ['b', 'a', 'c'] builder = WorkflowBuilder('TestWorkflow') @builder.task('a') def task_a(): order.append('a') builder.goto('c') @builder.task('b', True) def task_b(): order.append('b') builder.goto('a') @builder.task('c') def task_c(): order.append('c') builder.end() wf = builder.build() wf_proxy.set_workflow(wf) wf.execute() self.assertTrue(order == expect)
def test_wf_descriptor(self): wf = WorkflowFactory.from_descriptor() wf_proxy.set_workflow(wf) wf.execute() self.assertTrue(wf.state == STATE_SUCCEED)