Example #1
0
 def test_execute_with_complex_args(self):
     original_filter = Filter(action='sub1_filter1',
                              args={'arg1': {
                                  'a': '5.4',
                                  'b': 'string_in'
                              }})
     self.assertEqual(original_filter.execute(3, {}), '3.0 5.4 string_in')
Example #2
0
 def __execute_trigger(conditional, data_in):
     filters = [
         Filter(action=filter_element['action'],
                args=Triggers.__to_new_input_format(filter_element['args']))
         for filter_element in conditional['filters']
     ]
     return Flag(action=conditional['action'],
                 args=Triggers.__to_new_input_format(conditional['args']),
                 filters=filters).execute(data_in, {})
Example #3
0
 def test_init_with_args_with_routing(self):
     filter_elem = Filter(action='mod1_filter2', args={'arg1': '@step1'})
     self.__compare_init(filter_elem,
                         'mod1_filter2',
                         args={'arg1': '@step1'})
Example #4
0
 def test_execute_with_args_with_conversion(self):
     self.assertAlmostEqual(
         Filter(action='mod1_filter2', args={
             'arg1': '10.3'
         }).execute(5.4, {}), 15.7)
Example #5
0
 def test_execute_with_args_with_routing(self):
     self.assertAlmostEqual(
         Filter(action='mod1_filter2', args={
             'arg1': '@step1'
         }).execute(5.4, {'step1': 10.3}), 15.7)
Example #6
0
 def test_execute_with_invalid_input(self):
     self.assertEqual(
         Filter(action='Top Filter').execute('invalid', {}), 'invalid')
Example #7
0
 def test_execute_with_filter_which_raises_exception(self):
     self.assertEqual(
         Filter(action='sub1_filter3').execute('anything', {}), 'anything')
Example #8
0
 def test_execute_with_no_args_no_conversion(self):
     self.assertAlmostEqual(
         Filter(action='Top Filter').execute(5.4, {}), 5.4)
Example #9
0
 def test_execute_with_no_args_with_conversion(self):
     self.assertAlmostEqual(
         Filter(action='Top Filter').execute('-10.437', {}), -10.437)
Example #10
0
 def test_call_with_nested_complex_args(self):
     args = {'arg': {'a': '4', 'b': 6, 'c': [1, 2, 3]}}
     original_filter = Filter(action='complex', args=args)
     self.assertAlmostEqual(original_filter.execute(3, {}), 19.0)
Example #11
0
 def test_execute_action_with_valid_args_and_filters_valid_data(self):
     filters = [Filter(action='mod1_filter2', args={'arg1': '5'}), Filter(action='Top Filter')]
     # should go <input = 1> -> <mod1_filter2 = 5+1 = 6> -> <Top Filter 6=6> -> <mod1_flag2 4+6%2==0> -> True
     self.assertTrue(Flag(action='mod1_flag2', args={'arg1': 4}, filters=filters).execute('1', {}))
Example #12
0
 def test_init_with_uid(self):
     uid = uuid.uuid4().hex
     filter_elem = Filter(action='Top Filter', uid=uid)
     self.__compare_init(filter_elem, 'Top Filter', uid=uid)
Example #13
0
 def test_init_with_args(self):
     filter_elem = Filter(action='mod1_filter2', args={'arg1': '5.4'})
     self.__compare_init(filter_elem, 'mod1_filter2', args={'arg1': 5.4})
Example #14
0
 def test_init_invalid_action(self):
     with self.assertRaises(UnknownFilter):
         Filter(action='Invalid')
Example #15
0
 def test_init_action_only(self):
     filter_elem = Filter(action='Top Filter')
     self.__compare_init(filter_elem, 'Top Filter')
Example #16
0
 def test_call_with_args_invalid_input(self):
     self.assertEqual(
         Filter(action='mod1_filter2', args={
             'arg1': '10.3'
         }).execute('invalid', {}), 'invalid')
Example #17
0
 def test_execute_action_with_valid_args_and_filters_invalid_data_and_routing(self):
     filters = [Filter(action='mod1_filter2', args={'arg1': '@step1'}), Filter(action='Top Filter')]
     # should go <input = invalid> -> <mod1_filter2 with error = invalid> -> <Top Filter with error = invalid>
     # -> <mod1_flag2 4+invalid throws error> -> False
     accumulator = {'step1': '5', 'step2': 4}
     self.assertFalse(Flag(action='mod1_flag2', args={'arg1': 4}, filters=filters).execute('invalid', accumulator))
Example #18
0
 def test_execute_action_with_valid_args_and_filters_invalid_data(self):
     filters = [Filter(action='mod1_filter2', args={'arg1': '5'}), Filter(action='Top Filter')]
     # should go <input = invalid> -> <mod1_filter2 with error = invalid> -> <Top Filter with error = invalid>
     # -> <mod1_flag2 4+invalid throws error> -> False
     self.assertFalse(Flag(action='mod1_flag2', args={'arg1': 4}, filters=filters).execute('invalid', {}))
Example #19
0
 def test_init_with_invalid_arg_type(self):
     with self.assertRaises(InvalidInput):
         Filter(action='mod1_filter2', args={'arg1': 'invalid'})
Example #20
0
 def test_init_with_filters(self):
     filters = [Filter(action='mod1_filter2', args={'arg1': '5.4'}), Filter(action='Top Filter')]
     flag = Flag(action='Top Flag', filters=filters)
     self.__compare_init(flag, 'Top Flag', filters, {})