From cdee7e6ebfd5f412e5db5d2af1e2d3a212a91362 Mon Sep 17 00:00:00 2001 From: Gage Hugo Date: Fri, 2 Jun 2017 10:42:42 -0500 Subject: [PATCH] Remove assertRaisesRegexp testing function This change removes the function assertRaisesRegexp from within keystone to help reduce any confusion about what is really being called within the appropriate test. The test was changed to use assertRaisesRegex() which is aliased in six for python 2 and 3. assertRaisesRegexp in this change was a part of keystone itself rather than the function of the same name from python 2, and was causing confusion with recent changed regarding deprecation and python 3 changing the name to assertRaisesRegex. Change-Id: I63c84ff432e08866253cfb14ad3bb8db4a665589 --- keystone/tests/unit/core.py | 27 -------------------------- keystone/tests/unit/test_middleware.py | 6 +++--- 2 files changed, 3 insertions(+), 30 deletions(-) diff --git a/keystone/tests/unit/core.py b/keystone/tests/unit/core.py index 582357af28..70374d4162 100644 --- a/keystone/tests/unit/core.py +++ b/keystone/tests/unit/core.py @@ -21,7 +21,6 @@ import hashlib import json import ldap import os -import re import shutil import socket import sys @@ -797,32 +796,6 @@ class TestCase(BaseTestCase): def assertNotEmpty(self, l): self.assertGreater(len(l), 0) - def assertRaisesRegexp(self, expected_exception, expected_regexp, - callable_obj, *args, **kwargs): - """Assert that the message in a raised exception matches a regexp.""" - try: - callable_obj(*args, **kwargs) - except expected_exception as exc_value: - if isinstance(expected_regexp, six.string_types): - expected_regexp = re.compile(expected_regexp) - - if isinstance(exc_value.args[0], six.text_type): - if not expected_regexp.search(six.text_type(exc_value)): - raise self.failureException( - '"%s" does not match "%s"' % - (expected_regexp.pattern, six.text_type(exc_value))) - else: - if not expected_regexp.search(str(exc_value)): - raise self.failureException( - '"%s" does not match "%s"' % - (expected_regexp.pattern, str(exc_value))) - else: - if hasattr(expected_exception, '__name__'): - excName = expected_exception.__name__ - else: - excName = str(expected_exception) - raise self.failureException("%s not raised" % excName) - def assertUserDictEqual(self, expected, observed, message=''): """Assert that a user dict is equal to another user dict. diff --git a/keystone/tests/unit/test_middleware.py b/keystone/tests/unit/test_middleware.py index 3178b0ae7b..736c85f969 100644 --- a/keystone/tests/unit/test_middleware.py +++ b/keystone/tests/unit/test_middleware.py @@ -713,9 +713,9 @@ class AuthContextMiddlewareTest(test_backend_sql.SqlTests, 'request environment.' % CONF.tokenless_auth.issuer_attribute) # Check the content of the exception message as well - self.assertRaisesRegexp(exception.TokenlessAuthConfigError, - expected_msg, - auth._build_idp_id) + self.assertRaisesRegex(exception.TokenlessAuthConfigError, + expected_msg, + auth._build_idp_id) def test_admin_token_context(self): self.config_fixture.config(admin_token='ADMIN')