Unit tests catch deprecated function usage

Rather than continue to call deprecated functions without knowing
it, have the unit tests fail when deprecated function is used.

This will ensure that code isn't added that calls deprecated
functions.

Change-Id: If9f58e30a08a88778e4ae3fc01399ad90997e812
This commit is contained in:
Brant Knudson 2015-06-08 20:36:02 -05:00
parent 225832f591
commit 31f326dab6
7 changed files with 38 additions and 1 deletions

@ -13,6 +13,7 @@
# under the License.
import os
import warnings
import fixtures
from oslo_serialization import jsonutils
@ -595,3 +596,14 @@ class HackingCode(fixtures.Fixture):
(30, 0, 'K333'),
],
}
class Deprecations(fixtures.Fixture):
def setUp(self):
super(Deprecations, self).setUp()
# If keystoneclient calls any deprecated function this will raise an
# exception.
warnings.filterwarnings('error', category=DeprecationWarning,
module='^keystoneclient\\.')
self.addCleanup(warnings.resetwarnings)

@ -206,7 +206,9 @@ class BaseAuthTokenMiddlewareTest(testtools.TestCase):
"""
def setUp(self, expected_env=None, auth_version=None, fake_app=None):
testtools.TestCase.setUp(self)
super(BaseAuthTokenMiddlewareTest, self).setUp()
self.useFixture(client_fixtures.Deprecations())
self.expected_env = expected_env or dict()
self.fake_app = fake_app or FakeApp
@ -1673,6 +1675,10 @@ class v3AuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest,
class TokenEncodingTest(testtools.TestCase):
def setUp(self):
super(TokenEncodingTest, self).setUp()
self.useFixture(client_fixtures.Deprecations())
def test_unquoted_token(self):
self.assertEqual('foo%20bar', auth_token.safe_quote('foo bar'))

@ -17,12 +17,14 @@ from __future__ import unicode_literals
import testtools
from keystoneclient.contrib.ec2 import utils
from keystoneclient.tests.unit import client_fixtures
class Ec2SignerTest(testtools.TestCase):
def setUp(self):
super(Ec2SignerTest, self).setUp()
self.useFixture(client_fixtures.Deprecations())
self.access = '966afbde20b84200ae4e62e09acf46b2'
self.secret = '89cdf9e94e2643cab35b8b8ac5a51f83'
self.signer = utils.Ec2Signer(self.secret)

@ -21,6 +21,9 @@ from keystoneclient.tests.unit import client_fixtures
class TestCheckOsloNamespaceImports(testtools.TestCase):
def setUp(self):
super(TestCheckOsloNamespaceImports, self).setUp()
self.useFixture(client_fixtures.Deprecations())
# We are patching pep8 so that only the check under test is actually
# installed.

@ -14,9 +14,14 @@ import six
import testtools
from keystoneclient.middleware import memcache_crypt
from keystoneclient.tests.unit import client_fixtures
class MemcacheCryptPositiveTests(testtools.TestCase):
def setUp(self):
super(MemcacheCryptPositiveTests, self).setUp()
self.useFixture(client_fixtures.Deprecations())
def _setup_keys(self, strategy):
return memcache_crypt.derive_keys(b'token', b'secret', strategy)

@ -20,6 +20,7 @@ import testtools
import webob
from keystoneclient.middleware import s3_token
from keystoneclient.tests.unit import client_fixtures
from keystoneclient.tests.unit import utils
@ -221,6 +222,10 @@ class S3TokenMiddlewareTestBad(S3TokenMiddlewareTestBase):
class S3TokenMiddlewareTestUtil(testtools.TestCase):
def setUp(self):
super(S3TokenMiddlewareTestUtil, self).setUp()
self.useFixture(client_fixtures.Deprecations())
def test_split_path_failed(self):
self.assertRaises(ValueError, s3_token.split_path, '')
self.assertRaises(ValueError, s3_token.split_path, '/')

@ -24,6 +24,8 @@ import six
from six.moves.urllib import parse as urlparse
import testtools
from keystoneclient.tests.unit import client_fixtures
class TestCase(testtools.TestCase):
@ -42,6 +44,8 @@ class TestCase(testtools.TestCase):
def setUp(self):
super(TestCase, self).setUp()
self.useFixture(client_fixtures.Deprecations())
self.logger = self.useFixture(fixtures.FakeLogger(level=logging.DEBUG))
self.time_patcher = self.useFixture(
mockpatch.PatchObject(time, 'time', lambda: 1234)).mock