Merge "Fix notification tests not unmocking logging"
This commit is contained in:
@@ -321,6 +321,8 @@ class TestLogNotifier(test_utils.BaseTestCase):
|
|||||||
|
|
||||||
mock_utcnow.return_value = datetime.datetime.utcnow()
|
mock_utcnow.return_value = datetime.datetime.utcnow()
|
||||||
|
|
||||||
|
logger = mock.Mock()
|
||||||
|
|
||||||
message = {
|
message = {
|
||||||
'message_id': str(message_id),
|
'message_id': str(message_id),
|
||||||
'publisher_id': 'test.localhost',
|
'publisher_id': 'test.localhost',
|
||||||
@@ -330,15 +332,15 @@ class TestLogNotifier(test_utils.BaseTestCase):
|
|||||||
'timestamp': str(timeutils.utcnow()),
|
'timestamp': str(timeutils.utcnow()),
|
||||||
}
|
}
|
||||||
|
|
||||||
logger = mock.Mock()
|
with mock.patch.object(logging, 'getLogger') as gl:
|
||||||
logging.getLogger = mock.Mock()
|
gl.return_value = logger
|
||||||
logging.getLogger.return_value = logger
|
|
||||||
|
|
||||||
notifier.info({}, 'test.notify', 'bar')
|
notifier.info({}, 'test.notify', 'bar')
|
||||||
|
|
||||||
uuid.uuid4.assert_called_once_with()
|
uuid.uuid4.assert_called_once_with()
|
||||||
logging.getLogger.assert_called_once_with('oslo.messaging.'
|
logging.getLogger.assert_called_once_with(
|
||||||
'notification.test.notify')
|
'oslo.messaging.notification.test.notify')
|
||||||
|
|
||||||
logger.info.assert_called_once_with(JsonMessageMatcher(message))
|
logger.info.assert_called_once_with(JsonMessageMatcher(message))
|
||||||
|
|
||||||
self.assertTrue(notifier.is_enabled())
|
self.assertTrue(notifier.is_enabled())
|
||||||
@@ -351,10 +353,11 @@ class TestLogNotifier(test_utils.BaseTestCase):
|
|||||||
'notification.foo'))
|
'notification.foo'))
|
||||||
logger.sample = None
|
logger.sample = None
|
||||||
|
|
||||||
logging.getLogger = mock.Mock()
|
|
||||||
logging.getLogger.return_value = logger
|
|
||||||
|
|
||||||
msg = {'event_type': 'foo'}
|
msg = {'event_type': 'foo'}
|
||||||
|
|
||||||
|
with mock.patch.object(logging, 'getLogger') as gl:
|
||||||
|
gl.return_value = logger
|
||||||
|
|
||||||
driver.notify(None, msg, "sample", None)
|
driver.notify(None, msg, "sample", None)
|
||||||
|
|
||||||
logging.getLogger.assert_called_once_with('oslo.messaging.'
|
logging.getLogger.assert_called_once_with('oslo.messaging.'
|
||||||
|
|||||||
Reference in New Issue
Block a user