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:
parent
da44307e30
commit
1bc64117c1
|
@ -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.
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue