diff options
author | Jenkins <jenkins@review.openstack.org> | 2017-05-03 20:29:40 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2017-05-03 20:29:40 +0000 |
commit | e569c92cd9d17c907ecc35e24c50c49717844bde (patch) | |
tree | 36b880bf6821b0c05e2b729fe498bab8519d9ce6 | |
parent | c8ee259bacf2b71fc717ef94f43df0f7d2c4cf2a (diff) | |
parent | eb4f5c4fa03f34918e70af52773e95cccf51a039 (diff) | |
download | oslo-messaging-5.24.0.tar.gz |
Merge "Fix notification tests not unmocking logging"5.24.0
-rwxr-xr-x | oslo_messaging/tests/notify/test_notifier.py | 29 |
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 6bd3f7e..364803e 100755 --- a/oslo_messaging/tests/notify/test_notifier.py +++ b/oslo_messaging/tests/notify/test_notifier.py @@ -321,6 +321,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', @@ -330,15 +332,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()) @@ -351,14 +353,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 |