Test: Use assertIsNone() in unittest

Use assertIsNone() instead of assertEqual(), because assertEqual()
still fails on false values when compared to None

Change-Id: Ic52c319e3e55135df834fdf857982e1721bc44bb
This commit is contained in:
junboli 2017-06-25 10:29:23 +08:00 committed by junbo.li
parent 2d18ecdf4b
commit 99a6d3b30a
8 changed files with 41 additions and 45 deletions

View File

@ -262,7 +262,7 @@ class TestDloHeadManifest(DloTestCase):
# etag is manifest's etag
self.assertEqual(headers["Etag"], "etag-manyseg")
self.assertEqual(headers.get("Content-Length"), None)
self.assertIsNone(headers.get("Content-Length"))
def test_head_large_object_no_segments(self):
req = swob.Request.blank('/v1/AUTH_test/mancon/manifest-no-segments',
@ -459,7 +459,7 @@ class TestDloGetManifest(DloTestCase):
self.assertEqual(status, "200 OK")
# this requires multiple pages of container listing, so we can't send
# a Content-Length header
self.assertEqual(headers.get("Content-Length"), None)
self.assertIsNone(headers.get("Content-Length"))
self.assertEqual(body, "aaaaabbbbbcccccdddddeeeee")
def test_get_suffix_range(self):
@ -480,8 +480,8 @@ class TestDloGetManifest(DloTestCase):
status, headers, body = self.call_dlo(req)
headers = HeaderKeyDict(headers)
self.assertEqual(status, "200 OK")
self.assertEqual(headers.get("Content-Length"), None)
self.assertEqual(headers.get("Content-Range"), None)
self.assertIsNone(headers.get("Content-Length"))
self.assertIsNone(headers.get("Content-Range"))
self.assertEqual(body, "aaaaabbbbbcccccdddddeeeee")
def test_get_multi_range(self):
@ -494,8 +494,8 @@ class TestDloGetManifest(DloTestCase):
status, headers, body = self.call_dlo(req)
headers = HeaderKeyDict(headers)
self.assertEqual(status, "200 OK")
self.assertEqual(headers.get("Content-Length"), None)
self.assertEqual(headers.get("Content-Range"), None)
self.assertIsNone(headers.get("Content-Length"))
self.assertIsNone(headers.get("Content-Range"))
self.assertEqual(body, "aaaaabbbbbcccccdddddeeeee")
def test_if_match_matches(self):

View File

@ -169,10 +169,10 @@ class TestRateLimit(unittest.TestCase):
'container_ratelimit_75': 30}
test_ratelimit = ratelimit.filter_factory(conf_dict)(FakeApp())
test_ratelimit.logger = FakeLogger()
self.assertEqual(ratelimit.get_maxrate(
test_ratelimit.container_ratelimits, 0), None)
self.assertEqual(ratelimit.get_maxrate(
test_ratelimit.container_ratelimits, 5), None)
self.assertIsNone(ratelimit.get_maxrate(
test_ratelimit.container_ratelimits, 0))
self.assertIsNone(ratelimit.get_maxrate(
test_ratelimit.container_ratelimits, 5))
self.assertEqual(ratelimit.get_maxrate(
test_ratelimit.container_ratelimits, 10), 200)
self.assertEqual(ratelimit.get_maxrate(
@ -487,9 +487,8 @@ class TestRateLimit(unittest.TestCase):
mc = self.test_ratelimit.memcache_client
try:
self.test_ratelimit.memcache_client = None
self.assertEqual(
self.test_ratelimit.handle_ratelimit(req, 'n', 'c', None),
None)
self.assertIsNone(
self.test_ratelimit.handle_ratelimit(req, 'n', 'c', None))
finally:
self.test_ratelimit.memcache_client = mc

View File

@ -1367,16 +1367,14 @@ class PrefixAccount(unittest.TestCase):
test_auth = auth.filter_factory(conf)(FakeApp())
self.assertEqual(test_auth._get_account_prefix(
'AUTH_1234'), 'AUTH_')
self.assertEqual(test_auth._get_account_prefix(
'JUNK_1234'), None)
self.assertIsNone(test_auth._get_account_prefix('JUNK_1234'))
def test_same_as_default(self):
conf = {'reseller_prefix': 'AUTH'}
test_auth = auth.filter_factory(conf)(FakeApp())
self.assertEqual(test_auth._get_account_prefix(
'AUTH_1234'), 'AUTH_')
self.assertEqual(test_auth._get_account_prefix(
'JUNK_1234'), None)
self.assertIsNone(test_auth._get_account_prefix('JUNK_1234'))
def test_blank_reseller(self):
conf = {'reseller_prefix': ''}
@ -1391,8 +1389,7 @@ class PrefixAccount(unittest.TestCase):
test_auth = auth.filter_factory(conf)(FakeApp())
self.assertEqual(test_auth._get_account_prefix(
'AUTH_1234'), 'AUTH_')
self.assertEqual(test_auth._get_account_prefix(
'JUNK_1234'), None)
self.assertIsNone(test_auth._get_account_prefix('JUNK_1234'))
class ServiceTokenFunctionality(unittest.TestCase):

View File

@ -40,13 +40,13 @@ class TestConstraints(unittest.TestCase):
def test_check_metadata_empty(self):
headers = {}
self.assertEqual(constraints.check_metadata(Request.blank(
'/', headers=headers), 'object'), None)
self.assertIsNone(constraints.check_metadata(Request.blank(
'/', headers=headers), 'object'))
def test_check_metadata_good(self):
headers = {'X-Object-Meta-Name': 'Value'}
self.assertEqual(constraints.check_metadata(Request.blank(
'/', headers=headers), 'object'), None)
self.assertIsNone(constraints.check_metadata(Request.blank(
'/', headers=headers), 'object'))
def test_check_metadata_empty_name(self):
headers = {'X-Object-Meta-': 'Value'}
@ -75,8 +75,8 @@ class TestConstraints(unittest.TestCase):
def test_check_metadata_name_length(self):
name = 'a' * constraints.MAX_META_NAME_LENGTH
headers = {'X-Object-Meta-%s' % name: 'v'}
self.assertEqual(constraints.check_metadata(Request.blank(
'/', headers=headers), 'object'), None)
self.assertIsNone(constraints.check_metadata(Request.blank(
'/', headers=headers), 'object'))
name = 'a' * (constraints.MAX_META_NAME_LENGTH + 1)
headers = {'X-Object-Meta-%s' % name: 'v'}
@ -90,8 +90,8 @@ class TestConstraints(unittest.TestCase):
def test_check_metadata_value_length(self):
value = 'a' * constraints.MAX_META_VALUE_LENGTH
headers = {'X-Object-Meta-Name': value}
self.assertEqual(constraints.check_metadata(Request.blank(
'/', headers=headers), 'object'), None)
self.assertIsNone(constraints.check_metadata(Request.blank(
'/', headers=headers), 'object'))
value = 'a' * (constraints.MAX_META_VALUE_LENGTH + 1)
headers = {'X-Object-Meta-Name': value}
@ -107,8 +107,8 @@ class TestConstraints(unittest.TestCase):
headers = {}
for x in range(constraints.MAX_META_COUNT):
headers['X-Object-Meta-%d' % x] = 'v'
self.assertEqual(constraints.check_metadata(Request.blank(
'/', headers=headers), 'object'), None)
self.assertIsNone(constraints.check_metadata(Request.blank(
'/', headers=headers), 'object'))
headers['X-Object-Meta-Too-Many'] = 'v'
resp = constraints.check_metadata(Request.blank(
@ -128,8 +128,8 @@ class TestConstraints(unittest.TestCase):
'v' * constraints.MAX_META_VALUE_LENGTH
size += chunk
x += 1
self.assertEqual(constraints.check_metadata(Request.blank(
'/', headers=headers), 'object'), None)
self.assertIsNone(constraints.check_metadata(Request.blank(
'/', headers=headers), 'object'))
# add two more headers in case adding just one falls exactly on the
# limit (eg one header adds 1024 and the limit is 2048)
headers['X-Object-Meta-%04d%s' %
@ -146,8 +146,8 @@ class TestConstraints(unittest.TestCase):
def test_check_object_creation_content_length(self):
headers = {'Content-Length': str(constraints.MAX_FILE_SIZE),
'Content-Type': 'text/plain'}
self.assertEqual(constraints.check_object_creation(Request.blank(
'/', headers=headers), 'object_name'), None)
self.assertIsNone(constraints.check_object_creation(Request.blank(
'/', headers=headers), 'object_name'))
headers = {'Content-Length': str(constraints.MAX_FILE_SIZE + 1),
'Content-Type': 'text/plain'}
@ -157,8 +157,8 @@ class TestConstraints(unittest.TestCase):
headers = {'Transfer-Encoding': 'chunked',
'Content-Type': 'text/plain'}
self.assertEqual(constraints.check_object_creation(Request.blank(
'/', headers=headers), 'object_name'), None)
self.assertIsNone(constraints.check_object_creation(Request.blank(
'/', headers=headers), 'object_name'))
headers = {'Transfer-Encoding': 'gzip',
'Content-Type': 'text/plain'}
@ -189,8 +189,8 @@ class TestConstraints(unittest.TestCase):
headers = {'Transfer-Encoding': 'chunked',
'Content-Type': 'text/plain'}
name = 'o' * constraints.MAX_OBJECT_NAME_LENGTH
self.assertEqual(constraints.check_object_creation(Request.blank(
'/', headers=headers), name), None)
self.assertIsNone(constraints.check_object_creation(Request.blank(
'/', headers=headers), name))
name = 'o' * (MAX_OBJECT_NAME_LENGTH + 1)
resp = constraints.check_object_creation(
@ -203,8 +203,8 @@ class TestConstraints(unittest.TestCase):
def test_check_object_creation_content_type(self):
headers = {'Transfer-Encoding': 'chunked',
'Content-Type': 'text/plain'}
self.assertEqual(constraints.check_object_creation(Request.blank(
'/', headers=headers), 'object_name'), None)
self.assertIsNone(constraints.check_object_creation(Request.blank(
'/', headers=headers), 'object_name'))
headers = {'Transfer-Encoding': 'chunked'}
resp = constraints.check_object_creation(

View File

@ -1432,8 +1432,8 @@ class TestReplToNode(unittest.TestCase):
def test_repl_to_node_300_status(self):
self.http = ReplHttp('{"id": 3, "point": -1}', set_status=300)
self.assertEqual(self.replicator._repl_to_node(
self.fake_node, FakeBroker(), '0', self.fake_info), None)
self.assertIsNone(self.replicator._repl_to_node(
self.fake_node, FakeBroker(), '0', self.fake_info))
def test_repl_to_node_not_response(self):
self.http = mock.Mock(replicate=mock.Mock(return_value=None))

View File

@ -128,7 +128,7 @@ class TestManagerModule(unittest.TestCase):
manager.resource = MockResource(error=OSError())
manager.os.environ = {}
self.assertRaises(OSError, manager.setup_env)
self.assertEqual(manager.os.environ.get('PYTHON_EGG_CACHE'), None)
self.assertIsNone(manager.os.environ.get('PYTHON_EGG_CACHE'))
finally:
manager.resource = _orig_resource
os.environ = _orig_environ

View File

@ -572,7 +572,7 @@ class TestStoragePolicies(unittest.TestCase):
# remove name
policies.remove_policy_alias('tahi')
self.assertEqual(policies.get_by_name('tahi'), None)
self.assertIsNone(policies.get_by_name('tahi'))
# remove only name
self.assertRaisesWithMessage(PolicyError,
@ -586,7 +586,7 @@ class TestStoragePolicies(unittest.TestCase):
# remove default name
policies.remove_policy_alias('two')
self.assertEqual(policies.get_by_name('two'), None)
self.assertIsNone(policies.get_by_name('two'))
self.assertEqual(policies.get_by_index(2).name, 'rua')
# change default name to a new name

View File

@ -604,7 +604,7 @@ class TestWSGI(unittest.TestCase):
environ = {}
if headers is None:
headers = {}
self.assertEqual(environ['swift.authorize']('test'), None)
self.assertIsNone(environ['swift.authorize']('test'))
self.assertFalse('HTTP_X_TRANS_ID' in environ)
was_blank = Request.blank
Request.blank = FakeReq.fake_blank