def test_get_rendered_params_with_missing_dependency(self): runner_params = {'r1': '{{r3}}', 'r2': '{{r3}}'} test_pass = True try: param_utils.get_rendered_params(runner_params, {}, {}, {}, {}) test_pass = False except actionrunner.ActionRunnerException as e: test_pass = e.message.find('Dependecy') == 0 self.assertTrue(test_pass)
def test_get_rendered_params_with_dict(self): # Note : In this test runner_params.r1 has a string value. However per runner_param_info the # type is an integer. The expected type is considered and cast is performed accordingly. runner_params = {'r1': '{{r2}}', 'r2': {'r2.1': 1}} action_params = {'a1': True, 'a2': '{{a1}}'} runner_param_info = { 'r1': { 'type': 'object' }, 'r2': { 'type': 'object' } } action_param_info = { 'a1': { 'type': 'boolean' }, 'a2': { 'type': 'boolean' } } r_runner_params, r_action_params = param_utils.get_rendered_params( runner_params, action_params, runner_param_info, action_param_info) self.assertEqual(r_runner_params, { 'r1': { 'r2.1': 1 }, 'r2': { 'r2.1': 1 } }) self.assertEqual(r_action_params, {'a1': True, 'a2': True})
def test_get_rendered_params_no_cast(self): runner_params = {'r1': '{{r2}}', 'r2': 1} action_params = {'a1': True, 'a2': '{{r1}} {{a1}}'} runner_param_info = {'r1': {}, 'r2': {}} action_param_info = {'a1': {}, 'a2': {}} r_runner_params, r_action_params = param_utils.get_rendered_params( runner_params, action_params, runner_param_info, action_param_info) self.assertEqual(r_runner_params, {'r1': u'1', 'r2': 1}) self.assertEqual(r_action_params, {'a1': True, 'a2': u'1 True'})
def test_get_rendered_params_empty(self): runner_params = {} action_params = {} runner_param_info = {} action_param_info = {} r_runner_params, r_action_params = param_utils.get_rendered_params( runner_params, action_params, runner_param_info, action_param_info) self.assertEqual(r_runner_params, runner_params) self.assertEqual(r_action_params, action_params)
def test_get_rendered_params_none(self): runner_params = {'r1': None} action_params = {'a1': None} runner_param_info = {'r1': {}} action_param_info = {'a1': {}} r_runner_params, r_action_params = param_utils.get_rendered_params( runner_params, action_params, runner_param_info, action_param_info) self.assertEqual(r_runner_params, runner_params) self.assertEqual(r_action_params, action_params)
def test_get_rendered_params_with_list(self): # Note : In this test runner_params.r1 has a string value. However per runner_param_info the # type is an integer. The expected type is considered and cast is performed accordingly. runner_params = {'r1': '{{r2}}', 'r2': ['1', '2']} action_params = {'a1': True, 'a2': '{{a1}}'} runner_param_info = {'r1': {'type': 'array'}, 'r2': {'type': 'array'}} action_param_info = {'a1': {'type': 'boolean'}, 'a2': {'type': 'boolean'}} r_runner_params, r_action_params = param_utils.get_rendered_params( runner_params, action_params, {}, runner_param_info, action_param_info) self.assertEqual(r_runner_params, {'r1': ['1', '2'], 'r2': ['1', '2']}) self.assertEqual(r_action_params, {'a1': True, 'a2': True})
def test_get_rendered_params_with_cast(self): # Note : In this test runner_params.r1 has a string value. However per runner_param_info the # type is an integer. The expected type is considered and cast is performed accordingly. runner_params = {'r1': '{{r2}}', 'r2': 1} action_params = {'a1': True, 'a2': '{{a1}}', 'a3': '{{action_context.api_user}}'} runner_param_info = {'r1': {'type': 'integer'}, 'r2': {'type': 'integer'}} action_param_info = {'a1': {'type': 'boolean'}, 'a2': {'type': 'boolean'}, 'a3': {}} action_context = {'api_user': '******'} r_runner_params, r_action_params = param_utils.get_rendered_params( runner_params, action_params, action_context, runner_param_info, action_param_info) self.assertEqual(r_runner_params, {'r1': 1, 'r2': 1}) self.assertEqual(r_action_params, {'a1': True, 'a2': True, 'a3': 'noob'})
def test_get_rendered_params_non_existent_template_key_in_action_context(self): runner_params = {'r1': 'foo', 'r2': 2} action_params = {'a1': 'i love tests', 'a2': '{{action_context.lorem_ipsum}}'} runner_param_info = {'r1': {'type': 'string'}, 'r2': {'type': 'integer'}} action_param_info = {'a1': {'type': 'string'}, 'a2': {'type': 'string'}} action_context = {'api_user': '******', 'source_channel': 'reddit'} try: r_runner_params, r_action_params = param_utils.get_rendered_params( runner_params, action_params, action_context, runner_param_info, action_param_info) self.fail('This should have thrown because we are trying to deref a key in ' + 'action context that ain\'t exist.') except actionrunner.ActionRunnerException as e: error_msg = 'Failed to render parameter "a2": \'dict object\' ' + \ 'has no attribute \'lorem_ipsum\'' self.assertTrue(error_msg in e.message) pass
def test_get_rendered_params_with_casting_unicode_values(self): runner_params = {} action_params = {'a1': 'unicode1 ٩(̾●̮̮̃̾•̃̾)۶ unicode2'} runner_param_info = {} action_param_info = {'a1': {'type': 'string'}} r_runner_params, r_action_params = param_utils.get_rendered_params( runner_params, action_params, runner_param_info, action_param_info) expected_action_params = { 'a1': (u'unicode1 \xd9\xa9(\xcc\xbe\xe2\x97\x8f\xcc\xae\xcc\xae\xcc' u'\x83\xcc\xbe\xe2\x80\xa2\xcc\x83\xcc\xbe)\xdb\xb6 unicode2') } self.assertEqual(r_runner_params, {}) self.assertEqual(r_action_params, expected_action_params)