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, {})
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('1', {}))
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 self.assertFalse( Condition('HelloWorld', action_name='mod1_flag2', arguments=[Argument('arg1', value=4)], transforms=transforms).execute('invalid', {}))
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('invalid', accumulator))
def test_execute_with_filter_which_raises_exception(self): self.assertEqual(Transform('HelloWorld', 'sub1_filter3').execute('anything', {}), 'anything')
def test_execute_with_invalid_input(self): self.assertEqual(Transform('HelloWorld', 'Top Transform').execute('invalid', {}), 'invalid')
def test_execute_with_no_args_with_conversion(self): self.assertAlmostEqual(Transform('HelloWorld', 'Top Transform').execute('-10.437', {}), -10.437)
def test_execute_with_no_args_no_conversion(self): self.assertAlmostEqual(Transform('HelloWorld', 'Top Transform').execute(5.4, {}), 5.4)
def test_init_with_invalid_arg_type(self): with self.assertRaises(InvalidArgument): Transform('HelloWorld', action_name='mod1_filter2', arguments=[Argument('arg1', value='invalid')])
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(3, {}), '3.0 5.4 string_in')
def test_init_with_uid(self): uid = uuid.uuid4().hex filter_elem = Transform('HelloWorld', 'Top Transform', uid=uid) self.__compare_init(filter_elem, 'HelloWorld', 'Top Transform', uid=uid)
def test_init_invalid_action(self): with self.assertRaises(UnknownTransform): Transform('HelloWorld', 'Invalid')
def test_init_action_only(self): filter_elem = Transform('HelloWorld', 'Top Transform') self.__compare_init(filter_elem, 'HelloWorld', 'Top Transform')
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')
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)
def test_execute_with_args_with_routing(self): self.assertAlmostEqual( Transform('HelloWorld', action_name='mod1_filter2', arguments=[Argument('arg1', reference="action1")]).execute(5.4, {'action1': 10.3}), 15.7)
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')])
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)
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")])