Add sanity check to receives decorator
Add simple assertion to prevent simple mistakes like I4a39f2e9d2f10639a209e7311fe44b94d369c5b1. Change-Id: I3a18da4949dcd97096817c5e157cac99bb37c04d
This commit is contained in:
@@ -68,6 +68,8 @@ def receives(resource, events):
|
|||||||
@has_registry_receivers decorator to setup the __new__ method to
|
@has_registry_receivers decorator to setup the __new__ method to
|
||||||
actually register the instance methods after initialization.
|
actually register the instance methods after initialization.
|
||||||
"""
|
"""
|
||||||
|
assert isinstance(events, (list, tuple, set)), 'events must be collection'
|
||||||
|
|
||||||
def decorator(f):
|
def decorator(f):
|
||||||
for e in events:
|
for e in events:
|
||||||
_REGISTERED_CLASS_METHODS[f].append((resource, e))
|
_REGISTERED_CLASS_METHODS[f].append((resource, e))
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
import testtools
|
||||||
|
|
||||||
from oslotest import base
|
from oslotest import base
|
||||||
|
|
||||||
@@ -99,6 +100,10 @@ class CallBacksManagerTestCase(base.BaseTestCase):
|
|||||||
def test_object_new_not_broken(self):
|
def test_object_new_not_broken(self):
|
||||||
CallbackClassWithParameters('dummy')
|
CallbackClassWithParameters('dummy')
|
||||||
|
|
||||||
|
def test_no_strings_in_events_arg(self):
|
||||||
|
with testtools.ExpectedException(AssertionError):
|
||||||
|
registry.receives(resources.PORT, events.AFTER_CREATE)
|
||||||
|
|
||||||
|
|
||||||
class TestCallbackRegistryDispatching(base.BaseTestCase):
|
class TestCallbackRegistryDispatching(base.BaseTestCase):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user