Commit 9b93c077 authored by Jelte Jansen's avatar Jelte Jansen

[trac967] added some more tests for nested lists/maps

and added a check for the right identifier
parent a5dd2311
......@@ -52,3 +52,4 @@ EXTRA_DIST += spec27.spec
EXTRA_DIST += spec28.spec
EXTRA_DIST += spec29.spec
EXTRA_DIST += spec30.spec
EXTRA_DIST += spec31.spec
{
"module_spec": {
"module_name": "lists",
"module_description": "Logging options",
"config_data": [
{
"item_name": "first_list_items",
"item_type": "list",
"item_optional": false,
"item_default": [],
"list_item_spec": {
"item_name": "first_list_item",
"item_type": "map",
"item_optional": false,
"item_default": {},
"map_item_spec": [
{ "item_name": "foo",
"item_type": "string",
"item_optional": false,
"item_default": "foo"
},
{ "item_name": "second_list_items",
"item_type": "list",
"item_optional": false,
"item_default": [],
"list_item_spec": {
"item_name": "second_list_item",
"item_type": "map",
"item_optional": false,
"item_default": {},
"map_item_spec": [
{ "item_name": "map_element",
"item_type": "map",
"item_optional": false,
"item_default": {},
"map_item_spec": [
{ "item_name": "list1",
"item_type": "list",
"item_optional": false,
"item_default": [],
"list_item_spec":
{ "item_name": "list2",
"item_type": "list",
"item_optional": false,
"item_default": [],
"list_item_spec":
{ "item_name": "number",
"item_type": "integer",
"item_optional": false,
"item_default": 1
}
}
}]
}
]
}
}
]
}
}
]
}
}
......@@ -133,7 +133,7 @@ def _find_spec_part_single(cur_spec, id_part):
# The specification we want a sub-part for should be either a
# list or a map, which is internally represented by a dict with
# an element 'map_item_spec', a dict with an element 'list_item_spec',
# or a list.
# or a list (when it is the 'main' config_data element of a module).
if type(cur_spec) == dict and 'map_item_spec' in cur_spec.keys():
for cur_spec_item in cur_spec['map_item_spec']:
if cur_spec_item['item_name'] == id:
......@@ -141,7 +141,10 @@ def _find_spec_part_single(cur_spec, id_part):
# not found
raise isc.cc.data.DataNotFoundError(id + " not found")
elif type(cur_spec) == dict and 'list_item_spec' in cur_spec.keys():
return cur_spec['list_item_spec']
if cur_spec['item_name'] == id:
return cur_spec['list_item_spec']
# not found
raise isc.cc.data.DataNotFoundError(id + " not found")
elif type(cur_spec) == list:
for cur_spec_item in cur_spec:
if cur_spec_item['item_name'] == id:
......
......@@ -337,6 +337,27 @@ class TestMultiConfigData(unittest.TestCase):
spec_part = self.mcd.find_spec_part("/BAD_NAME/first_list_items[0]/second_list_items[1]/final_element")
self.assertEqual(None, spec_part)
def test_find_spec_part_nested2(self):
module_spec = isc.config.module_spec_from_file(self.data_path + os.sep + "spec31.spec")
self.mcd.set_specification(module_spec)
spec_part = self.mcd.find_spec_part("/lists/first_list_items[0]/second_list_items[1]/map_element/list1[1]/list2[2]")
self.assertEqual({"item_name": "number", "item_type": "integer", "item_optional": False, "item_default": 1}, spec_part)
spec_part = self.mcd.find_spec_part("/DOESNOTEXIST")
self.assertEqual(None, spec_part)
spec_part = self.mcd.find_spec_part("/lists/DOESNOTEXIST")
self.assertEqual(None, spec_part)
spec_part = self.mcd.find_spec_part("/lists/first_list_items[0]/DOESNOTEXIST")
self.assertEqual(None, spec_part)
spec_part = self.mcd.find_spec_part("/lists/first_list_items[0]/second_list_items[1]/DOESNOTEXIST")
self.assertEqual(None, spec_part)
spec_part = self.mcd.find_spec_part("/lists/first_list_items[0]/second_list_items[1]/map_element/DOESNOTEXIST")
self.assertEqual(None, spec_part)
spec_part = self.mcd.find_spec_part("/lists/first_list_items[0]/second_list_items[1]/map_element/list1[1]/DOESNOTEXIST")
self.assertEqual(None, spec_part)
spec_part = self.mcd.find_spec_part("/lists/first_list_items[0]/second_list_items[1]/map_element/list1[1]/list2[1]/DOESNOTEXIST")
self.assertEqual(None, spec_part)
def test_get_current_config(self):
cf = { 'module1': { 'item1': 2, 'item2': True } }
self.mcd._set_current_config(cf);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment