From 85590e653acc8cf458a8dbaf13e8a9c5cd43ba13 Mon Sep 17 00:00:00 2001 From: David Stanek Date: Wed, 10 Feb 2016 18:10:51 +0000 Subject: [PATCH] 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 --- .../tests/unit/common/test_notifications.py | 36 +++++++++---------- tests-py3-blacklist.txt | 1 - 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/keystone/tests/unit/common/test_notifications.py b/keystone/tests/unit/common/test_notifications.py index aa2e6f72a1..4ae4ee2bf0 100644 --- a/keystone/tests/unit/common/test_notifications.py +++ b/keystone/tests/unit/common/test_notifications.py @@ -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 diff --git a/tests-py3-blacklist.txt b/tests-py3-blacklist.txt index 7583622193..8aaf2c5f52 100644 --- a/tests-py3-blacklist.txt +++ b/tests-py3-blacklist.txt @@ -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