Browse Source

ok this is as far as i can get with coverage on config_data.py

git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@967 e5f2f494-b856-4b98-b285-d166d9295462
Jelte Jansen 15 years ago
parent
commit
25a2bfcf77

+ 10 - 5
src/lib/config/python/isc/config/config_data.py

@@ -73,7 +73,7 @@ def find_spec_part(element, identifier):
         elif type(cur_el) == list:
         elif type(cur_el) == list:
             found = False
             found = False
             for cur_el_item in cur_el:
             for cur_el_item in cur_el:
-                if cur_el_item['item_name'] == id and 'item_default' in cur_el_item.keys():
+                if cur_el_item['item_name'] == id:
                     cur_el = cur_el_item
                     cur_el = cur_el_item
                     found = True
                     found = True
             if not found:
             if not found:
@@ -201,6 +201,11 @@ class MultiConfigData:
             raise ConfigDataError("not a datadef: " + str(type(spec)))
             raise ConfigDataError("not a datadef: " + str(type(spec)))
         self._specifications[spec.get_module_name()] = spec
         self._specifications[spec.get_module_name()] = spec
 
 
+    def remove_specification(self, module_name):
+        """Removes the specification with the given module name. Does nothing if it wasn't there."""
+        if module_name in self._specifications:
+            del self._specifications[module_name]
+
     def get_module_spec(self, module):
     def get_module_spec(self, module):
         """Returns the ModuleSpec for the module with the given name.
         """Returns the ModuleSpec for the module with the given name.
            If there is no such module, it returns None"""
            If there is no such module, it returns None"""
@@ -344,13 +349,13 @@ class MultiConfigData:
                         else:
                         else:
                             entry['default'] = False
                             entry['default'] = False
                         result.append(entry)
                         result.append(entry)
-                else:
+                elif type(spec_part) == dict:
                     item = spec_part
                     item = spec_part
                     if item['item_type'] == 'list':
                     if item['item_type'] == 'list':
                         li_spec = item['list_item_spec']
                         li_spec = item['list_item_spec']
-                        l, status =  self.get_value("/" + identifier)
-                        if l:
-                            for value in l:
+                        item_list, status =  self.get_value("/" + identifier)
+                        if item_list != None:
+                            for value in item_list:
                                 result_part2 = {}
                                 result_part2 = {}
                                 result_part2['name'] = li_spec['item_name']
                                 result_part2['name'] = li_spec['item_name']
                                 result_part2['value'] = value
                                 result_part2['value'] = value

+ 23 - 0
src/lib/config/python/isc/config/config_data_test.py

@@ -297,6 +297,20 @@ class TestMultiConfigData(unittest.TestCase):
         self.assertEqual(MultiConfigData.NONE, status)
         self.assertEqual(MultiConfigData.NONE, status)
 
 
     def test_get_value_maps(self):
     def test_get_value_maps(self):
+        maps = self.mcd.get_value_maps()
+        self.assertEqual([], maps)
+        
+        module_spec = isc.config.module_spec_from_file(self.data_path + os.sep + "spec1.spec")
+        self.mcd.set_specification(module_spec)
+        maps = self.mcd.get_value_maps()
+        self.assertEqual([{'default': False, 'type': 'module', 'name': 'Spec1', 'value': None, 'modified': False}], maps)
+        maps = self.mcd.get_value_maps('Spec2')
+        self.assertEqual([], maps)
+        maps = self.mcd.get_value_maps('Spec1')
+        self.assertEqual([], maps)
+        self.mcd.remove_specification("Spec1")
+        self.mcd.remove_specification("foo")
+        
         module_spec = isc.config.module_spec_from_file(self.data_path + os.sep + "spec2.spec")
         module_spec = isc.config.module_spec_from_file(self.data_path + os.sep + "spec2.spec")
         self.mcd.set_specification(module_spec)
         self.mcd.set_specification(module_spec)
         maps = self.mcd.get_value_maps()
         maps = self.mcd.get_value_maps()
@@ -329,6 +343,15 @@ class TestMultiConfigData(unittest.TestCase):
         maps = self.mcd.get_value_maps("/Spec2/item4")
         maps = self.mcd.get_value_maps("/Spec2/item4")
         self.assertEqual([{'default': False, 'type': 'string', 'name': 'item4', 'value': 'test', 'modified': False}], maps)
         self.assertEqual([{'default': False, 'type': 'string', 'name': 'item4', 'value': 'test', 'modified': False}], maps)
 
 
+        module_spec = isc.config.module_spec_from_file(self.data_path + os.sep + "spec24.spec")
+        self.mcd.set_specification(module_spec)
+        maps = self.mcd.get_value_maps("/Spec24/item")
+        self.assertEqual([], maps)
+        self.mcd._set_current_config({ "Spec24": { "item": [] } })
+        maps = self.mcd.get_value_maps("/Spec24/item")
+        self.assertEqual([], maps)
+
+
 
 
     def test_set_value(self):
     def test_set_value(self):
         module_spec = isc.config.module_spec_from_file(self.data_path + os.sep + "spec2.spec")
         module_spec = isc.config.module_spec_from_file(self.data_path + os.sep + "spec2.spec")