Refactoring: use BaseTestCase instead of TestCase
The majority of setup from TestCase isn't used by these subclasses. This means that the extra CPU work per test is wasted. Change-Id: If6c33feb7e48dd7548bd7325400a0ae9ac817d24
This commit is contained in:
parent
ab1c318d6d
commit
16ebb1c40b
|
@ -26,7 +26,7 @@ base64url_alphabet = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
|||
'-_=') # includes pad char
|
||||
|
||||
|
||||
class TestValid(tests.TestCase):
|
||||
class TestValid(tests.BaseTestCase):
|
||||
def test_valid_base64(self):
|
||||
self.assertTrue(base64utils.is_valid_base64('+/=='))
|
||||
self.assertTrue(base64utils.is_valid_base64('+/+='))
|
||||
|
@ -68,7 +68,7 @@ class TestValid(tests.TestCase):
|
|||
self.assertTrue(base64utils.is_valid_base64url('-_=='))
|
||||
|
||||
|
||||
class TestBase64Padding(tests.TestCase):
|
||||
class TestBase64Padding(tests.BaseTestCase):
|
||||
|
||||
def test_filter(self):
|
||||
self.assertEqual('', base64utils.filter_formatting(''))
|
||||
|
@ -189,7 +189,7 @@ class TestBase64Padding(tests.TestCase):
|
|||
base64utils.base64url_percent_decode, 'AB%3D%3')
|
||||
|
||||
|
||||
class TestTextWrap(tests.TestCase):
|
||||
class TestTextWrap(tests.BaseTestCase):
|
||||
|
||||
def test_wrapping(self):
|
||||
raw_text = 'abcdefgh'
|
||||
|
|
|
@ -66,7 +66,7 @@ class PEM(object):
|
|||
self.pem_text = make_pem(self.pem_header, self.data)
|
||||
|
||||
|
||||
class TestPEMParseResult(tests.TestCase):
|
||||
class TestPEMParseResult(tests.BaseTestCase):
|
||||
|
||||
def test_pem_types(self):
|
||||
for pem_type in pemutils.pem_types:
|
||||
|
@ -91,7 +91,7 @@ class TestPEMParseResult(tests.TestCase):
|
|||
pemutils.PEMParseResult, pem_header=pem_header)
|
||||
|
||||
|
||||
class TestPEMParse(tests.TestCase):
|
||||
class TestPEMParse(tests.BaseTestCase):
|
||||
def test_parse_none(self):
|
||||
text = ''
|
||||
text += 'bla bla\n'
|
||||
|
|
|
@ -14,6 +14,7 @@ import datetime
|
|||
import uuid
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_config import fixture as config_fixture
|
||||
from oslo_serialization import jsonutils
|
||||
|
||||
from keystone.common import utils as common_utils
|
||||
|
@ -28,9 +29,13 @@ CONF = cfg.CONF
|
|||
TZ = utils.TZ
|
||||
|
||||
|
||||
class UtilsTestCase(tests.TestCase):
|
||||
class UtilsTestCase(tests.BaseTestCase):
|
||||
OPTIONAL = object()
|
||||
|
||||
def setUp(self):
|
||||
super(UtilsTestCase, self).setUp()
|
||||
self.config_fixture = self.useFixture(config_fixture.Config(CONF))
|
||||
|
||||
def test_hash(self):
|
||||
password = 'right'
|
||||
wrong = 'wrongwrong' # Two wrongs don't make a right
|
||||
|
@ -149,7 +154,7 @@ class UtilsTestCase(tests.TestCase):
|
|||
self.assertEqual(expected_json, json)
|
||||
|
||||
|
||||
class ServiceHelperTests(tests.TestCase):
|
||||
class ServiceHelperTests(tests.BaseTestCase):
|
||||
|
||||
@service.fail_gracefully
|
||||
def _do_test(self):
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
|
||||
import uuid
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_config import fixture as config_fixture
|
||||
from oslo_serialization import jsonutils
|
||||
import six
|
||||
|
||||
|
@ -22,7 +24,7 @@ from keystone import exception
|
|||
from keystone.tests import unit as tests
|
||||
|
||||
|
||||
class ExceptionTestCase(tests.TestCase):
|
||||
class ExceptionTestCase(tests.BaseTestCase):
|
||||
def assertValidJsonRendering(self, e):
|
||||
resp = wsgi.render_exception(e)
|
||||
self.assertEqual(e.code, resp.status_int)
|
||||
|
@ -105,6 +107,7 @@ class UnexpectedExceptionTestCase(ExceptionTestCase):
|
|||
def setUp(self):
|
||||
super(UnexpectedExceptionTestCase, self).setUp()
|
||||
self.exc_str = uuid.uuid4().hex
|
||||
self.config_fixture = self.useFixture(config_fixture.Config(cfg.CONF))
|
||||
|
||||
def test_unexpected_error_no_debug(self):
|
||||
self.config_fixture.config(debug=False)
|
||||
|
@ -151,6 +154,11 @@ class UnexpectedExceptionTestCase(ExceptionTestCase):
|
|||
|
||||
class SecurityErrorTestCase(ExceptionTestCase):
|
||||
"""Tests whether security-related info is exposed to the API user."""
|
||||
|
||||
def setUp(self):
|
||||
super(SecurityErrorTestCase, self).setUp()
|
||||
self.config_fixture = self.useFixture(config_fixture.Config(cfg.CONF))
|
||||
|
||||
def test_unauthorized_exposure(self):
|
||||
self.config_fixture.config(debug=False)
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ from keystone.tests import unit
|
|||
from keystone.token import provider
|
||||
|
||||
|
||||
class TestRandomStrings(unit.TestCase):
|
||||
class TestRandomStrings(unit.BaseTestCase):
|
||||
def test_strings_are_url_safe(self):
|
||||
s = provider.random_urlsafe_str()
|
||||
self.assertEqual(s, urllib.quote_plus(s))
|
||||
|
|
Loading…
Reference in New Issue