Debian Codegraph @

neutron_lib/tests/unit/callbacks/test_callback_exceptions.py

raw
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 """
14 test_callback_exceptions
15 ----------------------------------
16
17 Tests for `neutron_lib.callback.exceptions` module.
18 """
19
20 import functools
21
22 import neutron_lib.callbacks.exceptions as ex
23 from neutron_lib.tests.unit.exceptions import test_exceptions
24
25
26 class TestCallbackExceptions(test_exceptions.TestExceptionsBase):
27
28 def _check_exception(self, exc_class, expected_msg, **kwargs):
29 raise_exc_class = functools.partial(test_exceptions._raise, exc_class)
30 e = self.assertRaises(exc_class, raise_exc_class, **kwargs)
31 self.assertEqual(expected_msg, str(e))
32
33 def test_invalid(self):
34 self._check_exception(
35 ex.Invalid,
36 "The value 'foo' for bar is not valid.",
37 value='foo', element='bar')
38
39 def test_callback_failure(self):
40 self._check_exception(
41 ex.CallbackFailure,
42 'one',
43 errors='one')
44
45 def test_callback_failure_with_list(self):
46 self._check_exception(
47 ex.CallbackFailure,
48 '1,2,3',
49 errors=[1, 2, 3])
50
51 def test_notification_error(self):
52 '''Test that correct message is created for this error class.'''
53 error = ex.NotificationError('abc', 'boom')
54 self.assertEqual('Callback abc failed with "boom"', str(error))
55
56 def test_inner_exceptions(self):
57 key_err = KeyError()
58 n_key_err = ex.NotificationError('cb1', key_err)
59 err = ex.CallbackFailure([key_err, n_key_err])
60 self.assertEqual([key_err, n_key_err.error], err.inner_exceptions)