Commit 1cdc605c authored by Jelte Jansen's avatar Jelte Jansen
Browse files

[1344] and refactor into simpler code

parent 8b5b28cd
......@@ -649,22 +649,14 @@ 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 != "/":
# In case the element we are setting did not have any
# value set, was optional, *and* had no default, we do not
# want to error when trying to set it
# (this only goes for the 'final' element, if higher-level
# ones do not appear to exist, it is a failure, hence the
# final comparison)
if not 'item_default' in spec_part and\
'item_optional' in spec_part and\
spec_part['item_optional'] and\
cur_id_part + id == identifier:
pass
else:
raise isc.cc.data.DataNotFoundError(id_part +
" not found in " +
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)
if list_indices is not None:
# And check if we don't set something outside of any
# list
......
......@@ -765,9 +765,13 @@ 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",
......@@ -781,17 +785,22 @@ class TestUIModuleCCSession(unittest.TestCase):
self.assertEqual(status, uccs.DEFAULT)
# Try setting a value that is optional but has no default
uccs.add_value("/Spec32/named_set_item2", "new")
uccs.set_value("/Spec32/named_set_item2/new/first", 3)
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({ 'new': {'first': 3 }}, value)
self.assertEqual({ "new1": {"first": 3 }, "new2": {"second": 4}},
value)
self.assertEqual(status, uccs.LOCAL)
uccs.set_value("/Spec32/named_set_item2/new/second", "foo")
uccs.set_value("/Spec32/named_set_item2/new1/second", "foo")
value, status = uccs.get_value("/Spec32/named_set_item2")
self.assertEqual({ 'new': {'first': 3, 'second': "foo" }}, value)
self.assertEqual({ "new1": {"first": 3, "second": "foo" },
"new2": {"second": 4}},
value)
self.assertEqual(status, uccs.LOCAL)
# make sure using a bad name still fails
......@@ -799,6 +808,7 @@ class TestUIModuleCCSession(unittest.TestCase):
"/Spec32/named_set_item2/doesnotexist/first", 3)
def test_commit(self):
fake_conn = fakeUIConn()
uccs = self.create_uccs2(fake_conn)
......
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