From: Michal 'vorner' Vaner Date: Wed, 28 Dec 2011 14:30:30 +0000 (+0100) Subject: [1515] Don't crash when printing exception X-Git-Tag: trac2351_base~306^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ff1a0cd96fd213256d1e91c21cca3de2be634314;p=thirdparty%2Fkea.git [1515] Don't crash when printing exception The thing should be converted to string properly --- diff --git a/src/lib/config/tests/testdata/spec39.spec b/src/lib/config/tests/testdata/spec39.spec new file mode 100644 index 0000000000..1f7231923f --- /dev/null +++ b/src/lib/config/tests/testdata/spec39.spec @@ -0,0 +1,21 @@ +{ + "module_spec": { + "module_name": "Spec39", + "config_data": [ + { "item_name": "list", + "item_type": "list", + "item_optional": false, + "item_default": [], + "list_item_spec": { + "item_name": "list_item", + "item_type": "boolean", + "item_optional": false, + "item_default": false + } + } + ], + "commands": [], + "statistics": [] + } +} + diff --git a/src/lib/python/isc/config/ccsession.py b/src/lib/python/isc/config/ccsession.py index 2d998ced08..760ae5597c 100644 --- a/src/lib/python/isc/config/ccsession.py +++ b/src/lib/python/isc/config/ccsession.py @@ -451,9 +451,9 @@ class UIModuleCCSession(MultiConfigData): cur_list.append(value) self.set_value(identifier, cur_list) else: - raise isc.cc.data.DataAlreadyPresentError(value + + raise isc.cc.data.DataAlreadyPresentError(str(value) + " already in " - + identifier) + + str(identifier)) def _add_value_to_named_set(self, identifier, value, item_value): if type(value) != str: diff --git a/src/lib/python/isc/config/tests/ccsession_test.py b/src/lib/python/isc/config/tests/ccsession_test.py index 8d616e2b9b..50f6043d99 100644 --- a/src/lib/python/isc/config/tests/ccsession_test.py +++ b/src/lib/python/isc/config/tests/ccsession_test.py @@ -701,6 +701,12 @@ class TestUIModuleCCSession(unittest.TestCase): fake_conn.set_get_answer('/config_data', { 'version': BIND10_CONFIG_DATA_VERSION }) return UIModuleCCSession(fake_conn) + def create_uccs_listtest(self, fake_conn): + module_spec = isc.config.module_spec_from_file(self.spec_file("spec39.spec")) + fake_conn.set_get_answer('/module_spec', { module_spec.get_module_name(): module_spec.get_full_spec()}) + fake_conn.set_get_answer('/config_data', { 'version': BIND10_CONFIG_DATA_VERSION }) + return UIModuleCCSession(fake_conn) + def test_init(self): fake_conn = fakeUIConn() fake_conn.set_get_answer('/module_spec', {}) @@ -732,6 +738,7 @@ class TestUIModuleCCSession(unittest.TestCase): self.assertEqual({}, uccs._local_changes) uccs.add_value("Spec2/item5", "foo") self.assertEqual({'Spec2': {'item5': ['a', 'b', 'foo']}}, uccs._local_changes) + self.assertEqual({'Spec2': {'item5': ['a', 'b', 'foo']}}, uccs._local_changes) uccs.remove_value("Spec2/item5", "foo") self.assertEqual({'Spec2': {'item5': ['a', 'b']}}, uccs._local_changes) uccs._local_changes = {'Spec2': {'item5': []}} @@ -751,6 +758,14 @@ class TestUIModuleCCSession(unittest.TestCase): self.assertRaises(isc.cc.data.DataTypeError, uccs.remove_value, "Spec2/item5", None) + def test_add_dup_value(self): + fake_conn = fakeUIConn() + uccs = self.create_uccs_listtest(fake_conn) + + uccs.add_value("Spec39/list") + self.assertRaises(isc.cc.data.DataAlreadyPresentError, uccs.add_value, + "Spec39/list") + def test_add_remove_value_named_set(self): fake_conn = fakeUIConn() uccs = self.create_uccs_named_set(fake_conn)