Exemplo n.º 1
0
 def test_execute_with_complex_args(self):
     original_filter = Transform(
         'HelloWorld',
         action_name='sub1_filter1',
         arguments=[Argument('arg1', value={'a': '5.4', 'b': 'string_in'})]
     )
     self.assertEqual(original_filter.execute(LocalActionExecutionStrategy(), 3, {}), '3.0 5.4 string_in')
Exemplo n.º 2
0
 def test_execute_action_with_valid_arguments_and_transforms_invalid_data(self):
     transforms = [Transform('HelloWorld', action_name='mod1_filter2', arguments=[Argument('arg1', value='5')]),
                   Transform('HelloWorld', action_name='Top Transform')]
     # should go <input = invalid> -> <mod1_filter2 with error = invalid> -> <Top Transform with error = invalid>
     # -> <mod1_flag2 4+invalid throws error> -> False
     with self.assertRaises(InvalidArgument):
         Condition('HelloWorld', action_name='mod1_flag2', arguments=[Argument('arg1', value=4)],
                   transforms=transforms).execute('invalid', {})
Exemplo n.º 3
0
 def test_init_with_transforms(self):
     transforms = [
         Transform('HelloWorld',
                   action_name='mod1_filter2',
                   arguments=[Argument('arg1', value='5.4')]),
         Transform(app_name='HelloWorld', action_name='Top Transform')
     ]
     condition = Condition('HelloWorld',
                           action_name='Top Condition',
                           transforms=transforms)
     self.__compare_init(condition, 'HelloWorld', 'Top Condition',
                         transforms, [])
Exemplo n.º 4
0
 def test_execute_action_with_valid_arguments_and_transforms_valid_data(
         self):
     transforms = [
         Transform('HelloWorld',
                   action_name='mod1_filter2',
                   arguments=[Argument('arg1', value='5')]),
         Transform('HelloWorld', action_name='Top Transform')
     ]
     # should go <input = 1> -> <mod1_filter2 = 5+1 = 6> -> <Top Transform 6=6> -> <mod1_flag2 4+6%2==0> -> True
     self.assertTrue(
         Condition('HelloWorld',
                   action_name='mod1_flag2',
                   arguments=[Argument('arg1', value=4)],
                   transforms=transforms).execute(
                       LocalActionExecutionStrategy(), '1', {}))
Exemplo n.º 5
0
 def test_execute_with_args_with_conversion(self):
     self.assertAlmostEqual(
         Transform('HelloWorld',
                   action_name='mod1_filter2',
                   arguments=[Argument('arg1',
                                       value='10.3')]).execute(5.4, {}),
         15.7)
Exemplo n.º 6
0
 def test_init_with_args(self):
     filter_elem = Transform('HelloWorld',
                             action_name='mod1_filter2',
                             arguments=[Argument('arg1', value='5.4')])
     self.__compare_init(filter_elem,
                         'HelloWorld',
                         'mod1_filter2',
                         arguments=[Argument('arg1', value='5.4')])
Exemplo n.º 7
0
 def test_execute_with_args_with_routing(self):
     self.assertAlmostEqual(
         Transform(
             'HelloWorld',
             action_name='mod1_filter2',
             arguments=[Argument('arg1', reference="action1")]
         ).execute(LocalActionExecutionStrategy(), 5.4, {'action1': 10.3}),
         15.7
     )
Exemplo n.º 8
0
 def test_init_with_args_with_routing(self):
     filter_elem = Transform(
         'HelloWorld',
         action_name='mod1_filter2',
         arguments=[Argument('arg1', reference="action1")])
     self.__compare_init(filter_elem,
                         'HelloWorld',
                         'mod1_filter2',
                         arguments=[Argument('arg1', reference="action1")])
Exemplo n.º 9
0
 def test_execute_action_with_valid_arguments_and_transforms_invalid_data_and_routing(
         self):
     transforms = [
         Transform('HelloWorld',
                   action_name='mod1_filter2',
                   arguments=[Argument('arg1', reference='action1')]),
         Transform('HelloWorld', action_name='Top Transform')
     ]
     # should go <input = invalid> -> <mod1_filter2 with error = invalid> -> <Top Transform with error = invalid>
     # -> <mod1_flag2 4+invalid throws error> -> False
     accumulator = {'action1': '5', 'action2': 4}
     self.assertFalse(
         Condition('HelloWorld',
                   action_name='mod1_flag2',
                   arguments=[Argument('arg1', value=4)],
                   transforms=transforms).execute(
                       LocalActionExecutionStrategy(), 'invalid',
                       accumulator))
Exemplo n.º 10
0
def convert_transform(transform):
    arguments = []
    if 'arguments' in transform:
        for argument in transform['arguments']:
            arguments.append(convert_arg(argument))

    transform_obj = Transform(app_name=transform['app_name'], action_name=transform['action_name'],
                              id=transform.get('uid', None), arguments=arguments)

    return transform_obj
Exemplo n.º 11
0
 def test_call_with_args_invalid_input(self):
     self.assertEqual(
         Transform('HelloWorld', action_name='mod1_filter2', arguments=[Argument('arg1', value='10.3')]).execute(
             'invalid', {}),
         'invalid')
Exemplo n.º 12
0
 def test_call_with_nested_complex_args(self):
     args = [Argument('arg', value={'a': '4', 'b': 6, 'c': [1, 2, 3]})]
     original_filter = Transform('HelloWorld', action_name='complex', arguments=args)
     self.assertAlmostEqual(original_filter.execute(3, {}), 19.0)
Exemplo n.º 13
0
 def test_execute_with_filter_which_raises_exception(self):
     self.assertEqual(Transform('HelloWorld', 'sub1_filter3').execute('anything', {}), 'anything')
Exemplo n.º 14
0
 def test_execute_with_invalid_input(self):
     self.assertEqual(Transform('HelloWorld', 'Top Transform').execute('invalid', {}), 'invalid')
Exemplo n.º 15
0
 def test_execute_with_no_args_with_conversion(self):
     self.assertAlmostEqual(Transform('HelloWorld', 'Top Transform').execute('-10.437', {}), -10.437)
Exemplo n.º 16
0
 def test_execute_with_no_args_no_conversion(self):
     self.assertAlmostEqual(Transform('HelloWorld', 'Top Transform').execute(5.4, {}), 5.4)
Exemplo n.º 17
0
 def test_init_with_invalid_arg_type(self):
     with self.assertRaises(InvalidExecutionElement):
         Transform('HelloWorld', action_name='mod1_filter2', arguments=[Argument('arg1', value='invalid')])
Exemplo n.º 18
0
 def test_init_invalid_action(self):
     with self.assertRaises(InvalidExecutionElement):
         Transform('HelloWorld', 'Invalid')
Exemplo n.º 19
0
 def test_init_action_only(self):
     filter_elem = Transform('HelloWorld', 'Top Transform')
     self.__compare_init(filter_elem, 'HelloWorld', 'Top Transform')
Exemplo n.º 20
0
 def test_init_with_invalid_arg_type(self):
     transform = Transform('HelloWorld',
                           action_name='mod1_filter2',
                           arguments=[Argument('arg1', value='invalid')])
     self.assertEqual(len(transform.errors), 2)
Exemplo n.º 21
0
 def test_call_with_nested_complex_args(self):
     args = [Argument('arg', value={'a': '4', 'b': 6, 'c': [1, 2, 3]})]
     original_filter = Transform('HelloWorld', action_name='complex', arguments=args)
     self.assertAlmostEqual(original_filter.execute(LocalActionExecutionStrategy(), 3, {}), 19.0)
Exemplo n.º 22
0
 def test_init_invalid_action(self):
     transform = Transform('HelloWorld', 'Invalid')
     self.assertEqual(len(transform.errors), 1)
Exemplo n.º 23
0
 def test_execute_with_invalid_input(self):
     self.assertEqual(
         Transform('HelloWorld', 'Top Transform').execute(LocalActionExecutionStrategy(), 'invalid', {}),
         'invalid'
     )