Esempio n. 1
0
    def test_execute(self):
        class MockAction(object):
            id = 13

        condition1 = ConditionalExpression(
            'and',
            conditions=[Condition('HelloWorld', action_name='regMatch', arguments=[Argument('regex', value='(.*)')])])
        condition2 = ConditionalExpression(
            'and',
            conditions=[Condition('HelloWorld', action_name='regMatch', arguments=[Argument('regex', value='(.*)')]),
                        Condition('HelloWorld', action_name='regMatch', arguments=[Argument('regex', value='a')])])

        inputs = [('name1', None, ActionResult('aaaa', 'Success'), True),
                  ('name2', condition1, ActionResult('anyString', 'Success'), True),
                  ('name3', condition2, ActionResult('anyString', 'Success'), True),
                  ('name4', condition2, ActionResult('bbbb', 'Success'), False),
                  ('name4', condition2, ActionResult('aaaa', 'Custom'), False)]

        for name, condition, previous_result, expect_name in inputs:
            branch = Branch(source_id=1, destination_id=2, condition=condition)
            acc = {MockAction.id: previous_result.result}
            status = previous_result.status
            action = MockAction()
            if expect_name:
                expected_name = branch.destination_id
                self.assertEqual(branch.execute(LocalActionExecutionStrategy(), status, action, acc), expected_name)
            else:
                self.assertIsNone(branch.execute(LocalActionExecutionStrategy(), status, action, acc))
Esempio n. 2
0
    def test_execute(self):
        condition1 = ConditionalExpression(
            'and',
            conditions=[
                Condition('HelloWorld',
                          action_name='regMatch',
                          arguments=[Argument('regex', value='(.*)')])
            ])
        condition2 = ConditionalExpression(
            'and',
            conditions=[
                Condition('HelloWorld',
                          action_name='regMatch',
                          arguments=[Argument('regex', value='(.*)')]),
                Condition('HelloWorld',
                          action_name='regMatch',
                          arguments=[Argument('regex', value='a')])
            ])

        inputs = [('name1', None, ActionResult('aaaa', 'Success'), True),
                  ('name2', condition1, ActionResult('anyString',
                                                     'Success'), True),
                  ('name3', condition2, ActionResult('anyString',
                                                     'Success'), True),
                  ('name4', condition2, ActionResult('bbbb',
                                                     'Success'), False),
                  ('name4', condition2, ActionResult('aaaa', 'Custom'), False)]

        for name, condition, input_str, expect_name in inputs:
            branch = Branch(source_id=1, destination_id=2, condition=condition)
            if expect_name:
                expected_name = branch.destination_id
                self.assertEqual(branch.execute(input_str, {}), expected_name)
            else:
                self.assertIsNone(branch.execute(input_str, {}))
Esempio n. 3
0
    def test_execute(self):
        class MockAction(object):
            id = 13

        condition1 = ConditionalExpression(
            'and',
            conditions=[
                Condition('HelloWorld',
                          action_name='regMatch',
                          arguments=[Argument('regex', value='(.*)')])
            ])
        condition2 = ConditionalExpression(
            'and',
            conditions=[
                Condition('HelloWorld',
                          action_name='regMatch',
                          arguments=[Argument('regex', value='(.*)')]),
                Condition('HelloWorld',
                          action_name='regMatch',
                          arguments=[Argument('regex', value='a')])
            ])

        inputs = [('name1', None, ActionResult('aaaa', 'Success'), True),
                  ('name2', condition1, ActionResult('anyString',
                                                     'Success'), True),
                  ('name3', condition2, ActionResult('anyString',
                                                     'Success'), True),
                  ('name4', condition2, ActionResult('bbbb',
                                                     'Success'), False),
                  ('name4', condition2, ActionResult('aaaa', 'Custom'), False)]

        for name, condition, previous_result, expect_name in inputs:
            branch = Branch(source_id=1, destination_id=2, condition=condition)
            acc = {MockAction.id: previous_result.result}
            status = previous_result.status
            action = MockAction()
            if expect_name:
                expected_name = branch.destination_id
                self.assertEqual(
                    branch.execute(LocalActionExecutionStrategy(), status,
                                   action, acc), expected_name)
            else:
                self.assertIsNone(
                    branch.execute(LocalActionExecutionStrategy(), status,
                                   action, acc))