summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Mescheryakov <dmescheryakov@mirantis.com>2017-04-28 17:53:33 +0400
committerDmitry Mescheryakov <dmescheryakov@mirantis.com>2017-04-28 19:17:50 +0400
commiteb4f5c4fa03f34918e70af52773e95cccf51a039 (patch)
treefb0589b0513284c6c394445863d43540c8501864
parentb3893c13bd8270d62984a1d916c2c0347169410a (diff)
downloadoslo-messaging-eb4f5c4fa03f34918e70af52773e95cccf51a039.tar.gz
Fix notification tests not unmocking logging
Right now two tests mock logging module globally which leads to another test failure (TestRoutingNotifier.test_notify_filtered) on my env. Change-Id: Ifa47ee96dae79ea44dbe17a2d125401589ff13dd
-rwxr-xr-xoslo_messaging/tests/notify/test_notifier.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/oslo_messaging/tests/notify/test_notifier.py b/oslo_messaging/tests/notify/test_notifier.py
index 7484311..b9d1151 100755
--- a/oslo_messaging/tests/notify/test_notifier.py
+++ b/oslo_messaging/tests/notify/test_notifier.py
@@ -319,6 +319,8 @@ class TestLogNotifier(test_utils.BaseTestCase):
mock_utcnow.return_value = datetime.datetime.utcnow()
+ logger = mock.Mock()
+
message = {
'message_id': str(message_id),
'publisher_id': 'test.localhost',
@@ -328,15 +330,15 @@ class TestLogNotifier(test_utils.BaseTestCase):
'timestamp': str(timeutils.utcnow()),
}
- logger = mock.Mock()
- logging.getLogger = mock.Mock()
- logging.getLogger.return_value = logger
+ with mock.patch.object(logging, 'getLogger') as gl:
+ gl.return_value = logger
- notifier.info({}, 'test.notify', 'bar')
+ notifier.info({}, 'test.notify', 'bar')
+
+ uuid.uuid4.assert_called_once_with()
+ logging.getLogger.assert_called_once_with(
+ 'oslo.messaging.notification.test.notify')
- uuid.uuid4.assert_called_once_with()
- logging.getLogger.assert_called_once_with('oslo.messaging.'
- 'notification.test.notify')
logger.info.assert_called_once_with(JsonMessageMatcher(message))
self.assertTrue(notifier.is_enabled())
@@ -349,14 +351,15 @@ class TestLogNotifier(test_utils.BaseTestCase):
'notification.foo'))
logger.sample = None
- logging.getLogger = mock.Mock()
- logging.getLogger.return_value = logger
-
msg = {'event_type': 'foo'}
- driver.notify(None, msg, "sample", None)
- logging.getLogger.assert_called_once_with('oslo.messaging.'
- 'notification.foo')
+ with mock.patch.object(logging, 'getLogger') as gl:
+ gl.return_value = logger
+
+ driver.notify(None, msg, "sample", None)
+
+ logging.getLogger.assert_called_once_with('oslo.messaging.'
+ 'notification.foo')
def test_mask_passwords(self):
# Ensure that passwords are masked with notifications