diff --git a/ate/utils.py b/ate/utils.py index aea20f3f..835335c1 100644 --- a/ate/utils.py +++ b/ate/utils.py @@ -366,8 +366,15 @@ def update_ordered_dict(ordered_dict, override_mapping): def override_variables_binds(variable_binds, new_mapping): """ convert variable_binds in testcase to ordered mapping, with new_mapping overrided """ + if isinstance(variable_binds, list): + variable_binds_ordered_dict = convert_to_order_dict(variable_binds) + elif isinstance(variable_binds, OrderedDict): + variable_binds_ordered_dict = variable_binds + else: + raise exception.ParamsError("variable_binds error!") + return update_ordered_dict( - convert_to_order_dict(variable_binds), + variable_binds_ordered_dict, new_mapping ) diff --git a/tests/test_utils.py b/tests/test_utils.py index 0c1d9ec1..9cde8467 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,8 +1,10 @@ import os -from ate import utils -from ate import exception +from collections import OrderedDict + +from ate import exception, utils from tests.base import ApiServerUnittest + class TestUtils(ApiServerUnittest): def test_load_testcases_bad_filepath(self): @@ -278,3 +280,19 @@ class TestUtils(ApiServerUnittest): new_dict = utils.override_variables_binds(map_list, override_mapping) self.assertEqual(3, new_dict["a"]) self.assertEqual(4, new_dict["c"]) + + map_list = OrderedDict( + { + "a": 1, + "b": 2 + } + ) + override_mapping = {"a": 3, "c": 4} + new_dict = utils.override_variables_binds(map_list, override_mapping) + self.assertEqual(3, new_dict["a"]) + self.assertEqual(4, new_dict["c"]) + + map_list = "invalid" + override_mapping = {"a": 3, "c": 4} + with self.assertRaises(exception.ParamsError): + utils.override_variables_binds(map_list, override_mapping)