Modify assert statement when comparing with None

Replace assertEqual(None, *) with assertIsNone in glance's
tests to have more clear messages in case of failure.

Also, replace assertTrue(* is not None) with assertIsNotNone
for the same reason.

Change-Id: If41a71bd750057c7136b03bef94c04517092134c
Closes-Bug: #1280522
changes/84/73784/2
Jia Dong 9 years ago
parent 5959c38005
commit 8d4312a2c9
  1. 32
      glance/tests/functional/db/base.py
  2. 2
      glance/tests/functional/test_gzip_middleware.py
  3. 4
      glance/tests/functional/v1/test_ssl.py
  4. 4
      glance/tests/integration/legacy_functional/test_v1_api.py
  5. 2
      glance/tests/unit/api/middleware/test_cache_manage.py
  6. 4
      glance/tests/unit/common/test_location_strategy.py
  7. 2
      glance/tests/unit/test_auth.py
  8. 6
      glance/tests/unit/test_cache_middleware.py
  9. 12
      glance/tests/unit/test_context_middleware.py
  10. 24
      glance/tests/unit/test_domain.py
  11. 20
      glance/tests/unit/test_store_location.py
  12. 14
      glance/tests/unit/test_swift_store.py
  13. 6
      glance/tests/unit/v1/test_registry_client.py
  14. 2
      glance/tests/unit/v2/test_image_data_resource.py
  15. 8
      glance/tests/unit/v2/test_images_resource.py
  16. 4
      glance/tests/unit/v2/test_registry_client.py

@ -137,19 +137,19 @@ class DriverTests(object):
'updated_at': create_time}
image = self.db_api.image_create(self.context, values)
self.assertEqual(None, image['name'])
self.assertEqual(None, image['container_format'])
self.assertIsNone(image['name'])
self.assertIsNone(image['container_format'])
self.assertEqual(0, image['min_ram'])
self.assertEqual(0, image['min_disk'])
self.assertEqual(None, image['owner'])
self.assertIsNone(image['owner'])
self.assertEqual(False, image['is_public'])
self.assertEqual(None, image['size'])
self.assertEqual(None, image['checksum'])
self.assertEqual(None, image['disk_format'])
self.assertIsNone(image['size'])
self.assertIsNone(image['checksum'])
self.assertIsNone(image['disk_format'])
self.assertEqual([], image['locations'])
self.assertEqual(False, image['protected'])
self.assertEqual(False, image['deleted'])
self.assertEqual(None, image['deleted_at'])
self.assertIsNone(image['deleted_at'])
self.assertEqual([], image['properties'])
self.assertEqual(image['created_at'], create_time)
self.assertEqual(image['updated_at'], create_time)
@ -259,7 +259,7 @@ class DriverTests(object):
prop = self.db_api.image_property_create(self.context, fixture)
prop = self.db_api.image_property_delete(self.context,
prop['name'], UUID1)
self.assertNotEqual(prop['deleted_at'], None)
self.assertIsNotNone(prop['deleted_at'])
self.assertTrue(prop['deleted'])
def test_image_get(self):
@ -959,8 +959,8 @@ class DriverTests(object):
memberships = self.db_api.image_member_find(self.context)
self.assertEqual(1, len(memberships))
actual = memberships[0]
self.assertNotEqual(actual['created_at'], None)
self.assertNotEqual(actual['updated_at'], None)
self.assertIsNotNone(actual['created_at'])
self.assertIsNotNone(actual['updated_at'])
actual.pop('id')
actual.pop('created_at')
actual.pop('updated_at')
@ -1504,9 +1504,9 @@ class TaskTests(test_utils.BaseTestCase):
self.assertEqual(task['owner'], self.context.owner)
self.assertEqual(task['type'], 'export')
self.assertEqual(task['status'], 'pending')
self.assertEqual(task['input'], None)
self.assertEqual(task['result'], None)
self.assertEqual(task['message'], None)
self.assertIsNone(task['input'])
self.assertIsNone(task['result'])
self.assertIsNone(task['message'])
def test_task_update(self):
self.context.tenant = str(uuid.uuid4())
@ -1551,9 +1551,9 @@ class TaskTests(test_utils.BaseTestCase):
self.assertEqual(task['owner'], self.context.owner)
self.assertEqual(task['type'], 'import')
self.assertEqual(task['status'], 'processing')
self.assertEqual(task['input'], None)
self.assertEqual(task['result'], None)
self.assertEqual(task['message'], None)
self.assertIsNone(task['input'])
self.assertIsNone(task['result'])
self.assertIsNone(task['message'])
self.assertEqual(task['deleted'], False)
self.assertIsNone(task['deleted_at'])
self.assertIsNone(task['expires_at'])

@ -38,7 +38,7 @@ class GzipMiddlewareTest(functional.FunctionalTest):
# Accept-Encoding: Identity
headers = {'Accept-Encoding': 'identity'}
response, content = request('images', headers=headers)
self.assertEqual(response.get("-content-encoding"), None)
self.assertIsNone(response.get("-content-encoding"))
# Accept-Encoding: gzip
headers = {'Accept-Encoding': 'gzip'}

@ -379,7 +379,7 @@ class TestSSL(functional.FunctionalTest):
response, content = https.request(path, 'POST', headers=headers)
self.assertEqual(response.status, 201)
data = jsonutils.loads(content)
self.assertEqual(data['image']['checksum'], None)
self.assertIsNone(data['image']['checksum'])
self.assertEqual(data['image']['size'], 0)
self.assertEqual(data['image']['container_format'], 'ovf')
self.assertEqual(data['image']['disk_format'], 'raw')
@ -396,7 +396,7 @@ class TestSSL(functional.FunctionalTest):
self.assertEqual(response.status, 200)
data = jsonutils.loads(content)
self.assertEqual(data['images'][0]['id'], image_id)
self.assertEqual(data['images'][0]['checksum'], None)
self.assertIsNone(data['images'][0]['checksum'])
self.assertEqual(data['images'][0]['size'], 0)
self.assertEqual(data['images'][0]['container_format'], 'ovf')
self.assertEqual(data['images'][0]['disk_format'], 'raw')

@ -255,7 +255,7 @@ class TestApi(base.ApiTest):
response, content = self.http.request(path, 'POST', headers=headers)
self.assertEqual(response.status, 201)
data = jsonutils.loads(content)
self.assertEqual(data['image']['checksum'], None)
self.assertIsNone(data['image']['checksum'])
self.assertEqual(data['image']['size'], 0)
self.assertEqual(data['image']['container_format'], 'ovf')
self.assertEqual(data['image']['disk_format'], 'raw')
@ -271,7 +271,7 @@ class TestApi(base.ApiTest):
self.assertEqual(response.status, 200)
data = jsonutils.loads(content)
self.assertEqual(data['images'][0]['id'], image_id)
self.assertEqual(data['images'][0]['checksum'], None)
self.assertIsNone(data['images'][0]['checksum'])
self.assertEqual(data['images'][0]['size'], 0)
self.assertEqual(data['images'][0]['container_format'], 'ovf')
self.assertEqual(data['images'][0]['disk_format'], 'raw')

@ -42,7 +42,7 @@ class TestCacheManageFilter(test_utils.BaseTestCase):
resource = self.cache_manage_filter.process_request(bogus_request)
#check
self.assertEqual(None, resource)
self.assertIsNone(resource)
@mock.patch.object(cached_images.Controller, "get_cached_images")
def test_get_cached_images(self,

@ -129,8 +129,8 @@ class TestLocationStrategy(base.IsolatedUnitTest):
self.assertEqual(original_locs, ordered_locs)
def test_choose_best_location_with_none_or_empty_locations(self):
self.assertEqual(location_strategy.choose_best_location(None), None)
self.assertEqual(location_strategy.choose_best_location([]), None)
self.assertIsNone(location_strategy.choose_best_location(None))
self.assertIsNone(location_strategy.choose_best_location([]))
def test_choose_best_location(self):
self.config(location_strategy='location_order')

@ -803,7 +803,7 @@ class TestImageFactoryProxy(utils.BaseTestCase):
def test_admin_can_set_owner_to_none(self):
self.context.is_admin = True
image = self.image_factory.new_image(owner=None)
self.assertEqual(image.owner, None)
self.assertIsNone(image.owner)
def test_admin_still_gets_default_tenant(self):
self.context.is_admin = True

@ -77,7 +77,7 @@ class TestCacheMiddlewareRequestStashCacheInfo(testtools.TestCase):
def test_fetch_cache_request_info_unset(self):
out = self.middleware._fetch_request_info(self.request)
self.assertEqual(out, None)
self.assertIsNone(out)
class ChecksumTestCacheFilter(glance.api.middleware.cache.CacheFilter):
@ -121,7 +121,7 @@ class TestCacheMiddlewareChecksumVerification(base.IsolatedUnitTest):
resp = webob.Response(request=self.request)
cache_filter._process_GET_response(resp, None)
self.assertEqual(None, cache_filter.cache.image_checksum)
self.assertIsNone(cache_filter.cache.image_checksum)
class FakeImageSerializer(object):
@ -327,7 +327,7 @@ class TestCacheMiddlewareProcessRequest(base.IsolatedUnitTest):
self.set_policy_rules(rules)
cache_filter.policy = glance.api.policy.Enforcer()
self.assertEqual(None, cache_filter.process_request(request))
self.assertIsNone(cache_filter.process_request(request))
class TestCacheMiddlewareProcessResponse(base.IsolatedUnitTest):

@ -92,9 +92,9 @@ class TestContextMiddleware(base.IsolatedUnitTest):
self.config(allow_anonymous_access=True)
middleware = self._build_middleware()
middleware.process_request(req)
self.assertEqual(req.context.auth_tok, None)
self.assertEqual(req.context.user, None)
self.assertEqual(req.context.tenant, None)
self.assertIsNone(req.context.auth_tok)
self.assertIsNone(req.context.user)
self.assertIsNone(req.context.tenant)
self.assertEqual(req.context.roles, [])
self.assertFalse(req.context.is_admin)
self.assertTrue(req.context.read_only)
@ -124,9 +124,9 @@ class TestUnauthenticatedContextMiddleware(base.IsolatedUnitTest):
middleware = context.UnauthenticatedContextMiddleware(None)
req = webob.Request.blank('/')
middleware.process_request(req)
self.assertEqual(req.context.auth_tok, None)
self.assertEqual(req.context.user, None)
self.assertEqual(req.context.tenant, None)
self.assertIsNone(req.context.auth_tok)
self.assertIsNone(req.context.user)
self.assertIsNone(req.context.tenant)
self.assertEqual(req.context.roles, [])
self.assertTrue(req.context.is_admin)

@ -46,14 +46,14 @@ class TestImageFactory(test_utils.BaseTestCase):
self.assertEqual(image.created_at, image.updated_at)
self.assertEqual(image.status, 'queued')
self.assertEqual(image.visibility, 'private')
self.assertEqual(image.owner, None)
self.assertEqual(image.name, None)
self.assertEqual(image.size, None)
self.assertIsNone(image.owner)
self.assertIsNone(image.name)
self.assertIsNone(image.size)
self.assertEqual(image.min_disk, 0)
self.assertEqual(image.min_ram, 0)
self.assertEqual(image.protected, False)
self.assertEqual(image.disk_format, None)
self.assertEqual(image.container_format, None)
self.assertIsNone(image.disk_format)
self.assertIsNone(image.container_format)
self.assertEqual(image.extra_properties, {})
self.assertEqual(image.tags, set([]))
@ -68,12 +68,12 @@ class TestImageFactory(test_utils.BaseTestCase):
self.assertEqual(image.visibility, 'private')
self.assertEqual(image.owner, TENANT1)
self.assertEqual(image.name, 'image-1')
self.assertEqual(image.size, None)
self.assertIsNone(image.size)
self.assertEqual(image.min_disk, 256)
self.assertEqual(image.min_ram, 0)
self.assertEqual(image.protected, False)
self.assertEqual(image.disk_format, None)
self.assertEqual(image.container_format, None)
self.assertIsNone(image.disk_format)
self.assertIsNone(image.container_format)
self.assertEqual(image.extra_properties, {})
self.assertEqual(image.tags, set([]))
@ -89,14 +89,14 @@ class TestImageFactory(test_utils.BaseTestCase):
self.assertEqual(image.created_at, image.updated_at)
self.assertEqual(image.status, 'queued')
self.assertEqual(image.visibility, 'private')
self.assertEqual(image.owner, None)
self.assertIsNone(image.owner)
self.assertEqual(image.name, 'image-1')
self.assertEqual(image.size, None)
self.assertIsNone(image.size)
self.assertEqual(image.min_disk, 0)
self.assertEqual(image.min_ram, 0)
self.assertEqual(image.protected, False)
self.assertEqual(image.disk_format, None)
self.assertEqual(image.container_format, None)
self.assertIsNone(image.disk_format)
self.assertIsNone(image.container_format)
self.assertEqual(image.extra_properties, {'foo': 'bar'})
self.assertEqual(image.tags, set(['one', 'two']))

@ -154,7 +154,7 @@ class TestStoreLocation(base.StoreClearingUnitTest):
self.assertEqual("https://example.com", loc.swift_url)
self.assertEqual("images", loc.container)
self.assertEqual("1", loc.obj)
self.assertEqual(None, loc.user)
self.assertIsNone(loc.user)
self.assertEqual(uri, loc.get_uri())
uri = 'swift+https://user:pass@authurl.com/images/1'
@ -203,8 +203,8 @@ class TestStoreLocation(base.StoreClearingUnitTest):
self.assertEqual("http://storeurl.com/v1", loc.swift_url)
self.assertEqual("container", loc.container)
self.assertEqual("12345", loc.obj)
self.assertEqual(None, loc.user)
self.assertEqual(None, loc.key)
self.assertIsNone(loc.user)
self.assertIsNone(loc.key)
self.assertEqual(uri, loc.get_uri())
bad_uri = 'swif://'
@ -231,7 +231,7 @@ class TestStoreLocation(base.StoreClearingUnitTest):
self.assertEqual("example.com", loc.s3serviceurl)
self.assertEqual("images", loc.bucket)
self.assertEqual("1", loc.key)
self.assertEqual(None, loc.accesskey)
self.assertIsNone(loc.accesskey)
self.assertEqual(uri, loc.get_uri())
uri = 's3+https://accesskey:pass@s3serviceurl.com/images/1'
@ -288,18 +288,18 @@ class TestStoreLocation(base.StoreClearingUnitTest):
loc.parse_uri(uri)
self.assertEqual('imagename', loc.image)
self.assertEqual(None, loc.fsid)
self.assertEqual(None, loc.pool)
self.assertEqual(None, loc.snapshot)
self.assertIsNone(loc.fsid)
self.assertIsNone(loc.pool)
self.assertIsNone(loc.snapshot)
uri = u'rbd://imagename'
loc = glance.store.rbd.StoreLocation({})
loc.parse_uri(uri)
self.assertEqual('imagename', loc.image)
self.assertEqual(None, loc.fsid)
self.assertEqual(None, loc.pool)
self.assertEqual(None, loc.snapshot)
self.assertIsNone(loc.fsid)
self.assertIsNone(loc.pool)
self.assertIsNone(loc.snapshot)
uri = 'rbd://fsid/pool/image/snap'
loc = glance.store.rbd.StoreLocation({})

@ -789,8 +789,8 @@ class TestSingleTenantStoreConnections(base.IsolatedUnitTest):
self.assertEqual(connection.tenant_name, 'tenant')
self.assertEqual(connection.key, 'abcdefg')
self.assertFalse(connection.snet)
self.assertEqual(connection.preauthurl, None)
self.assertEqual(connection.preauthtoken, None)
self.assertIsNone(connection.preauthurl)
self.assertIsNone(connection.preauthtoken)
self.assertFalse(connection.insecure)
self.assertEqual(connection.os_options,
{'service_type': 'object-store',
@ -814,7 +814,7 @@ class TestSingleTenantStoreConnections(base.IsolatedUnitTest):
connection = self.store.get_connection(self.location)
self.assertEqual(connection.auth_version, '1')
self.assertEqual(connection.user, 'auth_v1_user')
self.assertEqual(connection.tenant_name, None)
self.assertIsNone(connection.tenant_name)
def test_connection_invalid_user(self):
self.store.configure()
@ -876,11 +876,11 @@ class TestMultiTenantStoreConnections(base.IsolatedUnitTest):
def test_basic_connection(self):
self.store.configure()
connection = self.store.get_connection(self.location)
self.assertEqual(connection.authurl, None)
self.assertIsNone(connection.authurl)
self.assertEqual(connection.auth_version, '2')
self.assertEqual(connection.user, 'user')
self.assertEqual(connection.tenant_name, 'tenant')
self.assertEqual(connection.key, None)
self.assertIsNone(connection.key)
self.assertFalse(connection.snet)
self.assertEqual(connection.preauthurl, 'https://example.com')
self.assertEqual(connection.preauthtoken, '0123')
@ -943,8 +943,8 @@ class TestCreatingLocations(base.IsolatedUnitTest):
self.assertEqual(location.swift_url, 'https://some_endpoint')
self.assertEqual(location.container, 'container_image-id')
self.assertEqual(location.obj, 'image-id')
self.assertEqual(location.user, None)
self.assertEqual(location.key, None)
self.assertIsNone(location.user)
self.assertIsNone(location.key)
self.assertEqual(fake_get_endpoint.service_type, 'object-store')
def test_multi_tenant_location_http(self):

@ -849,7 +849,7 @@ class TestRegistryV1ClientApi(base.IsolatedUnitTest):
def test_get_registry_client(self):
actual_client = rapi.get_registry_client(self.context)
self.assertEqual(actual_client.identity_headers, None)
self.assertIsNone(actual_client.identity_headers)
def test_get_registry_client_with_identity_headers(self):
self.config(send_identity_headers=True)
@ -895,7 +895,7 @@ class TestRegistryV1ClientApi(base.IsolatedUnitTest):
self.config(auth_region=expected['region'])
self.stubs.Set(os, 'getenv', lambda x: None)
self.assertEqual(rapi._CLIENT_CREDS, None)
self.assertIsNone(rapi._CLIENT_CREDS)
rapi.configure_registry_admin_creds()
self.assertEqual(rapi._CLIENT_CREDS, expected)
@ -908,7 +908,7 @@ class TestRegistryV1ClientApi(base.IsolatedUnitTest):
self.config(auth_strategy='test_strategy')
self.config(auth_region=expected['region'])
self.assertEqual(rapi._CLIENT_CREDS, None)
self.assertIsNone(rapi._CLIENT_CREDS)
rapi.configure_registry_admin_creds()
self.assertEqual(rapi._CLIENT_CREDS, expected)

@ -169,7 +169,7 @@ class TestImagesController(base.StoreClearingUnitTest):
self.image_repo.result = image
self.controller.upload(request, unit_test_utils.UUID2, 'YYYY', None)
self.assertEqual(image.data, 'YYYY')
self.assertEqual(image.size, None)
self.assertIsNone(image.size)
def test_upload_invalid(self):
request = unit_test_utils.get_fake_request()

@ -1257,7 +1257,7 @@ class TestImagesController(base.IsolatedUnitTest):
self.assertEqual(output.image_id, UUID1)
self.assertEqual(len(output.locations), 0)
self.assertEqual(output.status, 'queued')
self.assertEqual(output.size, None)
self.assertIsNone(output.size)
new_location = {'url': '%s/fake_location' % BASE_URI, 'metadata': {}}
changes = [{'op': 'replace', 'path': ['locations'],
@ -1587,7 +1587,7 @@ class TestImagesController(base.IsolatedUnitTest):
self.assertEqual(output.image_id, UUID1)
self.assertEqual(len(output.locations), 0)
self.assertTrue(output.status == 'queued')
self.assertEqual(output.size, None)
self.assertIsNone(output.size)
new_location = {'url': '%s/fake_location' % BASE_URI, 'metadata': {}}
changes = [{'op': 'add', 'path': ['locations', '-'],
@ -1770,9 +1770,9 @@ class TestImagesController(base.IsolatedUnitTest):
def test_invalid_locations_op_pos(self):
pos = self.controller._get_locations_op_pos(None, 2, True)
self.assertEqual(pos, None)
self.assertIsNone(pos)
pos = self.controller._get_locations_op_pos('1', None, True)
self.assertEqual(pos, None)
self.assertIsNone(pos)
class TestImagesControllerPolicies(base.IsolatedUnitTest):

@ -625,7 +625,7 @@ class TestRegistryV2ClientApi(base.IsolatedUnitTest):
self.config(auth_region=expected['region'])
self.stubs.Set(os, 'getenv', lambda x: None)
self.assertEqual(rapi._CLIENT_CREDS, None)
self.assertIsNone(rapi._CLIENT_CREDS)
rapi.configure_registry_admin_creds()
self.assertEqual(rapi._CLIENT_CREDS, expected)
@ -638,6 +638,6 @@ class TestRegistryV2ClientApi(base.IsolatedUnitTest):
self.config(auth_strategy='test_strategy')
self.config(auth_region=expected['region'])
self.assertEqual(rapi._CLIENT_CREDS, None)
self.assertIsNone(rapi._CLIENT_CREDS)
rapi.configure_registry_admin_creds()
self.assertEqual(rapi._CLIENT_CREDS, expected)

Loading…
Cancel
Save