Exemplo n.º 1
0
    def test_get_finalized_params_with_missing_dependency(self):
        params = {'r1': '{{r3}}', 'r2': '{{r3}}'}
        runner_param_info = {'r1': {}, 'r2': {}}
        action_param_info = {}
        test_pass = True
        try:
            param_utils.get_finalized_params(runner_param_info,
                                             action_param_info,
                                             params,
                                             {'user': None})
            test_pass = False
        except ParamException as e:
            test_pass = six.text_type(e).find('Dependency') == 0
        self.assertTrue(test_pass)

        params = {}
        runner_param_info = {'r1': {'default': '{{r3}}'}, 'r2': {'default': '{{r3}}'}}
        action_param_info = {}
        test_pass = True
        try:
            param_utils.get_finalized_params(runner_param_info,
                                             action_param_info,
                                             params,
                                             {'user': None})
            test_pass = False
        except ParamException as e:
            test_pass = six.text_type(e).find('Dependency') == 0
        self.assertTrue(test_pass)
Exemplo n.º 2
0
    def test_get_finalized_params_order(self):
        params = {"r1": "p1", "r2": "p2", "r3": "p3", "a1": "p4", "a2": "p5"}
        runner_param_info = {"r1": {}, "r2": {"default": "r2"}, "r3": {"default": "r3"}}
        action_param_info = {"a1": {}, "a2": {"default": "a2"}, "r3": {"default": "a3"}}
        action_context = {"api_user": "******"}
        r_runner_params, r_action_params = param_utils.get_finalized_params(
            runner_param_info, action_param_info, params, action_context
        )
        self.assertEqual(r_runner_params, {"r1": u"p1", "r2": u"p2", "r3": u"p3"})
        self.assertEqual(r_action_params, {"a1": u"p4", "a2": u"p5"})

        params = {}
        runner_param_info = {"r1": {}, "r2": {"default": "r2"}, "r3": {"default": "r3"}}
        action_param_info = {"a1": {}, "a2": {"default": "a2"}, "r3": {"default": "a3"}}
        action_context = {"api_user": "******"}
        r_runner_params, r_action_params = param_utils.get_finalized_params(
            runner_param_info, action_param_info, params, action_context
        )
        self.assertEqual(r_runner_params, {"r1": None, "r2": u"r2", "r3": u"a3"})
        self.assertEqual(r_action_params, {"a1": None, "a2": u"a2"})

        params = {}
        runner_param_info = {"r1": {}, "r2": {"default": "r2"}, "r3": {}}
        action_param_info = {"r1": {}, "r2": {}, "r3": {"default": "a3"}}
        action_context = {"api_user": "******"}
        r_runner_params, r_action_params = param_utils.get_finalized_params(
            runner_param_info, action_param_info, params, action_context
        )
        self.assertEqual(r_runner_params, {"r1": None, "r2": u"r2", "r3": u"a3"})
Exemplo n.º 3
0
    def test_get_finalized_params_order(self):
        params = {
            'r1': 'p1',
            'r2': 'p2',
            'r3': 'p3',
            'a1': 'p4',
            'a2': 'p5'
        }
        runner_param_info = {'r1': {}, 'r2': {'default': 'r2'}, 'r3': {'default': 'r3'}}
        action_param_info = {'a1': {}, 'a2': {'default': 'a2'}, 'r3': {'default': 'a3'}}
        action_context = {'api_user': '******'}
        r_runner_params, r_action_params = param_utils.get_finalized_params(
            runner_param_info, action_param_info, params, action_context)
        self.assertEqual(r_runner_params, {'r1': u'p1', 'r2': u'p2', 'r3': u'p3'})
        self.assertEqual(r_action_params, {'a1': u'p4', 'a2': u'p5'})

        params = {}
        runner_param_info = {'r1': {}, 'r2': {'default': 'r2'}, 'r3': {'default': 'r3'}}
        action_param_info = {'a1': {}, 'a2': {'default': 'a2'}, 'r3': {'default': 'a3'}}
        action_context = {'api_user': '******'}
        r_runner_params, r_action_params = param_utils.get_finalized_params(
            runner_param_info, action_param_info, params, action_context)
        self.assertEqual(r_runner_params, {'r1': None, 'r2': u'r2', 'r3': u'a3'})
        self.assertEqual(r_action_params, {'a1': None, 'a2': u'a2'})

        params = {}
        runner_param_info = {'r1': {}, 'r2': {'default': 'r2'}, 'r3': {}}
        action_param_info = {'r1': {}, 'r2': {}, 'r3': {'default': 'a3'}}
        action_context = {'api_user': '******'}
        r_runner_params, r_action_params = param_utils.get_finalized_params(
            runner_param_info, action_param_info, params, action_context)
        self.assertEqual(r_runner_params, {'r1': None, 'r2': u'r2', 'r3': u'a3'})
Exemplo n.º 4
0
 def test_get_finalized_params_with_cyclic_dependency(self):
     params = {"r1": "{{r2}}", "r2": "{{r1}}"}
     runner_param_info = {"r1": {}, "r2": {}}
     action_param_info = {}
     test_pass = True
     try:
         param_utils.get_finalized_params(runner_param_info, action_param_info, params, {})
         test_pass = False
     except ParamException as e:
         test_pass = e.message.find("Cyclic") == 0
     self.assertTrue(test_pass)
Exemplo n.º 5
0
 def test_get_finalized_params_with_cyclic_dependency(self):
     params = {'r1': '{{r2}}', 'r2': '{{r1}}'}
     runner_param_info = {'r1': {}, 'r2': {}}
     action_param_info = {}
     test_pass = True
     try:
         param_utils.get_finalized_params(runner_param_info, action_param_info, params, {})
         test_pass = False
     except ParamException as e:
         test_pass = e.message.find('Cyclic') == 0
     self.assertTrue(test_pass)
Exemplo n.º 6
0
    def test_get_finalized_params_system_values(self):
        KeyValuePair.add_or_update(
            KeyValuePairDB(name='actionstr', value='foo'))
        KeyValuePair.add_or_update(
            KeyValuePairDB(name='actionnumber', value='1.0'))
        params = {'runnerint': 555}
        liveaction_db = self._get_liveaction_model(params)

        runner_params, action_params = param_utils.get_finalized_params(
            ParamsUtilsTest.runnertype_db.runner_parameters,
            ParamsUtilsTest.action_system_default_db.parameters,
            liveaction_db.parameters, liveaction_db.context)

        # Asserts for runner params.
        # Assert that default values for runner params are resolved.
        self.assertEqual(runner_params.get('runnerstr'), 'defaultfoo')
        # Assert that a runner param from action exec is picked up.
        self.assertEqual(runner_params.get('runnerint'), 555)
        # Assert that an immutable param cannot be overridden by action param or execution param.
        self.assertEqual(runner_params.get('runnerimmutable'),
                         'runnerimmutable')

        # Asserts for action params.
        self.assertEqual(action_params.get('actionstr'), 'foo')
        self.assertEqual(action_params.get('actionnumber'), 1.0)
Exemplo n.º 7
0
    def test_get_finalized_param_object_contains_template_notation_in_the_value(self):
        runner_param_info = {'r1': {}}
        action_param_info = {
            'params': {
                'type': 'object',
                'default': {
                    'host': '{{host}}',
                    'port': '{{port}}',
                    'path': '/bar'}
            }
        }
        params = {
            'host': 'lolcathost',
            'port': 5555
        }
        action_context = {}

        r_runner_params, r_action_params = param_utils.get_finalized_params(
            runner_param_info, action_param_info, params, action_context)

        expected_params = {
            'host': 'lolcathost',
            'port': '5555',
            'path': '/bar'
        }
        self.assertEqual(r_action_params['params'], expected_params)
Exemplo n.º 8
0
 def test_get_finalized_params_with_cast_overriden(self):
     params = {
         'r1': '{{r2}}',
         'r2': 1,
         'a1': '{{r1}}',
         'a2': '{{r1}}',
         'a3': '{{r1}}'
     }
     runner_param_info = {
         'r1': {
             'type': 'integer'
         },
         'r2': {
             'type': 'integer'
         }
     }
     action_param_info = {
         'a1': {
             'type': 'boolean'
         },
         'a2': {
             'type': 'string'
         },
         'a3': {
             'type': 'integer'
         },
         'r1': {
             'type': 'string'
         }
     }
     action_context = {'api_user': '******'}
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, action_context)
     self.assertEqual(r_runner_params, {'r1': 1, 'r2': 1})
     self.assertEqual(r_action_params, {'a1': 1, 'a2': u'1', 'a3': 1})
Exemplo n.º 9
0
    def test_get_finalized_params_action_immutable(self):
        params = {
            'actionstr': 'foo',
            'some_key_that_aint_exist_in_action_or_runner': 'bar',
            'runnerint': 555,
            'actionimmutable': 'failed_override'
        }
        liveaction_db = self._get_liveaction_model(params)
        action_context = {'api_user': None}

        runner_params, action_params = param_utils.get_finalized_params(
            ParamsUtilsTest.runnertype_db.runner_parameters,
            ParamsUtilsTest.action_db.parameters, liveaction_db.parameters,
            action_context)

        # Asserts for runner params.
        # Assert that default values for runner params are resolved.
        self.assertEqual(runner_params.get('runnerstr'), 'defaultfoo')
        # Assert that a runner param from action exec is picked up.
        self.assertEqual(runner_params.get('runnerint'), 555)
        # Assert that a runner param can be overridden by action param default.
        self.assertEqual(runner_params.get('runnerdummy'), 'actiondummy')

        # Asserts for action params.
        self.assertEqual(action_params.get('actionstr'), 'foo')
        # Assert that a param that is provided in action exec that isn't in action or runner params
        # isn't in resolved params.
        self.assertEqual(
            action_params.get('some_key_that_aint_exist_in_action_or_runner'),
            None)
Exemplo n.º 10
0
    def test_get_finalized_param_object_contains_template_notation_in_the_value(self):
        runner_param_info = {'r1': {}}
        action_param_info = {
            'params': {
                'type': 'object',
                'default': {
                    'host': '{{host}}',
                    'port': '{{port}}',
                    'path': '/bar'}
            }
        }
        params = {
            'host': 'lolcathost',
            'port': 5555
        }
        action_context = {}

        r_runner_params, r_action_params = param_utils.get_finalized_params(
            runner_param_info, action_param_info, params, action_context)

        expected_params = {
            'host': 'lolcathost',
            'port': 5555,
            'path': '/bar'
        }
        self.assertEqual(r_action_params['params'], expected_params)
Exemplo n.º 11
0
 def test_get_finalized_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.
     params = {
         'r1': '{{r2}}',
         'r2': ['1', '2'],
         'a1': True,
         'a2': 'Test',
         'a3': 'Test2',
         'a4': '{{a1}}',
         'a5': ['{{a2}}', '{{a3}}']
     }
     runner_param_info = {'r1': {'type': 'array'}, 'r2': {'type': 'array'}}
     action_param_info = {
         'a1': {'type': 'boolean'},
         'a2': {'type': 'string'},
         'a3': {'type': 'string'},
         'a4': {'type': 'boolean'},
         'a5': {'type': 'array'}
     }
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, {})
     self.assertEqual(r_runner_params, {'r1': ['1', '2'], 'r2': ['1', '2']})
     self.assertEqual(
         r_action_params,
         {
             'a1': True,
             'a2': 'Test',
             'a3': 'Test2',
             'a4': True,
             'a5': ['Test', 'Test2']
         }
     )
Exemplo n.º 12
0
    def test_get_finalized_params_action_immutable(self):
        params = {
            'actionstr': 'foo',
            'some_key_that_aint_exist_in_action_or_runner': 'bar',
            'runnerint': 555,
            'actionimmutable': 'failed_override'
        }
        liveaction_db = self._get_liveaction_model(params)
        action_context = {'api_user': None}

        runner_params, action_params = param_utils.get_finalized_params(
            ParamsUtilsTest.runnertype_db.runner_parameters,
            ParamsUtilsTest.action_db.parameters,
            liveaction_db.parameters,
            action_context)

        # Asserts for runner params.
        # Assert that default values for runner params are resolved.
        self.assertEqual(runner_params.get('runnerstr'), 'defaultfoo')
        # Assert that a runner param from action exec is picked up.
        self.assertEqual(runner_params.get('runnerint'), 555)
        # Assert that a runner param can be overridden by action param default.
        self.assertEqual(runner_params.get('runnerdummy'), 'actiondummy')

        # Asserts for action params.
        self.assertEqual(action_params.get('actionstr'), 'foo')
        # Assert that a param that is provided in action exec that isn't in action or runner params
        # isn't in resolved params.
        self.assertEqual(action_params.get('some_key_that_aint_exist_in_action_or_runner'), None)
Exemplo n.º 13
0
    def test_get_finalized_params_system_values(self):
        KeyValuePair.add_or_update(KeyValuePairDB(name='actionstr', value='foo'))
        KeyValuePair.add_or_update(KeyValuePairDB(name='actionnumber', value='1.0'))
        params = {
            'runnerint': 555
        }
        liveaction_db = self._get_liveaction_model(params)

        runner_params, action_params = param_utils.get_finalized_params(
            ParamsUtilsTest.runnertype_db.runner_parameters,
            ParamsUtilsTest.action_system_default_db.parameters,
            liveaction_db.parameters,
            liveaction_db.context)

        # Asserts for runner params.
        # Assert that default values for runner params are resolved.
        self.assertEqual(runner_params.get('runnerstr'), 'defaultfoo')
        # Assert that a runner param from action exec is picked up.
        self.assertEqual(runner_params.get('runnerint'), 555)
        # Assert that an immutable param cannot be overridden by action param or execution param.
        self.assertEqual(runner_params.get('runnerimmutable'), 'runnerimmutable')

        # Asserts for action params.
        self.assertEqual(action_params.get('actionstr'), 'foo')
        self.assertEqual(action_params.get('actionnumber'), 1.0)
Exemplo n.º 14
0
    def test_get_finalized_params_action_immutable(self):
        params = {
            "actionstr": "foo",
            "some_key_that_aint_exist_in_action_or_runner": "bar",
            "runnerint": 555,
            "actionimmutable": "failed_override",
        }
        liveaction_db = self._get_liveaction_model(params)
        action_context = {"api_user": None}

        runner_params, action_params = param_utils.get_finalized_params(
            ParamsUtilsTest.runnertype_db.runner_parameters,
            ParamsUtilsTest.action_db.parameters,
            liveaction_db.parameters,
            action_context,
        )

        # Asserts for runner params.
        # Assert that default values for runner params are resolved.
        self.assertEqual(runner_params.get("runnerstr"), "defaultfoo")
        # Assert that a runner param from action exec is picked up.
        self.assertEqual(runner_params.get("runnerint"), 555)
        # Assert that a runner param can be overridden by action param default.
        self.assertEqual(runner_params.get("runnerdummy"), "actiondummy")

        # Asserts for action params.
        self.assertEqual(action_params.get("actionstr"), "foo")
        # Assert that a param that is provided in action exec that isn't in action or runner params
        # isn't in resolved params.
        self.assertEqual(action_params.get("some_key_that_aint_exist_in_action_or_runner"), None)
Exemplo n.º 15
0
 def test_get_finalized_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.
     params = {
         "r1": "{{r2}}",
         "r2": ["1", "2"],
         "a1": True,
         "a2": "Test",
         "a3": "Test2",
         "a4": "{{a1}}",
         "a5": ["{{a2}}", "{{a3}}"],
     }
     runner_param_info = {"r1": {"type": "array"}, "r2": {"type": "array"}}
     action_param_info = {
         "a1": {"type": "boolean"},
         "a2": {"type": "string"},
         "a3": {"type": "string"},
         "a4": {"type": "boolean"},
         "a5": {"type": "array"},
     }
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, {}
     )
     self.assertEqual(r_runner_params, {"r1": ["1", "2"], "r2": ["1", "2"]})
     self.assertEqual(
         r_action_params, {"a1": True, "a2": "Test", "a3": "Test2", "a4": True, "a5": ["Test", "Test2"]}
     )
Exemplo n.º 16
0
 def test_get_finalized_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.
     params = {
         'r1': '{{r2}}',
         'r2': {'r2.1': 1},
         'a1': True,
         'a2': '{{a1}}',
         'a3': {
             'test': '{{a1}}',
             'test1': '{{a4}}',
             'test2': '{{a5}}',
         },
         'a4': 3,
         'a5': ['1', '{{a1}}']
     }
     runner_param_info = {'r1': {'type': 'object'}, 'r2': {'type': 'object'}}
     action_param_info = {
         'a1': {
             'type': 'boolean',
         },
         'a2': {
             'type': 'boolean',
         },
         'a3': {
             'type': 'object',
         },
         'a4': {
             'type': 'integer',
         },
         'a5': {
             'type': 'array',
         },
     }
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, {})
     self.assertEqual(
         r_runner_params, {'r1': {'r2.1': 1}, 'r2': {'r2.1': 1}})
     self.assertEqual(
         r_action_params,
         {
             'a1': True,
             'a2': True,
             'a3': {
                 'test': True,
                 'test1': 3,
                 'test2': [
                     '1',
                     True
                 ],
             },
             'a4': 3,
             'a5': [
                 '1',
                 True
             ],
         }
     )
 def test_get_finalized_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.
     params = {
         'r1': '{{r2}}',
         'r2': {'r2.1': 1},
         'a1': True,
         'a2': '{{a1}}',
         'a3': {
             'test': '{{a1}}',
             'test1': '{{a4}}',
             'test2': '{{a5}}',
         },
         'a4': 3,
         'a5': ['1', '{{a1}}']
     }
     runner_param_info = {'r1': {'type': 'object'}, 'r2': {'type': 'object'}}
     action_param_info = {
         'a1': {
             'type': 'boolean',
         },
         'a2': {
             'type': 'boolean',
         },
         'a3': {
             'type': 'object',
         },
         'a4': {
             'type': 'integer',
         },
         'a5': {
             'type': 'array',
         },
     }
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, {})
     self.assertEqual(
         r_runner_params, {'r1': {'r2.1': 1}, 'r2': {'r2.1': 1}})
     self.assertEqual(
         r_action_params,
         {
             'a1': True,
             'a2': True,
             'a3': {
                 'test': True,
                 'test1': 3,
                 'test2': [
                     '1',
                     True
                 ],
             },
             'a4': 3,
             'a5': [
                 '1',
                 True
             ],
         }
     )
Exemplo n.º 18
0
 def test_get_finalized_params_no_double_rendering(self):
     params = {'r1': '{{ action_context.h1 }}{{ action_context.h2 }}'}
     runner_param_info = {'r1': {}}
     action_param_info = {}
     action_context = {'h1': '{', 'h2': '{ missing }}', 'user': None}
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, action_context)
     self.assertEqual(r_runner_params, {'r1': '{{ missing }}'})
     self.assertEqual(r_action_params, {})
Exemplo n.º 19
0
 def test_get_finalized_params_none(self):
     params = {'r1': None, 'a1': None}
     runner_param_info = {'r1': {}}
     action_param_info = {'a1': {}}
     action_context = {'api_user': None}
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, action_context)
     self.assertEqual(r_runner_params, {'r1': None})
     self.assertEqual(r_action_params, {'a1': None})
Exemplo n.º 20
0
 def test_get_finalized_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.
     self.maxDiff = None
     params = {
         "r1": "{{r2}}",
         "r2": ["1", "2"],
         "a1": True,
         "a2": "Test",
         "a3": "Test2",
         "a4": "{{a1}}",
         "a5": ["{{a2}}", "{{a3}}"],
         "a6": [
             ["{{r2}}", "{{a2}}"],
             ["{{a3}}", "{{a1}}"],
             [
                 "{{a7}}",
                 "This should be rendered as a string {{a1}}",
                 "{{a1}} This, too, should be rendered as a string {{a1}}",
             ],
         ],
         "a7": 5,
     }
     runner_param_info = {"r1": {"type": "array"}, "r2": {"type": "array"}}
     action_param_info = {
         "a1": {"type": "boolean"},
         "a2": {"type": "string"},
         "a3": {"type": "string"},
         "a4": {"type": "boolean"},
         "a5": {"type": "array"},
         "a6": {"type": "array"},
         "a7": {"type": "integer"},
     }
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, {"user": None}
     )
     self.assertEqual(r_runner_params, {"r1": ["1", "2"], "r2": ["1", "2"]})
     self.assertEqual(
         r_action_params,
         {
             "a1": True,
             "a2": "Test",
             "a3": "Test2",
             "a4": True,
             "a5": ["Test", "Test2"],
             "a6": [
                 [["1", "2"], "Test"],
                 ["Test2", True],
                 [
                     5,
                     "This should be rendered as a string True",
                     "True This, too, should be rendered as a string True",
                 ],
             ],
             "a7": 5,
         },
     )
 def test_get_finalized_params_empty(self):
     params = {}
     runner_param_info = {}
     action_param_info = {}
     action_context = {}
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, action_context)
     self.assertEqual(r_runner_params, params)
     self.assertEqual(r_action_params, params)
Exemplo n.º 22
0
 def test_get_finalized_params_empty(self):
     params = {}
     runner_param_info = {}
     action_param_info = {}
     action_context = {}
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, action_context)
     self.assertEqual(r_runner_params, params)
     self.assertEqual(r_action_params, params)
Exemplo n.º 23
0
 def test_get_finalized_params_no_double_rendering(self):
     params = {"r1": "{{ action_context.h1 }}{{ action_context.h2 }}"}
     runner_param_info = {"r1": {}}
     action_param_info = {}
     action_context = {"h1": "{", "h2": "{ missing }}", "user": None}
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, action_context)
     self.assertEqual(r_runner_params, {"r1": "{{ missing }}"})
     self.assertEqual(r_action_params, {})
Exemplo n.º 24
0
 def test_get_finalized_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.
     self.maxDiff = None
     params = {
         'r1': '{{r2}}',
         'r2': ['1', '2'],
         'a1': True,
         'a2': 'Test',
         'a3': 'Test2',
         'a4': '{{a1}}',
         'a5': ['{{a2}}', '{{a3}}'],
         'a6': [
             ['{{r2}}', '{{a2}}'],
             ['{{a3}}', '{{a1}}'],
             [
                 '{{a7}}',
                 'This should be rendered as a string {{a1}}',
                 '{{a1}} This, too, should be rendered as a string {{a1}}',
             ]
         ],
         'a7': 5,
     }
     runner_param_info = {'r1': {'type': 'array'}, 'r2': {'type': 'array'}}
     action_param_info = {
         'a1': {'type': 'boolean'},
         'a2': {'type': 'string'},
         'a3': {'type': 'string'},
         'a4': {'type': 'boolean'},
         'a5': {'type': 'array'},
         'a6': {'type': 'array'},
         'a7': {'type': 'integer'},
     }
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, {})
     self.assertEqual(r_runner_params, {'r1': ['1', '2'], 'r2': ['1', '2']})
     self.assertEqual(
         r_action_params,
         {
             'a1': True,
             'a2': 'Test',
             'a3': 'Test2',
             'a4': True,
             'a5': ['Test', 'Test2'],
             'a6': [
                 [['1', '2'], 'Test'],
                 ['Test2', True],
                 [
                     5,
                     u'This should be rendered as a string True',
                     u'True This, too, should be rendered as a string True'
                 ]
             ],
             'a7': 5,
         }
     )
 def test_get_finalized_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.
     self.maxDiff = None
     params = {
         'r1': '{{r2}}',
         'r2': ['1', '2'],
         'a1': True,
         'a2': 'Test',
         'a3': 'Test2',
         'a4': '{{a1}}',
         'a5': ['{{a2}}', '{{a3}}'],
         'a6': [
             ['{{r2}}', '{{a2}}'],
             ['{{a3}}', '{{a1}}'],
             [
                 '{{a7}}',
                 'This should be rendered as a string {{a1}}',
                 '{{a1}} This, too, should be rendered as a string {{a1}}',
             ]
         ],
         'a7': 5,
     }
     runner_param_info = {'r1': {'type': 'array'}, 'r2': {'type': 'array'}}
     action_param_info = {
         'a1': {'type': 'boolean'},
         'a2': {'type': 'string'},
         'a3': {'type': 'string'},
         'a4': {'type': 'boolean'},
         'a5': {'type': 'array'},
         'a6': {'type': 'array'},
         'a7': {'type': 'integer'},
     }
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, {})
     self.assertEqual(r_runner_params, {'r1': ['1', '2'], 'r2': ['1', '2']})
     self.assertEqual(
         r_action_params,
         {
             'a1': True,
             'a2': 'Test',
             'a3': 'Test2',
             'a4': True,
             'a5': ['Test', 'Test2'],
             'a6': [
                 [['1', '2'], 'Test'],
                 ['Test2', True],
                 [
                     5,
                     u'This should be rendered as a string True',
                     u'True This, too, should be rendered as a string True'
                 ]
             ],
             'a7': 5,
         }
     )
    def test_get_finalized_params_jinja_filters(self):
        params = {'cmd': 'echo {{"1.6.0" | version_bump_minor}}'}
        runner_param_info = {'r1': {}}
        action_param_info = {'cmd': {}}
        action_context = {}

        r_runner_params, r_action_params = param_utils.get_finalized_params(
            runner_param_info, action_param_info, params, action_context)

        self.assertEqual(r_action_params['cmd'], "echo 1.7.0")
Exemplo n.º 27
0
 def test_get_finalized_params_no_double_rendering(self):
     params = {"r1": "{{ action_context.h1 }}{{ action_context.h2 }}"}
     runner_param_info = {"r1": {}}
     action_param_info = {}
     action_context = {"h1": "{", "h2": "{ missing }}"}
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, action_context
     )
     self.assertEqual(r_runner_params, {"r1": "{{ missing }}"})
     self.assertEqual(r_action_params, {})
Exemplo n.º 28
0
 def test_get_finalized_params_cross_talk_no_cast(self):
     params = {"r1": "{{a1}}", "r2": 1, "a1": True, "a2": "{{r1}} {{a1}}", "a3": "{{action_context.api_user}}"}
     runner_param_info = {"r1": {}, "r2": {}}
     action_param_info = {"a1": {}, "a2": {}, "a3": {}}
     action_context = {"api_user": "******"}
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, action_context
     )
     self.assertEqual(r_runner_params, {"r1": u"True", "r2": 1})
     self.assertEqual(r_action_params, {"a1": True, "a2": u"True True", "a3": "noob"})
Exemplo n.º 29
0
 def test_get_finalized_params_none(self):
     params = {"r1": None, "a1": None}
     runner_param_info = {"r1": {}}
     action_param_info = {"a1": {}}
     action_context = {"api_user": None}
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, action_context
     )
     self.assertEqual(r_runner_params, {"r1": None})
     self.assertEqual(r_action_params, {"a1": None})
Exemplo n.º 30
0
 def test_get_finalized_params_cross_talk_with_cast(self):
     params = {"r1": "{{a1}}", "r2": 1, "r3": 1, "a1": True, "a2": "{{r1}},{{a1}},{{a3}},{{r3}}", "a3": "{{a1}}"}
     runner_param_info = {"r1": {"type": "boolean"}, "r2": {"type": "integer"}, "r3": {}}
     action_param_info = {"a1": {"type": "boolean"}, "a2": {"type": "array"}, "a3": {}}
     action_context = {}
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, action_context
     )
     self.assertEqual(r_runner_params, {"r1": True, "r2": 1, "r3": 1})
     self.assertEqual(r_action_params, {"a1": True, "a2": (True, True, True, 1), "a3": u"True"})
Exemplo n.º 31
0
    def test_get_finalized_params_jinja_filters(self):
        params = {'cmd': 'echo {{"1.6.0" | version_bump_minor}}'}
        runner_param_info = {'r1': {}}
        action_param_info = {'cmd': {}}
        action_context = {}

        r_runner_params, r_action_params = param_utils.get_finalized_params(
            runner_param_info, action_param_info, params, action_context)

        self.assertEqual(r_action_params['cmd'], "echo 1.7.0")
Exemplo n.º 32
0
 def test_get_finalized_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.
     params = {"r1": "{{r2}}", "r2": {"r2.1": 1}, "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_finalized_params(
         runner_param_info, action_param_info, params, {}
     )
     self.assertEqual(r_runner_params, {"r1": {"r2.1": 1}, "r2": {"r2.1": 1}})
     self.assertEqual(r_action_params, {"a1": True, "a2": True})
Exemplo n.º 33
0
 def test_get_finalized_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.
     params = {
         "r1": "{{r2}}",
         "r2": {"r2.1": 1},
         "a1": True,
         "a2": "{{a1}}",
         "a3": {
             "test": "{{a1}}",
             "test1": "{{a4}}",
             "test2": "{{a5}}",
         },
         "a4": 3,
         "a5": ["1", "{{a1}}"],
     }
     runner_param_info = {"r1": {"type": "object"}, "r2": {"type": "object"}}
     action_param_info = {
         "a1": {
             "type": "boolean",
         },
         "a2": {
             "type": "boolean",
         },
         "a3": {
             "type": "object",
         },
         "a4": {
             "type": "integer",
         },
         "a5": {
             "type": "array",
         },
     }
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, {"user": None}
     )
     self.assertEqual(r_runner_params, {"r1": {"r2.1": 1}, "r2": {"r2.1": 1}})
     self.assertEqual(
         r_action_params,
         {
             "a1": True,
             "a2": True,
             "a3": {
                 "test": True,
                 "test1": 3,
                 "test2": ["1", True],
             },
             "a4": 3,
             "a5": ["1", True],
         },
     )
Exemplo n.º 34
0
    def test_get_finalized_params_with_missing_dependency(self):
        params = {"r1": "{{r3}}", "r2": "{{r3}}"}
        runner_param_info = {"r1": {}, "r2": {}}
        action_param_info = {}
        test_pass = True
        try:
            param_utils.get_finalized_params(runner_param_info, action_param_info, params, {})
            test_pass = False
        except ParamException as e:
            test_pass = e.message.find("Dependecy") == 0
        self.assertTrue(test_pass)

        params = {}
        runner_param_info = {"r1": {"default": "{{r3}}"}, "r2": {"default": "{{r3}}"}}
        action_param_info = {}
        test_pass = True
        try:
            param_utils.get_finalized_params(runner_param_info, action_param_info, params, {})
            test_pass = False
        except ParamException as e:
            test_pass = e.message.find("Dependecy") == 0
        self.assertTrue(test_pass)
    def test_get_finalized_params_with_missing_dependency(self):
        params = {'r1': '{{r3}}', 'r2': '{{r3}}'}
        runner_param_info = {'r1': {}, 'r2': {}}
        action_param_info = {}
        test_pass = True
        try:
            param_utils.get_finalized_params(runner_param_info, action_param_info, params, {})
            test_pass = False
        except ParamException as e:
            test_pass = e.message.find('Dependecy') == 0
        self.assertTrue(test_pass)

        params = {}
        runner_param_info = {'r1': {'default': '{{r3}}'}, 'r2': {'default': '{{r3}}'}}
        action_param_info = {}
        test_pass = True
        try:
            param_utils.get_finalized_params(runner_param_info, action_param_info, params, {})
            test_pass = False
        except ParamException as e:
            test_pass = e.message.find('Dependecy') == 0
        self.assertTrue(test_pass)
Exemplo n.º 36
0
 def test_get_finalized_params_no_double_rendering(self):
     params = {
         'r1': '{{ action_context.h1 }}{{ action_context.h2 }}'
     }
     runner_param_info = {'r1': {}}
     action_param_info = {}
     action_context = {
         'h1': '{',
         'h2': '{ missing }}'
     }
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, action_context)
     self.assertEqual(r_runner_params, {'r1': '{{ missing }}'})
     self.assertEqual(r_action_params, {})
Exemplo n.º 37
0
    def test_get_finalized_param_object_contains_template_notation_in_the_value(self):
        runner_param_info = {"r1": {}}
        action_param_info = {
            "params": {"type": "object", "default": {"host": "{{host}}", "port": "{{port}}", "path": "/bar"}}
        }
        params = {"host": "lolcathost", "port": 5555}
        action_context = {}

        r_runner_params, r_action_params = param_utils.get_finalized_params(
            runner_param_info, action_param_info, params, action_context
        )

        expected_params = {"host": "lolcathost", "port": "5555", "path": "/bar"}
        self.assertEqual(r_action_params["params"], expected_params)
Exemplo n.º 38
0
 def test_get_finalized_params_with_cast_overriden(self):
     params = {"r1": "{{r2}}", "r2": 1, "a1": "{{r1}}", "a2": "{{r1}}", "a3": "{{r1}}"}
     runner_param_info = {"r1": {"type": "integer"}, "r2": {"type": "integer"}}
     action_param_info = {
         "a1": {"type": "boolean"},
         "a2": {"type": "string"},
         "a3": {"type": "integer"},
         "r1": {"type": "string"},
     }
     action_context = {"api_user": "******"}
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, action_context
     )
     self.assertEqual(r_runner_params, {"r1": 1, "r2": 1})
     self.assertEqual(r_action_params, {"a1": 1, "a2": u"1", "a3": 1})
 def test_get_finalized_params_cross_talk_no_cast(self):
     params = {
         'r1': '{{a1}}',
         'r2': 1,
         'a1': True,
         'a2': '{{r1}} {{a1}}',
         'a3': '{{action_context.api_user}}'
     }
     runner_param_info = {'r1': {}, 'r2': {}}
     action_param_info = {'a1': {}, 'a2': {}, 'a3': {}}
     action_context = {'api_user': '******'}
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, action_context)
     self.assertEqual(r_runner_params, {'r1': u'True', 'r2': 1})
     self.assertEqual(r_action_params, {'a1': True, 'a2': u'True True', 'a3': 'noob'})
Exemplo n.º 40
0
 def test_get_finalized_params_cross_talk_no_cast(self):
     params = {
         'r1': '{{a1}}',
         'r2': 1,
         'a1': True,
         'a2': '{{r1}} {{a1}}',
         'a3': '{{action_context.api_user}}'
     }
     runner_param_info = {'r1': {}, 'r2': {}}
     action_param_info = {'a1': {}, 'a2': {}, 'a3': {}}
     action_context = {'api_user': '******'}
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, action_context)
     self.assertEqual(r_runner_params, {'r1': u'True', 'r2': 1})
     self.assertEqual(r_action_params, {'a1': True, 'a2': u'True True', 'a3': 'noob'})
Exemplo n.º 41
0
 def test_get_finalized_params_cross_talk_with_cast(self):
     params = {
         'r1': '{{a1}}',
         'r2': 1,
         'r3': 1,
         'a1': True,
         'a2': '{{r1}},{{a1}},{{a3}},{{r3}}',
         'a3': '{{a1}}'
     }
     runner_param_info = {'r1': {'type': 'boolean'}, 'r2': {'type': 'integer'}, 'r3': {}}
     action_param_info = {'a1': {'type': 'boolean'}, 'a2': {'type': 'array'}, 'a3': {}}
     action_context = {}
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, action_context)
     self.assertEqual(r_runner_params, {'r1': True, 'r2': 1, 'r3': 1})
     self.assertEqual(r_action_params, {'a1': True, 'a2': (True, True, True, 1), 'a3': u'True'})
Exemplo n.º 42
0
 def test_get_finalized_params_non_existent_template_key_in_action_context(self):
     params = {"r1": "foo", "r2": 2, "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_finalized_params(
             runner_param_info, action_param_info, params, action_context
         )
         self.fail(
             "This should have thrown because we are trying to deref a key in " + "action context that ain't exist."
         )
     except ParamException as e:
         error_msg = "Failed to render parameter \"a2\": 'dict object' " + "has no attribute 'lorem_ipsum'"
         self.assertTrue(error_msg in e.message)
         pass
Exemplo n.º 43
0
 def test_get_finalized_params_cross_talk_no_cast(self):
     params = {
         "r1": "{{a1}}",
         "r2": 1,
         "a1": True,
         "a2": "{{r1}} {{a1}}",
         "a3": "{{action_context.api_user}}",
     }
     runner_param_info = {"r1": {}, "r2": {}}
     action_param_info = {"a1": {}, "a2": {}, "a3": {}}
     action_context = {"api_user": "******"}
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, action_context
     )
     self.assertEqual(r_runner_params, {"r1": "True", "r2": 1})
     self.assertEqual(r_action_params, {"a1": True, "a2": "True True", "a3": "noob"})
Exemplo n.º 44
0
 def test_get_finalized_params_with_cast_overriden(self):
     params = {
         'r1': '{{r2}}',
         'r2': 1,
         'a1': '{{r1}}',
         'a2': '{{r1}}',
         'a3': '{{r1}}'
     }
     runner_param_info = {'r1': {'type': 'integer'}, 'r2': {'type': 'integer'}}
     action_param_info = {'a1': {'type': 'boolean'}, 'a2': {'type': 'string'},
                          'a3': {'type': 'integer'}, 'r1': {'type': 'string'}}
     action_context = {'api_user': '******'}
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, action_context)
     self.assertEqual(r_runner_params, {'r1': 1, 'r2': 1})
     self.assertEqual(r_action_params, {'a1': 1, 'a2': u'1', 'a3': 1})
 def test_get_finalized_params_cross_talk_with_cast(self):
     params = {
         'r1': '{{a1}}',
         'r2': 1,
         'r3': 1,
         'a1': True,
         'a2': '{{r1}},{{a1}},{{a3}},{{r3}}',
         'a3': '{{a1}}'
     }
     runner_param_info = {'r1': {'type': 'boolean'}, 'r2': {'type': 'integer'}, 'r3': {}}
     action_param_info = {'a1': {'type': 'boolean'}, 'a2': {'type': 'array'}, 'a3': {}}
     action_context = {}
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, action_context)
     self.assertEqual(r_runner_params, {'r1': True, 'r2': 1, 'r3': 1})
     self.assertEqual(r_action_params, {'a1': True, 'a2': (True, True, True, 1), 'a3': u'True'})
Exemplo n.º 46
0
    def test_get_finalized_params(self):
        params = {
            "actionstr": "foo",
            "some_key_that_aint_exist_in_action_or_runner": "bar",
            "runnerint": 555,
            "runnerimmutable": "failed_override",
            "actionimmutable": "failed_override",
        }
        liveaction_db = self._get_liveaction_model(params)

        runner_params, action_params = param_utils.get_finalized_params(
            ParamsUtilsTest.runnertype_db.runner_parameters,
            ParamsUtilsTest.action_db.parameters,
            liveaction_db.parameters,
            liveaction_db.context,
        )

        # Asserts for runner params.
        # Assert that default values for runner params are resolved.
        self.assertEqual(runner_params.get("runnerstr"), "defaultfoo")
        # Assert that a runner param from action exec is picked up.
        self.assertEqual(runner_params.get("runnerint"), 555)
        # Assert that a runner param can be overridden by action param default.
        self.assertEqual(runner_params.get("runnerdummy"), "actiondummy")
        # Assert that a runner param default can be overridden by 'falsey' action param default,
        # (timeout: 0 case).
        self.assertEqual(runner_params.get("runnerdefaultint"), 0)
        # Assert that an immutable param cannot be overridden by action param or execution param.
        self.assertEqual(runner_params.get("runnerimmutable"),
                         "runnerimmutable")

        # Asserts for action params.
        self.assertEqual(action_params.get("actionstr"), "foo")
        # Assert that a param that is provided in action exec that isn't in action or runner params
        # isn't in resolved params.
        self.assertEqual(
            action_params.get("some_key_that_aint_exist_in_action_or_runner"),
            None)
        # Assert that an immutable param cannot be overridden by execution param.
        self.assertEqual(action_params.get("actionimmutable"),
                         "actionimmutable")
        # Assert that an action context param is set correctly.
        self.assertEqual(action_params.get("action_api_user"), "noob")
        # Assert that none of runner params are present in action_params.
        for k in action_params:
            self.assertNotIn(k, runner_params,
                             "Param " + k + " is a runner param.")
 def test_get_finalized_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.
     params = {
         'r1': '{{r2}}',
         'r2': 1,
         '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_finalized_params(
         runner_param_info, action_param_info, params, action_context)
     self.assertEqual(r_runner_params, {'r1': 1, 'r2': 1})
     self.assertEqual(r_action_params, {'a1': True, 'a2': True, 'a3': 'noob'})
Exemplo n.º 48
0
 def test_get_finalized_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.
     params = {
         'r1': '{{r2}}',
         'r2': 1,
         '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_finalized_params(
         runner_param_info, action_param_info, params, action_context)
     self.assertEqual(r_runner_params, {'r1': 1, 'r2': 1})
     self.assertEqual(r_action_params, {'a1': True, 'a2': True, 'a3': 'noob'})
Exemplo n.º 49
0
    def test_get_finalized_param_object_contains_template_notation_in_the_value(self):
        runner_param_info = {"r1": {}}
        action_param_info = {
            "params": {
                "type": "object",
                "default": {"host": "{{host}}", "port": "{{port}}", "path": "/bar"},
            }
        }
        params = {"host": "lolcathost", "port": 5555}
        action_context = {"user": None}

        r_runner_params, r_action_params = param_utils.get_finalized_params(
            runner_param_info, action_param_info, params, action_context
        )

        expected_params = {"host": "lolcathost", "port": 5555, "path": "/bar"}
        self.assertEqual(r_action_params["params"], expected_params)
    def test_get_finalized_params_with_casting_unicode_values(self):
        params = {'a1': 'unicode1 ٩(̾●̮̮̃̾•̃̾)۶ unicode2'}

        runner_param_info = {}
        action_param_info = {'a1': {'type': 'string'}}

        action_context = {}

        r_runner_params, r_action_params = param_utils.get_finalized_params(
            runner_param_info, action_param_info, params, action_context)

        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)
Exemplo n.º 51
0
 def test_get_finalized_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.
     params = {'r1': '{{r2}}', 'r2': ['1', '2'], '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_finalized_params(
         runner_param_info, action_param_info, params, {})
     self.assertEqual(r_runner_params, {'r1': ['1', '2'], 'r2': ['1', '2']})
     self.assertEqual(r_action_params, {'a1': True, 'a2': True})
Exemplo n.º 52
0
    def test_get_finalized_params_with_casting_unicode_values(self):
        params = {'a1': 'unicode1 ٩(̾●̮̮̃̾•̃̾)۶ unicode2'}

        runner_param_info = {}
        action_param_info = {'a1': {'type': 'string'}}

        action_context = {}

        r_runner_params, r_action_params = param_utils.get_finalized_params(
            runner_param_info, action_param_info, params, action_context)

        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)
Exemplo n.º 53
0
    def test_get_finalized_params_with_config(self):
        with mock.patch('st2common.util.config_loader.ContentPackConfigLoader'
                        ) as config_loader:
            config_loader().get_config.return_value = {
                'generic_config_param': 'So generic'
            }

            params = {
                'config_param': '{{config_context.generic_config_param}}',
            }
            liveaction_db = self._get_liveaction_model(params, True)

            _, action_params = param_utils.get_finalized_params(
                ParamsUtilsTest.runnertype_db.runner_parameters,
                ParamsUtilsTest.action_db.parameters, liveaction_db.parameters,
                liveaction_db.context)
            self.assertEqual(action_params.get('config_param'), 'So generic')
Exemplo n.º 54
0
    def test_get_finalized_params(self):
        params = {
            'actionstr': 'foo',
            'some_key_that_aint_exist_in_action_or_runner': 'bar',
            'runnerint': 555,
            'runnerimmutable': 'failed_override',
            'actionimmutable': 'failed_override'
        }
        liveaction_db = self._get_liveaction_model(params)

        runner_params, action_params = param_utils.get_finalized_params(
            ParamsUtilsTest.runnertype_db.runner_parameters,
            ParamsUtilsTest.action_db.parameters, liveaction_db.parameters,
            liveaction_db.context)

        # Asserts for runner params.
        # Assert that default values for runner params are resolved.
        self.assertEqual(runner_params.get('runnerstr'), 'defaultfoo')
        # Assert that a runner param from action exec is picked up.
        self.assertEqual(runner_params.get('runnerint'), 555)
        # Assert that a runner param can be overridden by action param default.
        self.assertEqual(runner_params.get('runnerdummy'), 'actiondummy')
        # Assert that a runner param default can be overridden by 'falsey' action param default,
        # (timeout: 0 case).
        self.assertEqual(runner_params.get('runnerdefaultint'), 0)
        # Assert that an immutable param cannot be overridden by action param or execution param.
        self.assertEqual(runner_params.get('runnerimmutable'),
                         'runnerimmutable')

        # Asserts for action params.
        self.assertEqual(action_params.get('actionstr'), 'foo')
        # Assert that a param that is provided in action exec that isn't in action or runner params
        # isn't in resolved params.
        self.assertEqual(
            action_params.get('some_key_that_aint_exist_in_action_or_runner'),
            None)
        # Assert that an immutable param cannot be overridden by execution param.
        self.assertEqual(action_params.get('actionimmutable'),
                         'actionimmutable')
        # Assert that an action context param is set correctly.
        self.assertEqual(action_params.get('action_api_user'), 'noob')
        # Assert that none of runner params are present in action_params.
        for k in action_params:
            self.assertTrue(k not in runner_params,
                            'Param ' + k + ' is a runner param.')
Exemplo n.º 55
0
    def test_get_finalized_params_with_config(self):
        with mock.patch("st2common.util.config_loader.ContentPackConfigLoader"
                        ) as config_loader:
            config_loader().get_config.return_value = {
                "generic_config_param": "So generic"
            }

            params = {
                "config_param": "{{config_context.generic_config_param}}",
            }
            liveaction_db = self._get_liveaction_model(params, True)

            _, action_params = param_utils.get_finalized_params(
                ParamsUtilsTest.runnertype_db.runner_parameters,
                ParamsUtilsTest.action_db.parameters,
                liveaction_db.parameters,
                liveaction_db.context,
            )
            self.assertEqual(action_params.get("config_param"), "So generic")
 def test_get_finalized_params_non_existent_template_key_in_action_context(self):
     params = {
         'r1': 'foo',
         'r2': 2,
         '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_finalized_params(
             runner_param_info, action_param_info, params, action_context)
         self.fail('This should have thrown because we are trying to deref a key in ' +
                   'action context that ain\'t exist.')
     except ParamException as e:
         error_msg = 'Failed to render parameter "a2": \'dict object\' ' + \
                     'has no attribute \'lorem_ipsum\''
         self.assertTrue(error_msg in e.message)
         pass
Exemplo n.º 57
0
 def test_get_finalized_params_with_cast_overriden(self):
     params = {
         "r1": "{{r2}}",
         "r2": 1,
         "a1": "{{r1}}",
         "a2": "{{r1}}",
         "a3": "{{r1}}",
     }
     runner_param_info = {"r1": {"type": "integer"}, "r2": {"type": "integer"}}
     action_param_info = {
         "a1": {"type": "boolean"},
         "a2": {"type": "string"},
         "a3": {"type": "integer"},
         "r1": {"type": "string"},
     }
     action_context = {"api_user": "******"}
     r_runner_params, r_action_params = param_utils.get_finalized_params(
         runner_param_info, action_param_info, params, action_context
     )
     self.assertEqual(r_runner_params, {"r1": 1, "r2": 1})
     self.assertEqual(r_action_params, {"a1": 1, "a2": "1", "a3": 1})
Exemplo n.º 58
0
    def test_get_finalized_params_older_kv_scopes_backwards_compatibility(
            self):
        KeyValuePair.add_or_update(
            KeyValuePairDB(name='cmd_to_run',
                           value='echo MELANIA',
                           scope=FULL_SYSTEM_SCOPE))
        # k2 = KeyValuePair.add_or_update(KeyValuePairDB(name='ivanka:cmd_to_run',
        #                                                value='echo MA DAD IS GREAT',
        #                                                scope=USER_SCOPE))
        params = {
            'sys_cmd': '{{system.cmd_to_run}}',
            # 'user_cmd': '{{user.ivanka:cmd_to_run}}' Not supported yet.
        }
        runner_param_info = {'r1': {}}
        action_param_info = {'sys_cmd': {}}
        action_context = {}

        r_runner_params, r_action_params = param_utils.get_finalized_params(
            runner_param_info, action_param_info, params, action_context)

        self.assertEqual(r_action_params['sys_cmd'], "echo MELANIA")
Exemplo n.º 59
0
 def test_get_finalized_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.
     params = {
         "r1": "{{r2}}",
         "r2": 1,
         "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_finalized_params(
         runner_param_info, action_param_info, params, action_context
     )
     self.assertEqual(r_runner_params, {"r1": 1, "r2": 1})
     self.assertEqual(r_action_params, {"a1": True, "a2": True, "a3": "noob"})
Exemplo n.º 60
0
    def test_get_finalized_params_with_casting_unicode_values(self):
        params = {"a1": "unicode1 ٩(̾●̮̮̃̾•̃̾)۶ unicode2"}

        runner_param_info = {}
        action_param_info = {"a1": {"type": "string"}}

        action_context = {"user": None}

        r_runner_params, r_action_params = param_utils.get_finalized_params(
            runner_param_info, action_param_info, params, action_context
        )

        if six.PY3:
            expected_action_params = {"a1": ("unicode1 ٩(̾●̮̮̃̾•̃̾)۶ unicode2")}
        else:
            expected_action_params = {
                "a1": (
                    "unicode1 \xd9\xa9(\xcc\xbe\xe2\x97\x8f\xcc\xae\xcc\xae\xcc"
                    "\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)