From: Jelte Jansen Date: Tue, 25 Sep 2012 21:59:40 +0000 (+0200) Subject: [2254] change exception type X-Git-Tag: trac2402_base~83^2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b9f5f6d4afd45a3482ca0d4aec22f5d00df1865;p=thirdparty%2Fkea.git [2254] change exception type and add comment to tests --- diff --git a/src/lib/python/isc/config/ccsession.py b/src/lib/python/isc/config/ccsession.py index 1a45bf3166..8464a01e04 100644 --- a/src/lib/python/isc/config/ccsession.py +++ b/src/lib/python/isc/config/ccsession.py @@ -575,7 +575,7 @@ class UIModuleCCSession(MultiConfigData): # for type any, we determine the 'type' by what value is set # (which would be either list or dict) cur_value, _ = self.get_value(identifier) - type_any = module_spec['item_type'] == 'any' + type_any = isc.config.config_data.spec_part_is_any(module_spec) # the specified element must be a list or a named_set if 'list_item_spec' in module_spec or\ @@ -603,7 +603,7 @@ class UIModuleCCSession(MultiConfigData): self._add_value_to_named_set(identifier, item_name, item_value) else: - raise isc.cc.data.DataNotFoundError(str(identifier) + " is not a list or a named set") + raise isc.cc.data.DataTypeError(str(identifier) + " is not a list or a named set") def _remove_value_from_list(self, identifier, value): if value is None: @@ -668,7 +668,7 @@ class UIModuleCCSession(MultiConfigData): (type_any and type(cur_value) == dict): self._remove_value_from_named_set(identifier, value_str) else: - raise isc.cc.data.DataNotFoundError(str(identifier) + " is not a list or a named_set") + raise isc.cc.data.DataTypeError(str(identifier) + " is not a list or a named_set") diff --git a/src/lib/python/isc/config/tests/ccsession_test.py b/src/lib/python/isc/config/tests/ccsession_test.py index f81b1dbfdc..ad364accaf 100644 --- a/src/lib/python/isc/config/tests/ccsession_test.py +++ b/src/lib/python/isc/config/tests/ccsession_test.py @@ -993,11 +993,15 @@ class TestUIModuleCCSession(unittest.TestCase): self.assertRaises(isc.cc.data.DataNotFoundError, uccs.add_value, 1, "a") self.assertRaises(isc.cc.data.DataNotFoundError, uccs.add_value, "no_such_item", "a") - self.assertRaises(isc.cc.data.DataNotFoundError, uccs.add_value, "Spec2/item1", "a") self.assertRaises(isc.cc.data.DataNotFoundError, uccs.remove_value, 1, "a") self.assertRaises(isc.cc.data.DataNotFoundError, uccs.remove_value, "no_such_item", "a") - self.assertRaises(isc.cc.data.DataNotFoundError, uccs.remove_value, "Spec2/item1", "a") - self.assertRaises(isc.cc.data.DataNotFoundError, uccs.remove_value, "Spec2", "") + # add and remove should raise DataNotFoundError when used with items + # that are not a list or named_set (more importantly, they should + # not raise TypeError) + self.assertRaises(isc.cc.data.DataTypeError, uccs.add_value, "Spec2/item1", "a") + self.assertRaises(isc.cc.data.DataTypeError, uccs.remove_value, "Spec2/item1", "a") + self.assertRaises(isc.cc.data.DataTypeError, uccs.add_value, "Spec2", "") + self.assertRaises(isc.cc.data.DataTypeError, uccs.remove_value, "Spec2", "") self.assertEqual({}, uccs._local_changes) uccs.add_value("Spec2/item5", "foo") @@ -1044,9 +1048,9 @@ class TestUIModuleCCSession(unittest.TestCase): items_as_str = [ '1234', 'foo', 'true', 'false' ] def test_fails(): - self.assertRaises(isc.cc.data.DataNotFoundError, uccs.add_value, "Spec40/item1", "foo") - self.assertRaises(isc.cc.data.DataNotFoundError, uccs.add_value, "Spec40/item1", "foo", "bar") - self.assertRaises(isc.cc.data.DataNotFoundError, uccs.remove_value, "Spec40/item1", "foo") + self.assertRaises(isc.cc.data.DataTypeError, uccs.add_value, "Spec40/item1", "foo") + self.assertRaises(isc.cc.data.DataTypeError, uccs.add_value, "Spec40/item1", "foo", "bar") + self.assertRaises(isc.cc.data.DataTypeError, uccs.remove_value, "Spec40/item1", "foo") self.assertRaises(isc.cc.data.DataTypeError, uccs.remove_value, "Spec40/item1[0]", None) # A few helper functions to perform a number of tests