From a70fc983eefe50196aa7429acccee8874524a5e6 Mon Sep 17 00:00:00 2001 From: Brant Knudson Date: Fri, 10 Jul 2015 16:26:47 -0500 Subject: [PATCH] Clean up code to use .items() The code was overly complicated because it didn't use .items() to get the value along with the key. Change-Id: I4b8b4bb3fbb5854d3e24e40ff110ef45a3b1bff8 --- keystone/notifications.py | 5 ++--- keystone/tests/unit/common/test_notifications.py | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/keystone/notifications.py b/keystone/notifications.py index 1d935083d5..0a8d6a2249 100644 --- a/keystone/notifications.py +++ b/keystone/notifications.py @@ -332,11 +332,10 @@ def listener(cls): return __new_init__ def _register_event_callbacks(self): - for event in self.event_callbacks: - for resource_type in self.event_callbacks[event]: + for event, resource_types in self.event_callbacks.items(): + for resource_type, callbacks in resource_types.items(): # Make sure we register the provider for each event it # cares to call back. - callbacks = self.event_callbacks[event][resource_type] if not callbacks: continue if not hasattr(callbacks, '__iter__'): diff --git a/keystone/tests/unit/common/test_notifications.py b/keystone/tests/unit/common/test_notifications.py index 3e17dc8271..6af922f487 100644 --- a/keystone/tests/unit/common/test_notifications.py +++ b/keystone/tests/unit/common/test_notifications.py @@ -716,7 +716,7 @@ class TestEventCallbacks(test_v3.RestfulTestCase): def __init__(self): self.event_callbacks = 'bogus' - self.assertRaises(TypeError, Foo) + self.assertRaises(AttributeError, Foo) def test_invalid_event_callbacks_event(self): @notifications.listener @@ -724,7 +724,7 @@ class TestEventCallbacks(test_v3.RestfulTestCase): def __init__(self): self.event_callbacks = {CREATED_OPERATION: 'bogus'} - self.assertRaises(TypeError, Foo) + self.assertRaises(AttributeError, Foo) class CadfNotificationsWrapperTestCase(test_v3.RestfulTestCase):