Commit 0e776c32 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

Merge branch 'trac1344'

parents 723a57ed 1cdc605c
......@@ -12,6 +12,27 @@
"item_optional": false,
"item_default": 3
}
},
{ "item_name": "named_set_item2",
"item_type": "named_set",
"item_optional": true,
"item_default": { },
"named_set_item_spec": {
"item_name": "named_set_element",
"item_type": "map",
"item_optional": false,
"item_default": {},
"map_item_spec": [
{ "item_name": "first",
"item_type": "integer",
"item_optional": true
},
{ "item_name": "second",
"item_type": "string",
"item_optional": true
}
]
}
}
]
}
......
......@@ -515,7 +515,7 @@ class MultiConfigData:
return value, self.CURRENT
if default:
value = self.get_default_value(identifier)
if value != None:
if value is not None:
return value, self.DEFAULT
return None, self.NONE
......@@ -649,7 +649,11 @@ class MultiConfigData:
id, list_indices = isc.cc.data.split_identifier_list_indices(id_part)
cur_value, status = self.get_value(cur_id_part + id)
# Check if the value was there in the first place
if status == MultiConfigData.NONE and cur_id_part != "/":
# If we are at the final element, we do not care whether we found
# it, since if we have reached this point and it did not exist,
# it was apparently an optional value without a default.
if status == MultiConfigData.NONE and cur_id_part != "/" and\
cur_id_part + id != identifier:
raise isc.cc.data.DataNotFoundError(id_part +
" not found in " +
cur_id_part)
......
......@@ -776,14 +776,50 @@ class TestUIModuleCCSession(unittest.TestCase):
value, status = uccs.get_value("/Spec32/named_set_item")
self.assertEqual({'b': 2}, value)
uccs.set_value("/Spec32/named_set_item/c", 5)
value, status = uccs.get_value("/Spec32/named_set_item")
self.assertEqual({"b": 2, "c": 5}, value)
self.assertRaises(isc.cc.data.DataNotFoundError,
uccs.set_value,
"/Spec32/named_set_item/no_such_item",
"/Spec32/named_set_item/no_such_item/a",
4)
self.assertRaises(isc.cc.data.DataNotFoundError,
uccs.remove_value, "/Spec32/named_set_item",
"no_such_item")
def test_set_value_named_set(self):
fake_conn = fakeUIConn()
uccs = self.create_uccs_named_set(fake_conn)
value, status = uccs.get_value("/Spec32/named_set_item2")
self.assertEqual({}, value)
self.assertEqual(status, uccs.DEFAULT)
# Try setting a value that is optional but has no default
uccs.add_value("/Spec32/named_set_item2", "new1")
uccs.set_value("/Spec32/named_set_item2/new1/first", 3)
# Different method to add a new element
uccs.set_value("/Spec32/named_set_item2/new2", { "second": 4 })
value, status = uccs.get_value("/Spec32/named_set_item2")
self.assertEqual({ "new1": {"first": 3 }, "new2": {"second": 4}},
value)
self.assertEqual(status, uccs.LOCAL)
uccs.set_value("/Spec32/named_set_item2/new1/second", "foo")
value, status = uccs.get_value("/Spec32/named_set_item2")
self.assertEqual({ "new1": {"first": 3, "second": "foo" },
"new2": {"second": 4}},
value)
self.assertEqual(status, uccs.LOCAL)
# make sure using a bad name still fails
self.assertRaises(isc.cc.data.DataNotFoundError, uccs.set_value,
"/Spec32/named_set_item2/doesnotexist/first", 3)
def test_commit(self):
fake_conn = fakeUIConn()
uccs = self.create_uccs2(fake_conn)
......
......@@ -627,7 +627,7 @@ class TestMultiConfigData(unittest.TestCase):
config_items = self.mcd.get_config_item_list(None, False)
self.assertEqual(['Spec32'], config_items)
config_items = self.mcd.get_config_item_list(None, True)
self.assertEqual(['Spec32/named_set_item'], config_items)
self.assertEqual(['Spec32/named_set_item', 'Spec32/named_set_item2'], config_items)
self.mcd.set_value('Spec32/named_set_item', { "aaaa": 4, "aabb": 5, "bbbb": 6})
config_items = self.mcd.get_config_item_list("/Spec32/named_set_item", True)
self.assertEqual(['Spec32/named_set_item/aaaa',
......
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