コード例 #1
0
ファイル: test_branch.py プロジェクト: pir8aye/WALKOFF
    def test_branch_counter(self):
        action = Action('HelloWorld', 'helloWorld', 'helloWorld', id=1)

        branch = Branch(source_id=action.id, destination_id=action.id)
        self.assertEqual(branch._counter, 0)
        accumulator = {}

        action._output = ActionResult(result='aaa', status='Success')
        workflow = Workflow('test', 1, actions=[action], branches=[branch])
        workflow.get_branch(action, accumulator)

        self.assertEqual(branch._counter, 1)
        self.assertIn(branch.id, accumulator)
        self.assertEqual(accumulator[branch.id], 1)
コード例 #2
0
ファイル: test_branch.py プロジェクト: pir8aye/WALKOFF
    def test_get_branch(self):
        action = Action('HelloWorld', 'helloWorld', 'helloWorld', id=10)
        action2 = Action('HelloWorld', 'helloWorld', 'helloWorld', id=2)
        condition = ConditionalExpression(
            'and',
            conditions=[
                Condition('HelloWorld',
                          action_name='regMatch',
                          arguments=[Argument('regex', value='aaa')])
            ])
        branch = Branch(source_id=action.id,
                        destination_id=2,
                        condition=condition)
        action._output = ActionResult(result='aaa', status='Success')
        workflow = Workflow("helloWorld",
                            action.id,
                            actions=[action, action2],
                            branches=[branch])

        result = {'triggered': False}

        def validate_sent_data(sender, **kwargs):
            if isinstance(sender, Branch):
                self.assertIn('event', kwargs)
                self.assertEqual(kwargs['event'], WalkoffEvent.BranchTaken)
                result['triggered'] = True

        WalkoffEvent.CommonWorkflowSignal.connect(validate_sent_data)

        self.assertEqual(workflow.get_branch(action, {}), 2)
        self.assertTrue(result['triggered'])
コード例 #3
0
ファイル: test_branch.py プロジェクト: pir8aye/WALKOFF
    def test_branch_with_priority(self):
        action = Action('HelloWorld', 'helloWorld', 'helloWorld', id=10)
        action2 = Action('HelloWorld', 'helloWorld', 'helloWorld', id=5)
        action3 = Action('HelloWorld', 'helloWorld', 'helloWorld', id=1)

        condition = ConditionalExpression(
            'and',
            conditions=[
                Condition('HelloWorld',
                          action_name='regMatch',
                          arguments=[Argument('regex', value='aaa')])
            ])

        branch_one = Branch(source_id=action.id,
                            destination_id=5,
                            condition=condition,
                            priority=5)
        branch_two = Branch(source_id=action.id,
                            destination_id=1,
                            condition=condition,
                            priority=1)

        action._output = ActionResult(result='aaa', status='Success')
        workflow = Workflow('test',
                            1,
                            actions=[action, action2, action3],
                            branches=[branch_one, branch_two])

        self.assertEqual(workflow.get_branch(action, {}), 1)
コード例 #4
0
ファイル: test_branch.py プロジェクト: pir8aye/WALKOFF
 def test_get_branch_no_branches(self):
     workflow = Workflow('test', 1)
     self.assertIsNone(workflow.get_branch(None, {}))