Merge "Fixes bug with notify_decorator bad getattr default value"

This commit is contained in:
Jenkins 2016-05-11 22:29:10 +00:00 committed by Gerrit Code Review
commit 9282b99b8e
2 changed files with 26 additions and 1 deletions

@ -69,7 +69,7 @@ def notify_decorator(name, fn):
publisher_id=(CONF.default_publisher_id
or CONF.host))
method = getattr(notifier, CONF.default_notification_level.lower(),
'info')
notifier.info)
method(ctxt, name, body)
return fn(*args, **kwarg)

@ -481,6 +481,31 @@ class NotificationsTestCase(test.TestCase):
self.assertEqual(n.context, ctxt)
self.assertTrue(self.decorated_function_called)
def test_notify_decorator_wrong_default_notification_level(self):
func_name = self._decorated_function.__name__
self.flags(default_notification_level='fake_level')
self._decorated_function = notifications.notify_decorator(
func_name,
self._decorated_function)
mock_info = mock.Mock()
class FakeNotifier(object):
info = mock_info
mock_notifier_p = mock.patch.object(
notifications.rpc,
'get_notifier',
mock.Mock(return_value=FakeNotifier)
)
with mock_notifier_p:
self._decorated_function(1, 2)
self.assertTrue(self.decorated_function_called)
self.assertTrue(mock_info.called)
class NotificationsFormatTestCase(test.NoDBTestCase):