Clean up notifications type checking

Python already raises understandable exceptions when the wrong type
is used. All this type checking just makes the code harder to
understand. So remove the type checking code and let the interpreter
raise the expected exception.

Change-Id: Idca30f7a519d40263cba32e26003a9b1bdd51907
This commit is contained in:
Brant Knudson 2015-07-10 16:19:06 -05:00
parent da44307e30
commit 1bc64117c1
2 changed files with 2 additions and 12 deletions

View File

@ -328,21 +328,11 @@ def listener(cls):
@functools.wraps(init)
def __new_init__(self, *args, **kwargs):
init(self, *args, **kwargs)
if not hasattr(self, 'event_callbacks'):
msg = _("%r object has no attribute 'event_callbacks'")
raise AttributeError(msg % self.__class__.__name)
_register_event_callbacks(self)
return __new_init__
def _register_event_callbacks(self):
if not isinstance(self.event_callbacks, dict):
msg = _('event_callbacks must be a dict')
raise ValueError(msg)
for event in self.event_callbacks:
if not isinstance(self.event_callbacks[event], dict):
msg = _('event_callbacks[%s] must be a dict') % event
raise ValueError(msg)
for resource_type in self.event_callbacks[event]:
# Make sure we register the provider for each event it
# cares to call back.

View File

@ -716,7 +716,7 @@ class TestEventCallbacks(test_v3.RestfulTestCase):
def __init__(self):
self.event_callbacks = 'bogus'
self.assertRaises(ValueError, Foo)
self.assertRaises(TypeError, 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(ValueError, Foo)
self.assertRaises(TypeError, Foo)
class CadfNotificationsWrapperTestCase(test_v3.RestfulTestCase):