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
This commit is contained in:
Lance Bragstad 2018-10-09 17:57:04 +00:00
parent 413d5c18ff
commit f4b6ae4244
1 changed files with 6 additions and 7 deletions

View File

@ -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,