From 0e0449bbdfb855b6031b3bd40e67455741cf78d2 Mon Sep 17 00:00:00 2001 From: David Stanek Date: Thu, 31 Oct 2013 00:28:50 +0000 Subject: [PATCH] Uses fixtures for mox and stubs Fixtures use the much more reliable addCleanup instead of the tearDown. They also allow us the only use fixtures in test classes that use then instead of having the overhead for every test class. Change-Id: Ifca4ecce0d66932282334d3e4db6d10a2921dbbb --- keystone/tests/core.py | 10 +--------- keystone/tests/test_backend_ldap.py | 5 +++++ keystone/tests/test_notifications.py | 12 ++++++++++++ keystone/tests/test_policy.py | 4 ++++ keystone/tests/test_versions.py | 10 ++++++++-- keystone/tests/test_wsgi.py | 4 ++++ 6 files changed, 34 insertions(+), 11 deletions(-) diff --git a/keystone/tests/core.py b/keystone/tests/core.py index da5fa043d6..47c2ba2bc7 100644 --- a/keystone/tests/core.py +++ b/keystone/tests/core.py @@ -24,9 +24,7 @@ import sys import time from lxml import etree -import mox from paste import deploy -import stubout import testtools @@ -82,6 +80,7 @@ TMPDIR = os.path.join(TESTSDIR, 'tmp') CONF = config.CONF cd = os.chdir +exception._FATAL_EXCEPTION_FORMAT_ERRORS = True def rootdir(*p): @@ -259,10 +258,7 @@ class TestCase(testtools.TestCase): testsdir('test_overrides.conf')]) # ensure the cache region instance is setup cache.configure_cache_region(cache.REGION) - self.mox = mox.Mox() self.opt(policy_file=etcdir('policy.json')) - self.stubs = stubout.StubOutForTesting() - self.stubs.Set(exception, '_FATAL_EXCEPTION_FORMAT_ERRORS', True) def config(self, config_files): CONF(args=[], project='keystone', default_config_files=config_files) @@ -270,10 +266,6 @@ class TestCase(testtools.TestCase): def tearDown(self): try: timeutils.clear_time_override() - self.mox.UnsetStubs() - self.stubs.UnsetAll() - self.stubs.SmartUnsetAll() - self.mox.VerifyAll() # NOTE(morganfainberg): The only way to reconfigure the # CacheRegion object on each setUp() call is to remove the # .backend property. diff --git a/keystone/tests/test_backend_ldap.py b/keystone/tests/test_backend_ldap.py index c50c818927..57ac9bd35f 100644 --- a/keystone/tests/test_backend_ldap.py +++ b/keystone/tests/test_backend_ldap.py @@ -27,6 +27,7 @@ from keystone.common import sql from keystone import config from keystone import exception from keystone import identity +from keystone.openstack.common.fixture import moxstubout from keystone import tests from keystone.tests import default_fixtures from keystone.tests import fakeldap @@ -353,6 +354,10 @@ class LDAPIdentity(tests.TestCase, BaseLDAPIdentity): self.load_backends() self.load_fixtures(default_fixtures) + fixture = self.useFixture(moxstubout.MoxStubout()) + self.mox = fixture.mox + self.stubs = fixture.stubs + def test_configurable_allowed_project_actions(self): tenant = {'id': 'fake1', 'name': 'fake1', 'enabled': True} self.assignment_api.create_project('fake1', tenant) diff --git a/keystone/tests/test_notifications.py b/keystone/tests/test_notifications.py index fd5533d6b5..64c0387307 100644 --- a/keystone/tests/test_notifications.py +++ b/keystone/tests/test_notifications.py @@ -17,6 +17,7 @@ import uuid from keystone import notifications +from keystone.openstack.common.fixture import moxstubout from keystone.openstack.common.notifier import api as notifier_api from keystone import tests from keystone.tests import test_v3 @@ -45,6 +46,9 @@ class NotificationsWrapperTestCase(tests.TestCase): self.assertEqual(self.exp_host, host) self.send_notification_called = True + fixture = self.useFixture(moxstubout.MoxStubout()) + self.stubs = fixture.stubs + self.stubs.Set(notifications, '_send_notification', fake_notify) @notifications.created(EXP_RESOURCE_TYPE) @@ -118,6 +122,11 @@ class NotificationsWrapperTestCase(tests.TestCase): class NotificationsTestCase(tests.TestCase): + def setUp(self): + super(NotificationsTestCase, self).setUp() + fixture = self.useFixture(moxstubout.MoxStubout()) + self.stubs = fixture.stubs + def test_send_notification(self): """Test the private method _send_notification to ensure event_type, payload, and context are built and passed properly. @@ -163,6 +172,9 @@ class NotificationsForEntities(test_v3.RestfulTestCase): self.exp_resource_type = resource_type self.send_notification_called = True + fixture = self.useFixture(moxstubout.MoxStubout()) + self.stubs = fixture.stubs + self.stubs.Set(notifications, '_send_notification', fake_notify) def _assertLastNotify(self, resource_id, operation, resource_type): diff --git a/keystone/tests/test_policy.py b/keystone/tests/test_policy.py index 5fe6096692..cb641bf5b3 100644 --- a/keystone/tests/test_policy.py +++ b/keystone/tests/test_policy.py @@ -21,6 +21,7 @@ import urllib2 from keystone import config from keystone import exception +from keystone.openstack.common.fixture import moxstubout from keystone.openstack.common import policy as common_policy from keystone.policy.backends import rules from keystone import tests @@ -81,6 +82,9 @@ class PolicyTestCase(tests.TestCase): self.credentials = {} self.target = {} + fixture = self.useFixture(moxstubout.MoxStubout()) + self.stubs = fixture.stubs + def _set_rules(self): these_rules = common_policy.Rules( dict((k, common_policy.parse_rule(v)) diff --git a/keystone/tests/test_versions.py b/keystone/tests/test_versions.py index cf29876371..88c1f4c274 100644 --- a/keystone/tests/test_versions.py +++ b/keystone/tests/test_versions.py @@ -15,11 +15,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -from keystone import tests - from keystone import config from keystone import controllers +from keystone.openstack.common.fixture import moxstubout from keystone.openstack.common import jsonutils +from keystone import tests CONF = config.CONF @@ -120,6 +120,9 @@ class VersionTestCase(tests.TestCase): self.public_server = self.serveapp('keystone', name='main') self.admin_server = self.serveapp('keystone', name='admin') + fixture = self.useFixture(moxstubout.MoxStubout()) + self.stubs = fixture.stubs + def _paste_in_port(self, response, port): for link in response['links']: if link['rel'] == 'self': @@ -327,6 +330,9 @@ vnd.openstack.identity-v3+xml"/> self.public_server = self.serveapp('keystone', name='main') self.admin_server = self.serveapp('keystone', name='admin') + fixture = self.useFixture(moxstubout.MoxStubout()) + self.stubs = fixture.stubs + def test_public_versions(self): client = self.client(self.public_app) resp = client.get('/', headers=self.REQUEST_HEADERS) diff --git a/keystone/tests/test_wsgi.py b/keystone/tests/test_wsgi.py index d332164b35..df31fd11eb 100644 --- a/keystone/tests/test_wsgi.py +++ b/keystone/tests/test_wsgi.py @@ -21,6 +21,7 @@ import gettext from keystone.common import wsgi from keystone import exception +from keystone.openstack.common.fixture import moxstubout from keystone.openstack.common import gettextutils from keystone.openstack.common import jsonutils from keystone import tests @@ -224,6 +225,9 @@ class LocalizedResponseTest(tests.TestCase): super(LocalizedResponseTest, self).setUp() gettextutils._AVAILABLE_LANGUAGES.clear() + fixture = self.useFixture(moxstubout.MoxStubout()) + self.stubs = fixture.stubs + def tearDown(self): gettextutils._AVAILABLE_LANGUAGES.clear() super(LocalizedResponseTest, self).tearDown()