From f4b6ae4244c93e1518ca02646685109d64caa104 Mon Sep 17 00:00:00 2001 From: Lance Bragstad Date: Tue, 9 Oct 2018 17:57:04 +0000 Subject: [PATCH] Don't mock internal implementation details of oslo Keystone relies on oslo.messaging to handle the underlying routing of messaging for keystone notifications and CADF events. Early testing implementations for notification support in keystone mocked and internal method of the oslo.messaging implementation to make sure it was actually being invoked. This falls outside of the realm of keystone testing because it's testing the internal implementation details of an external library (which is already tested anyway). This commit adjusts the tests to mock a public facing method instead of a private one. This makes the mock safer since it's consuming a public API just like the rest of the notification framework. Change-Id: I04b78a94eddda5486337e7555817a25e0a106433 --- keystone/tests/unit/common/test_notifications.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/keystone/tests/unit/common/test_notifications.py b/keystone/tests/unit/common/test_notifications.py index 5a5b8d503d..4908740836 100644 --- a/keystone/tests/unit/common/test_notifications.py +++ b/keystone/tests/unit/common/test_notifications.py @@ -141,12 +141,11 @@ class NotificationsTestCase(unit.BaseTestCase): expected_args = [ {}, # empty context 'identity.%s.created' % resource_type, # event_type - {'resource_info': resource}, # payload - 'INFO', # priority is always INFO... + {'resource_info': resource} # payload ] with mock.patch.object(notifications._get_notifier(), - '_notify') as mocked: + 'info') as mocked: notifications._send_notification(operation, resource_type, resource) mocked.assert_called_once_with(*expected_args) @@ -170,7 +169,7 @@ class NotificationsTestCase(unit.BaseTestCase): conf.config(notification_opt_out=[event_type]) with mock.patch.object(notifications._get_notifier(), - '_notify') as mocked: + 'info') as mocked: notifications._send_notification(operation, resource_type, resource) @@ -194,7 +193,7 @@ class NotificationsTestCase(unit.BaseTestCase): conf.config(notification_opt_out=[event_type]) with mock.patch.object(notifications._get_notifier(), - '_notify') as mocked: + 'info') as mocked: notifications._send_audit_notification(action, initiator, @@ -218,7 +217,7 @@ class NotificationsTestCase(unit.BaseTestCase): conf.config(notification_opt_out=[meter_name]) with mock.patch.object(notifications._get_notifier(), - '_notify') as mocked: + 'info') as mocked: notifications._send_audit_notification(action, initiator, @@ -1341,7 +1340,7 @@ class CADFNotificationsDataTestCase(test_v3.RestfulTestCase): event_type = 'identity.authenticate.created' with mock.patch.object(notifications._get_notifier(), - '_notify') as mocked: + 'info') as mocked: notifications._send_audit_notification(action, initiator,