Enables the notification tests in py3

There are two things being fixed here:
 - In py3 a class is unhashable if it defines an __eq__, but doesn't
   define a __hash__. testtools.TestCase does this so adding the
   TestCase's methods into the set of methods to be called fails. The
   fake Manager class was created to bypass the issue since objects are
   hashable by default.
 - In py3 unbound methods are no longer a special object. They are
   treated the same an any other function object (note I don't mean
   instance methods). Because of this the TypeError is no longer raised
   when calling an unbound method without a class instance. To catch the
   same error in py3 we can get rid of the *args and spell out the
   arguments. This way when the method is called it will get a
   TypeError, since not all of the arguments will be passed in (no self,
   because it's not being called with an instance).

An unused callback method was also removed.

bp python3

Change-Id: I1d51a47614cdb8dd348c171e6fce644b3b4eec37
This commit is contained in:
David Stanek 2016-02-10 18:10:51 +00:00 committed by Brant Knudson
parent 4f822c53a8
commit 85590e653a
2 changed files with 18 additions and 19 deletions

View File

@ -831,17 +831,11 @@ class V2Notifications(BaseNotificationTest):
class TestEventCallbacks(test_v3.RestfulTestCase):
def setUp(self):
super(TestEventCallbacks, self).setUp()
self.has_been_called = False
class FakeManager(object):
def _project_deleted_callback(self, service, resource_type, operation,
payload):
self.has_been_called = True
def _project_created_callback(self, service, resource_type, operation,
payload):
self.has_been_called = True
def _project_deleted_callback(self, service, resource_type, operation,
payload):
"""Used just for the callback interface."""
def test_notification_received(self):
callback = register_callback(CREATED_OPERATION, 'project')
@ -858,22 +852,28 @@ class TestEventCallbacks(test_v3.RestfulTestCase):
[fake_method])
def test_notification_event_not_valid(self):
manager = self.FakeManager()
self.assertRaises(ValueError,
notifications.register_event_callback,
uuid.uuid4().hex,
'project',
self._project_deleted_callback)
manager._project_deleted_callback)
def test_event_registration_for_unknown_resource_type(self):
# Registration for unknown resource types should succeed. If no event
# is issued for that resource type, the callback wont be triggered.
notifications.register_event_callback(DELETED_OPERATION,
uuid.uuid4().hex,
self._project_deleted_callback)
manager = self.FakeManager()
notifications.register_event_callback(
DELETED_OPERATION,
uuid.uuid4().hex,
manager._project_deleted_callback)
resource_type = uuid.uuid4().hex
notifications.register_event_callback(DELETED_OPERATION,
resource_type,
self._project_deleted_callback)
notifications.register_event_callback(
DELETED_OPERATION,
resource_type,
manager._project_deleted_callback)
def test_provider_event_callback_subscription(self):
callback_called = []
@ -948,7 +948,7 @@ class TestEventCallbacks(test_v3.RestfulTestCase):
self.event_callbacks = {CREATED_OPERATION:
{'project': Foo.callback}}
def callback(self, *args):
def callback(self, service, resource_type, operation, payload):
pass
# TODO(dstanek): it would probably be nice to fail early using

View File

@ -1,5 +1,4 @@
keystone.tests.unit.common.test_ldap
keystone.tests.unit.common.test_notifications
keystone.tests.unit.test_backend_ldap
keystone.tests.unit.test_backend_ldap_pool
keystone.tests.unit.test_v2