Rationalize test asserts
Utilizing assertIn and assertNotIn in a consistent way rather than assertTrue( x <not> in y) and assertFalse(x in y). Change-Id: Ic43d107c40a5a50b852ee476b1167c21e5ad86e8
This commit is contained in:
parent
a37151a492
commit
e8e71dba4d
@ -172,7 +172,7 @@ class DriverTests(object):
|
||||
|
||||
# NOTE(bcwaldon): the tags attribute should not be returned as a part
|
||||
# of a core image entity
|
||||
self.assertFalse('tags' in image)
|
||||
self.assertNotIn('tags', image)
|
||||
|
||||
def test_image_create_duplicate_id(self):
|
||||
self.assertRaises(exception.Duplicate,
|
||||
@ -323,13 +323,13 @@ class DriverTests(object):
|
||||
properties = {p['name']: p for p in image['properties']}
|
||||
|
||||
# New properties are set
|
||||
self.assertTrue('ping' in properties)
|
||||
self.assertIn('ping', properties)
|
||||
self.assertEqual('pong', properties['ping']['value'])
|
||||
self.assertFalse(properties['ping']['deleted'])
|
||||
|
||||
# Original properties still show up, but with deleted=True
|
||||
# TODO(markwash): db api should not return deleted properties
|
||||
self.assertTrue('foo' in properties)
|
||||
self.assertIn('foo', properties)
|
||||
self.assertEqual('bar', properties['foo']['value'])
|
||||
self.assertTrue(properties['foo']['deleted'])
|
||||
|
||||
@ -968,8 +968,8 @@ class DriverTests(object):
|
||||
self.assertFalse(active_image['deleted_at'])
|
||||
|
||||
self.assertEqual(2, len(active_image['locations']))
|
||||
self.assertTrue('id' in active_image['locations'][0])
|
||||
self.assertTrue('id' in active_image['locations'][1])
|
||||
self.assertIn('id', active_image['locations'][0])
|
||||
self.assertIn('id', active_image['locations'][1])
|
||||
active_image['locations'][0].pop('id')
|
||||
active_image['locations'][1].pop('id')
|
||||
self.assertEqual(location_data, active_image['locations'])
|
||||
@ -1644,7 +1644,7 @@ class TaskTests(test_utils.BaseTestCase):
|
||||
self.assertEqual(fixture['updated_at'], task['updated_at'])
|
||||
task_details_keys = ['input', 'message', 'result']
|
||||
for key in task_details_keys:
|
||||
self.assertFalse(key in task)
|
||||
self.assertNotIn(key, task)
|
||||
|
||||
def test_task_create(self):
|
||||
task_id = str(uuid.uuid4())
|
||||
|
@ -110,8 +110,8 @@ class TestBinGlanceCacheManage(functional.FunctionalTest):
|
||||
exitcode, out, err = execute(cmd, raise_error=False)
|
||||
|
||||
self.assertEqual(1, exitcode)
|
||||
self.assertTrue('Cache management middleware not enabled on host'
|
||||
in out.strip())
|
||||
self.assertIn('Cache management middleware not enabled on host',
|
||||
out.strip())
|
||||
|
||||
self.stop_servers()
|
||||
|
||||
@ -131,7 +131,7 @@ class TestBinGlanceCacheManage(functional.FunctionalTest):
|
||||
exitcode, out, err = execute(cmd)
|
||||
|
||||
self.assertEqual(0, exitcode)
|
||||
self.assertTrue('No cached images' in out.strip())
|
||||
self.assertIn('No cached images', out.strip())
|
||||
|
||||
ids = {}
|
||||
|
||||
@ -170,7 +170,7 @@ class TestBinGlanceCacheManage(functional.FunctionalTest):
|
||||
exitcode, out, err = execute(cmd)
|
||||
|
||||
self.assertEqual(0, exitcode)
|
||||
self.assertTrue('No cached images' in out.strip())
|
||||
self.assertIn('No cached images', out.strip())
|
||||
|
||||
# Verify no queued images
|
||||
cmd = "%s --port=%d list-queued" % (exe_cmd, api_port)
|
||||
@ -178,7 +178,7 @@ class TestBinGlanceCacheManage(functional.FunctionalTest):
|
||||
exitcode, out, err = execute(cmd)
|
||||
|
||||
self.assertEqual(0, exitcode)
|
||||
self.assertTrue('No queued images' in out.strip())
|
||||
self.assertIn('No queued images', out.strip())
|
||||
|
||||
ids = {}
|
||||
|
||||
@ -201,7 +201,7 @@ class TestBinGlanceCacheManage(functional.FunctionalTest):
|
||||
exitcode, out, err = execute(cmd)
|
||||
|
||||
self.assertEqual(0, exitcode)
|
||||
self.assertTrue(ids[1] in out, 'Image %s was not queued!' % ids[1])
|
||||
self.assertIn(ids[1], out, 'Image %s was not queued!' % ids[1])
|
||||
|
||||
# Cache images in the queue by running the prefetcher
|
||||
cache_config_filepath = os.path.join(self.test_dir, 'etc',
|
||||
@ -243,7 +243,7 @@ filesystem_store_datadir=%(filesystem_store_datadir)s
|
||||
exitcode, out, err = execute(cmd)
|
||||
|
||||
self.assertEqual(0, exitcode)
|
||||
self.assertTrue('No queued images' in out.strip())
|
||||
self.assertIn('No queued images', out.strip())
|
||||
|
||||
# Verify second image now cached
|
||||
cmd = "%s --port=%d list-cached" % (exe_cmd, api_port)
|
||||
@ -251,7 +251,7 @@ filesystem_store_datadir=%(filesystem_store_datadir)s
|
||||
exitcode, out, err = execute(cmd)
|
||||
|
||||
self.assertEqual(0, exitcode)
|
||||
self.assertTrue(ids[1] in out, 'Image %s was not cached!' % ids[1])
|
||||
self.assertIn(ids[1], out, 'Image %s was not cached!' % ids[1])
|
||||
|
||||
# Queue third image and then delete it from queue
|
||||
cmd = "%s --port=%d --force queue-image %s" % (
|
||||
@ -267,7 +267,7 @@ filesystem_store_datadir=%(filesystem_store_datadir)s
|
||||
exitcode, out, err = execute(cmd)
|
||||
|
||||
self.assertEqual(0, exitcode)
|
||||
self.assertTrue(ids[2] in out, 'Image %s was not queued!' % ids[2])
|
||||
self.assertIn(ids[2], out, 'Image %s was not queued!' % ids[2])
|
||||
|
||||
# Delete the image from the queue
|
||||
cmd = ("%s --port=%d --force "
|
||||
@ -283,7 +283,7 @@ filesystem_store_datadir=%(filesystem_store_datadir)s
|
||||
exitcode, out, err = execute(cmd)
|
||||
|
||||
self.assertEqual(0, exitcode)
|
||||
self.assertTrue('No queued images' in out.strip())
|
||||
self.assertIn('No queued images', out.strip())
|
||||
|
||||
# Queue all images
|
||||
for x in range(4):
|
||||
@ -300,7 +300,7 @@ filesystem_store_datadir=%(filesystem_store_datadir)s
|
||||
exitcode, out, err = execute(cmd)
|
||||
|
||||
self.assertEqual(0, exitcode)
|
||||
self.assertTrue('Found 3 queued images' in out)
|
||||
self.assertIn('Found 3 queued images', out)
|
||||
|
||||
# Delete the image from the queue
|
||||
cmd = ("%s --port=%d --force "
|
||||
@ -316,7 +316,7 @@ filesystem_store_datadir=%(filesystem_store_datadir)s
|
||||
exitcode, out, err = execute(cmd)
|
||||
|
||||
self.assertEqual(0, exitcode)
|
||||
self.assertTrue('No queued images' in out.strip())
|
||||
self.assertIn('No queued images', out.strip())
|
||||
|
||||
# verify two image id when queue-image
|
||||
cmd = ("%s --port=%d --force "
|
||||
@ -325,8 +325,8 @@ filesystem_store_datadir=%(filesystem_store_datadir)s
|
||||
exitcode, out, err = execute(cmd, raise_error=False)
|
||||
|
||||
self.assertEqual(1, exitcode)
|
||||
self.assertTrue('Please specify one and only ID of '
|
||||
'the image you wish to ' in out.strip())
|
||||
self.assertIn('Please specify one and only ID of '
|
||||
'the image you wish to ', out.strip())
|
||||
|
||||
# verify two image id when delete-queued-image
|
||||
cmd = ("%s --port=%d --force delete-queued-image "
|
||||
@ -335,8 +335,8 @@ filesystem_store_datadir=%(filesystem_store_datadir)s
|
||||
exitcode, out, err = execute(cmd, raise_error=False)
|
||||
|
||||
self.assertEqual(1, exitcode)
|
||||
self.assertTrue('Please specify one and only ID of '
|
||||
'the image you wish to ' in out.strip())
|
||||
self.assertIn('Please specify one and only ID of '
|
||||
'the image you wish to ', out.strip())
|
||||
|
||||
# verify two image id when delete-cached-image
|
||||
cmd = ("%s --port=%d --force delete-cached-image "
|
||||
@ -345,7 +345,7 @@ filesystem_store_datadir=%(filesystem_store_datadir)s
|
||||
exitcode, out, err = execute(cmd, raise_error=False)
|
||||
|
||||
self.assertEqual(1, exitcode)
|
||||
self.assertTrue('Please specify one and only ID of '
|
||||
'the image you wish to ' in out.strip())
|
||||
self.assertIn('Please specify one and only ID of '
|
||||
'the image you wish to ', out.strip())
|
||||
|
||||
self.stop_servers()
|
||||
|
@ -437,7 +437,7 @@ class BaseCacheManageMiddlewareTest(object):
|
||||
response, content = http.request(path, 'GET')
|
||||
self.assertEqual(200, response.status)
|
||||
data = jsonutils.loads(content)
|
||||
self.assertTrue('images' in data)
|
||||
self.assertIn('images', data)
|
||||
self.assertEqual(0, len(data['images']))
|
||||
|
||||
def add_image(self, name):
|
||||
@ -471,7 +471,7 @@ class BaseCacheManageMiddlewareTest(object):
|
||||
self.assertEqual(200, response.status)
|
||||
|
||||
data = jsonutils.loads(content)
|
||||
self.assertTrue('cached_images' in data)
|
||||
self.assertIn('cached_images', data)
|
||||
self.assertEqual([], data['cached_images'])
|
||||
|
||||
@skip_if_disabled
|
||||
@ -501,7 +501,7 @@ class BaseCacheManageMiddlewareTest(object):
|
||||
self.assertEqual(200, response.status)
|
||||
|
||||
data = jsonutils.loads(content)
|
||||
self.assertTrue('cached_images' in data)
|
||||
self.assertIn('cached_images', data)
|
||||
|
||||
cached_images = data['cached_images']
|
||||
self.assertEqual(1, len(cached_images))
|
||||
@ -569,7 +569,7 @@ class BaseCacheManageMiddlewareTest(object):
|
||||
self.assertEqual(200, response.status)
|
||||
|
||||
data = jsonutils.loads(content)
|
||||
self.assertTrue('cached_images' in data)
|
||||
self.assertIn('cached_images', data)
|
||||
|
||||
# Verify the last_modified/last_accessed values are valid floats
|
||||
for cached_image in data['cached_images']:
|
||||
@ -601,7 +601,7 @@ class BaseCacheManageMiddlewareTest(object):
|
||||
self.assertEqual(200, response.status)
|
||||
|
||||
data = jsonutils.loads(content)
|
||||
self.assertTrue('cached_images' in data)
|
||||
self.assertIn('cached_images', data)
|
||||
|
||||
cached_images = data['cached_images']
|
||||
self.assertEqual(1, len(cached_images))
|
||||
@ -646,7 +646,7 @@ class BaseCacheManageMiddlewareTest(object):
|
||||
self.assertEqual(200, response.status)
|
||||
|
||||
data = jsonutils.loads(content)
|
||||
self.assertTrue('cached_images' in data)
|
||||
self.assertIn('cached_images', data)
|
||||
|
||||
cached_images = data['cached_images']
|
||||
self.assertEqual(4, len(cached_images))
|
||||
@ -668,11 +668,11 @@ class BaseCacheManageMiddlewareTest(object):
|
||||
self.assertEqual(200, response.status)
|
||||
|
||||
data = jsonutils.loads(content)
|
||||
self.assertTrue('cached_images' in data)
|
||||
self.assertIn('cached_images', data)
|
||||
|
||||
cached_images = data['cached_images']
|
||||
self.assertEqual(3, len(cached_images))
|
||||
self.assertTrue(ids[2] not in [x['image_id'] for x in cached_images])
|
||||
self.assertNotIn(ids[2], [x['image_id'] for x in cached_images])
|
||||
|
||||
# Delete all cached images and verify nothing in cache
|
||||
path = "http://%s:%d/v1/cached_images" % ("127.0.0.1", self.api_port)
|
||||
@ -686,7 +686,7 @@ class BaseCacheManageMiddlewareTest(object):
|
||||
self.assertEqual(200, response.status)
|
||||
|
||||
data = jsonutils.loads(content)
|
||||
self.assertTrue('cached_images' in data)
|
||||
self.assertIn('cached_images', data)
|
||||
|
||||
cached_images = data['cached_images']
|
||||
self.assertEqual(0, len(cached_images))
|
||||
@ -804,12 +804,12 @@ filesystem_store_datadir=%(filesystem_store_datadir)s
|
||||
self.assertEqual(200, response.status)
|
||||
|
||||
data = jsonutils.loads(content)
|
||||
self.assertTrue('cached_images' in data)
|
||||
self.assertIn('cached_images', data)
|
||||
|
||||
cached_images = data['cached_images']
|
||||
self.assertEqual(1, len(cached_images))
|
||||
self.assertTrue(ids[0] in [r['image_id']
|
||||
for r in data['cached_images']])
|
||||
self.assertIn(ids[0], [r['image_id']
|
||||
for r in data['cached_images']])
|
||||
|
||||
self.stop_servers()
|
||||
|
||||
|
@ -51,9 +51,9 @@ class TestGlanceManage(functional.FunctionalTest):
|
||||
cmd = "sqlite3 %s '.schema'" % self.db_filepath
|
||||
exitcode, out, err = execute(cmd, raise_error=True)
|
||||
|
||||
self.assertTrue('CREATE TABLE images' in out)
|
||||
self.assertTrue('CREATE TABLE image_tags' in out)
|
||||
self.assertTrue('CREATE TABLE image_locations' in out)
|
||||
self.assertIn('CREATE TABLE images', out)
|
||||
self.assertIn('CREATE TABLE image_tags', out)
|
||||
self.assertIn('CREATE TABLE image_locations', out)
|
||||
|
||||
# NOTE(bcwaldon): For some reason we need double-quotes around
|
||||
# these two table names
|
||||
|
@ -43,13 +43,13 @@ class TestLogging(functional.FunctionalTest):
|
||||
|
||||
api_log_out = open(self.api_server.log_file, 'r').read()
|
||||
|
||||
self.assertTrue('DEBUG glance' in api_log_out)
|
||||
self.assertIn('DEBUG glance', api_log_out)
|
||||
|
||||
self.assertTrue(os.path.exists(self.registry_server.log_file))
|
||||
|
||||
registry_log_out = open(self.registry_server.log_file, 'r').read()
|
||||
|
||||
self.assertTrue('DEBUG glance' in registry_log_out)
|
||||
self.assertIn('DEBUG glance', registry_log_out)
|
||||
|
||||
self.stop_servers()
|
||||
|
||||
@ -65,13 +65,13 @@ class TestLogging(functional.FunctionalTest):
|
||||
|
||||
api_log_out = open(self.api_server.log_file, 'r').read()
|
||||
|
||||
self.assertFalse('DEBUG glance' in api_log_out)
|
||||
self.assertNotIn('DEBUG glance', api_log_out)
|
||||
|
||||
self.assertTrue(os.path.exists(self.registry_server.log_file))
|
||||
|
||||
registry_log_out = open(self.registry_server.log_file, 'r').read()
|
||||
|
||||
self.assertFalse('DEBUG glance' in registry_log_out)
|
||||
self.assertNotIn('DEBUG glance', registry_log_out)
|
||||
|
||||
self.stop_servers()
|
||||
|
||||
|
@ -35,6 +35,6 @@ class TestSqlite(functional.FunctionalTest):
|
||||
cmd = "sqlite3 tests.sqlite '.schema'"
|
||||
exitcode, out, err = execute(cmd, raise_error=True)
|
||||
|
||||
self.assertFalse('BIGINT' in out)
|
||||
self.assertNotIn('BIGINT', out)
|
||||
|
||||
self.stop_servers()
|
||||
|
@ -50,6 +50,6 @@ class TestWSGIServer(testtools.TestCase):
|
||||
return sock.recv(1024)
|
||||
|
||||
# Should succeed - no timeout
|
||||
self.assertTrue(greetings in get_request())
|
||||
self.assertIn(greetings, get_request())
|
||||
# Should fail - connection timed out so we get nothing from the server
|
||||
self.assertFalse(get_request(delay=0.2))
|
||||
|
@ -268,7 +268,7 @@ class TestCopyToFile(functional.FunctionalTest):
|
||||
|
||||
expected = 'External sources are not supported: \'%s\'' % copy_from
|
||||
msg = 'expected "%s" in "%s"' % (expected, content)
|
||||
self.assertTrue(expected in content, msg)
|
||||
self.assertIn(expected, content, msg)
|
||||
|
||||
self.stop_servers()
|
||||
|
||||
@ -294,6 +294,6 @@ class TestCopyToFile(functional.FunctionalTest):
|
||||
|
||||
expected = 'External sources are not supported: \'swift+config://xxx\''
|
||||
msg = 'expected "%s" in "%s"' % (expected, content)
|
||||
self.assertTrue(expected in content, msg)
|
||||
self.assertIn(expected, content, msg)
|
||||
|
||||
self.stop_servers()
|
||||
|
@ -114,8 +114,8 @@ class TestMiscellaneous(functional.FunctionalTest):
|
||||
'X-Image-Meta-Disk-Format': 'Invalid', }
|
||||
ignored, content = http.request(path, 'POST', headers=headers)
|
||||
|
||||
self.assertTrue('Invalid disk format' in content,
|
||||
"Could not find 'Invalid disk format' "
|
||||
"in output: %s" % content)
|
||||
self.assertIn('Invalid disk format', content,
|
||||
"Could not find 'Invalid disk format' "
|
||||
"in output: %s" % content)
|
||||
|
||||
self.stop_servers()
|
||||
|
@ -70,6 +70,6 @@ class TestMultiprocessing(functional.FunctionalTest):
|
||||
self.assertTrue(len(children) >= len(self._get_children()))
|
||||
for child in self._get_children():
|
||||
# ensure no new children spawned
|
||||
self.assertTrue(child in children, child)
|
||||
self.assertIn(child, children, child)
|
||||
|
||||
self.stop_servers()
|
||||
|
@ -360,7 +360,7 @@ class TestImages(functional.FunctionalTest):
|
||||
self.assertEqual('baz', image['foo'])
|
||||
self.assertEqual('pong', image['ping'])
|
||||
self.assertTrue(image['protected'])
|
||||
self.assertFalse('type' in image, response.text)
|
||||
self.assertNotIn('type', image, response.text)
|
||||
|
||||
# Adding 11 image properties should fail since configured limit is 10
|
||||
path = self._url('/v2/images/%s' % image_id)
|
||||
@ -414,7 +414,7 @@ class TestImages(functional.FunctionalTest):
|
||||
self.assertEqual('baz', image['foo'])
|
||||
self.assertEqual('pong', image['ping'])
|
||||
self.assertTrue(image['protected'])
|
||||
self.assertFalse('type' in image, response.text)
|
||||
self.assertNotIn('type', image, response.text)
|
||||
|
||||
# Try to download data before its uploaded
|
||||
path = self._url('/v2/images/%s/file' % image_id)
|
||||
@ -1570,7 +1570,7 @@ class TestImages(functional.FunctionalTest):
|
||||
# 'random_role' is allowed read 'spl_default_policy'.
|
||||
self.assertEqual(image['spl_default_policy'], 'default_bar')
|
||||
# 'random_role' is forbidden to read 'spl_creator_policy'.
|
||||
self.assertFalse('spl_creator_policy' in image)
|
||||
self.assertNotIn('spl_creator_policy', image)
|
||||
|
||||
# Attempt to replace and remove properties which are permitted
|
||||
path = self._url('/v2/images/%s' % image_id)
|
||||
@ -1590,7 +1590,7 @@ class TestImages(functional.FunctionalTest):
|
||||
|
||||
# 'spl_creator_policy' has delete permission for admin
|
||||
# hence the value has been deleted
|
||||
self.assertFalse('spl_creator_policy' in image)
|
||||
self.assertNotIn('spl_creator_policy', image)
|
||||
|
||||
# Attempt to read a property that is permitted
|
||||
path = self._url('/v2/images/%s' % image_id)
|
||||
@ -2357,7 +2357,7 @@ class TestImages(functional.FunctionalTest):
|
||||
images = jsonutils.loads(response.text)['images']
|
||||
first = jsonutils.loads(response.text)['first']
|
||||
self.assertEqual(0, len(images))
|
||||
self.assertTrue('next' not in jsonutils.loads(response.text))
|
||||
self.assertNotIn('next', jsonutils.loads(response.text))
|
||||
self.assertEqual('/v2/images', first)
|
||||
|
||||
# Create 7 images
|
||||
@ -2386,7 +2386,7 @@ class TestImages(functional.FunctionalTest):
|
||||
body = jsonutils.loads(response.text)
|
||||
self.assertEqual(7, len(body['images']))
|
||||
self.assertEqual('/v2/images', body['first'])
|
||||
self.assertFalse('next' in jsonutils.loads(response.text))
|
||||
self.assertNotIn('next', jsonutils.loads(response.text))
|
||||
|
||||
# Begin pagination after the first image
|
||||
template_url = ('/v2/images?limit=2&sort_dir=asc&sort_key=name'
|
||||
@ -2481,7 +2481,7 @@ class TestImages(functional.FunctionalTest):
|
||||
self.assertEqual(1, len(images))
|
||||
image = images[0]
|
||||
self.assertEqual('private', image['visibility'])
|
||||
self.assertTrue('tenant1' in image['name'])
|
||||
self.assertIn('tenant1', image['name'])
|
||||
|
||||
# 4. Unknown user sees only public images
|
||||
images = list_images('none')
|
||||
@ -2681,7 +2681,7 @@ class TestImageDirectURLVisibility(functional.FunctionalTest):
|
||||
response = requests.get(path, headers=headers)
|
||||
self.assertEqual(200, response.status_code)
|
||||
image = jsonutils.loads(response.text)
|
||||
self.assertFalse('direct_url' in image)
|
||||
self.assertNotIn('direct_url', image)
|
||||
|
||||
# Upload some image data, setting the image location
|
||||
path = self._url('/v2/images/%s/file' % image_id)
|
||||
@ -2695,7 +2695,7 @@ class TestImageDirectURLVisibility(functional.FunctionalTest):
|
||||
response = requests.get(path, headers=headers)
|
||||
self.assertEqual(200, response.status_code)
|
||||
image = jsonutils.loads(response.text)
|
||||
self.assertTrue('direct_url' in image)
|
||||
self.assertIn('direct_url', image)
|
||||
|
||||
# Image direct_url should be visible to non-owner, non-admin user
|
||||
path = self._url('/v2/images/%s' % image_id)
|
||||
@ -2712,7 +2712,7 @@ class TestImageDirectURLVisibility(functional.FunctionalTest):
|
||||
response = requests.get(path, headers=headers)
|
||||
self.assertEqual(200, response.status_code)
|
||||
image = jsonutils.loads(response.text)['images'][0]
|
||||
self.assertTrue('direct_url' in image)
|
||||
self.assertIn('direct_url', image)
|
||||
|
||||
self.stop_servers()
|
||||
|
||||
@ -2739,7 +2739,7 @@ class TestImageDirectURLVisibility(functional.FunctionalTest):
|
||||
response = requests.get(path, headers=headers)
|
||||
self.assertEqual(200, response.status_code)
|
||||
image = jsonutils.loads(response.text)
|
||||
self.assertTrue('locations' in image)
|
||||
self.assertIn('locations', image)
|
||||
self.assertTrue(image["locations"] == [])
|
||||
|
||||
# Upload some image data, setting the image location
|
||||
@ -2754,12 +2754,12 @@ class TestImageDirectURLVisibility(functional.FunctionalTest):
|
||||
response = requests.get(path, headers=headers)
|
||||
self.assertEqual(200, response.status_code)
|
||||
image = jsonutils.loads(response.text)
|
||||
self.assertTrue('locations' in image)
|
||||
self.assertIn('locations', image)
|
||||
loc = image['locations']
|
||||
self.assertTrue(len(loc) > 0)
|
||||
loc = loc[0]
|
||||
self.assertTrue('url' in loc)
|
||||
self.assertTrue('metadata' in loc)
|
||||
self.assertIn('url', loc)
|
||||
self.assertIn('metadata', loc)
|
||||
|
||||
self.stop_servers()
|
||||
|
||||
@ -2800,7 +2800,7 @@ class TestImageDirectURLVisibility(functional.FunctionalTest):
|
||||
response = requests.get(path, headers=headers)
|
||||
self.assertEqual(200, response.status_code)
|
||||
image = jsonutils.loads(response.text)
|
||||
self.assertFalse('direct_url' in image)
|
||||
self.assertNotIn('direct_url', image)
|
||||
|
||||
# Image direct_url should not be visible in a list
|
||||
path = self._url('/v2/images')
|
||||
@ -2808,7 +2808,7 @@ class TestImageDirectURLVisibility(functional.FunctionalTest):
|
||||
response = requests.get(path, headers=headers)
|
||||
self.assertEqual(200, response.status_code)
|
||||
image = jsonutils.loads(response.text)['images'][0]
|
||||
self.assertFalse('direct_url' in image)
|
||||
self.assertNotIn('direct_url', image)
|
||||
|
||||
self.stop_servers()
|
||||
|
||||
@ -2883,7 +2883,7 @@ class TestImageLocationSelectionStrategy(functional.FunctionalTest):
|
||||
response = requests.get(path, headers=headers)
|
||||
self.assertEqual(200, response.status_code)
|
||||
image = jsonutils.loads(response.text)
|
||||
self.assertTrue('locations' in image)
|
||||
self.assertIn('locations', image)
|
||||
self.assertTrue(image["locations"] == [])
|
||||
|
||||
# Update image locations via PATCH
|
||||
@ -2907,9 +2907,9 @@ class TestImageLocationSelectionStrategy(functional.FunctionalTest):
|
||||
response = requests.get(path, headers=headers)
|
||||
self.assertEqual(200, response.status_code)
|
||||
image = jsonutils.loads(response.text)
|
||||
self.assertTrue('locations' in image)
|
||||
self.assertIn('locations', image)
|
||||
self.assertEqual(values, image['locations'])
|
||||
self.assertTrue('direct_url' in image)
|
||||
self.assertIn('direct_url', image)
|
||||
self.assertEqual(values[0]['url'], image['direct_url'])
|
||||
|
||||
self.stop_servers()
|
||||
@ -3002,8 +3002,8 @@ class TestImageMembers(functional.FunctionalTest):
|
||||
image_member = jsonutils.loads(response.text)
|
||||
self.assertEqual(image_fixture[1]['id'], image_member['image_id'])
|
||||
self.assertEqual(TENANT3, image_member['member_id'])
|
||||
self.assertTrue('created_at' in image_member)
|
||||
self.assertTrue('updated_at' in image_member)
|
||||
self.assertIn('created_at', image_member)
|
||||
self.assertIn('updated_at', image_member)
|
||||
self.assertEqual('pending', image_member['status'])
|
||||
|
||||
# Image list should contain 3 images for TENANT3
|
||||
@ -3150,8 +3150,8 @@ class TestImageMembers(functional.FunctionalTest):
|
||||
image_member = jsonutils.loads(response.text)
|
||||
self.assertEqual(image_fixture[3]['id'], image_member['image_id'])
|
||||
self.assertEqual(TENANT4, image_member['member_id'])
|
||||
self.assertTrue('created_at' in image_member)
|
||||
self.assertTrue('updated_at' in image_member)
|
||||
self.assertIn('created_at', image_member)
|
||||
self.assertIn('updated_at', image_member)
|
||||
|
||||
# Add Image member to public image
|
||||
path = self._url('/v2/images/%s/members' % image_fixture[0]['id'])
|
||||
|
@ -80,7 +80,7 @@ class TestTasks(functional.FunctionalTest):
|
||||
task = jsonutils.loads(response.text)
|
||||
task_id = task['id']
|
||||
|
||||
self.assertTrue('Location' in response.headers)
|
||||
self.assertIn('Location', response.headers)
|
||||
self.assertEqual(path + '/' + task_id, response.headers['Location'])
|
||||
|
||||
checked_keys = set([u'created_at',
|
||||
|
@ -395,8 +395,8 @@ class TestApi(base.ApiTest):
|
||||
headers=headers)
|
||||
self.assertEqual(400, response.status)
|
||||
expected = "Content-Type must be application/octet-stream"
|
||||
self.assertTrue(expected in content,
|
||||
"Could not find '%s' in '%s'" % (expected, content))
|
||||
self.assertIn(expected, content,
|
||||
"Could not find '%s' in '%s'" % (expected, content))
|
||||
|
||||
def test_filtered_images(self):
|
||||
"""
|
||||
@ -691,7 +691,7 @@ class TestApi(base.ApiTest):
|
||||
path = "/v1/images?%s" % (params)
|
||||
response, content = self.http.request(path, 'GET')
|
||||
self.assertEqual(400, response.status)
|
||||
self.assertTrue("filter size_min got -1" in content)
|
||||
self.assertIn("filter size_min got -1", content)
|
||||
|
||||
# 19. GET /images with size_min filter
|
||||
# Verify correct images returned with size >= expected
|
||||
@ -699,7 +699,7 @@ class TestApi(base.ApiTest):
|
||||
path = "/v1/images?%s" % (params)
|
||||
response, content = self.http.request(path, 'GET')
|
||||
self.assertEqual(400, response.status)
|
||||
self.assertTrue("filter size_max got -1" in content)
|
||||
self.assertIn("filter size_max got -1", content)
|
||||
|
||||
# 20. GET /images with size_min filter
|
||||
# Verify correct images returned with size >= expected
|
||||
@ -707,7 +707,7 @@ class TestApi(base.ApiTest):
|
||||
path = "/v1/images?%s" % (params)
|
||||
response, content = self.http.request(path, 'GET')
|
||||
self.assertEqual(400, response.status)
|
||||
self.assertTrue("Bad value passed to filter min_ram got -1" in content)
|
||||
self.assertIn("Bad value passed to filter min_ram got -1", content)
|
||||
|
||||
# 21. GET /images with size_min filter
|
||||
# Verify correct images returned with size >= expected
|
||||
@ -715,7 +715,7 @@ class TestApi(base.ApiTest):
|
||||
path = "/v1/images?%s" % (params)
|
||||
response, content = self.http.request(path, 'GET')
|
||||
self.assertEqual(400, response.status)
|
||||
self.assertTrue("protected got imalittleteapot" in content)
|
||||
self.assertIn("protected got imalittleteapot", content)
|
||||
|
||||
# 22. GET /images with size_min filter
|
||||
# Verify correct images returned with size >= expected
|
||||
@ -723,7 +723,7 @@ class TestApi(base.ApiTest):
|
||||
path = "/v1/images?%s" % (params)
|
||||
response, content = self.http.request(path, 'GET')
|
||||
self.assertEqual(400, response.status)
|
||||
self.assertTrue("is_public got imalittleteapot" in content)
|
||||
self.assertIn("is_public got imalittleteapot", content)
|
||||
|
||||
def test_limited_images(self):
|
||||
"""
|
||||
@ -1008,8 +1008,8 @@ class TestApi(base.ApiTest):
|
||||
self.assertEqual(400, response.status)
|
||||
type = format.replace('_format', '')
|
||||
expected = "Invalid %s format 'bad_value' for image" % type
|
||||
self.assertTrue(expected in content,
|
||||
"Could not find '%s' in '%s'" % (expected, content))
|
||||
self.assertIn(expected, content,
|
||||
"Could not find '%s' in '%s'" % (expected, content))
|
||||
|
||||
# make sure the image was not created
|
||||
# Verify no public images
|
||||
@ -1059,8 +1059,8 @@ class TestApi(base.ApiTest):
|
||||
self.assertEqual(400, response.status)
|
||||
type = format.replace('_format', '').capitalize()
|
||||
expected = "%s format is not specified" % type
|
||||
self.assertTrue(expected in content,
|
||||
"Could not find '%s' in '%s'" % (expected, content))
|
||||
self.assertIn(expected, content,
|
||||
"Could not find '%s' in '%s'" % (expected, content))
|
||||
|
||||
def test_put_image_content_bad_container_format(self):
|
||||
self._do_test_put_image_content_missing_format('container_format')
|
||||
@ -1420,7 +1420,7 @@ class TestApiWithFakeAuth(base.ApiTest):
|
||||
|
||||
# 'spl_delete_prop' has delete permission for spl_role
|
||||
# hence the property has been deleted
|
||||
self.assertTrue('spl_delete_prop' not in image['image']['properties'])
|
||||
self.assertNotIn('spl_delete_prop', image['image']['properties'])
|
||||
|
||||
# 'spl_create_prop' has create permission for spl_role
|
||||
# hence the property has been created
|
||||
|
@ -217,7 +217,7 @@ class TestUtils(test_utils.BaseTestCase):
|
||||
}
|
||||
|
||||
mashup_dict = utils.create_mashup_dict(image_meta)
|
||||
self.assertFalse('properties' in mashup_dict)
|
||||
self.assertNotIn('properties', mashup_dict)
|
||||
self.assertEqual(image_meta['properties']['test_key'],
|
||||
mashup_dict['test_key'])
|
||||
|
||||
@ -244,7 +244,7 @@ class TestUtils(test_utils.BaseTestCase):
|
||||
}
|
||||
|
||||
mashup_dict = utils.create_mashup_dict(image_meta)
|
||||
self.assertFalse('properties' in mashup_dict)
|
||||
self.assertNotIn('properties', mashup_dict)
|
||||
self.assertNotEqual(image_meta['properties']['min_ram'],
|
||||
mashup_dict['min_ram'])
|
||||
self.assertEqual(image_meta['min_ram'], mashup_dict['min_ram'])
|
||||
|
@ -154,10 +154,10 @@ class MigrationsMixin(test_migrations.WalkVersionsMixin):
|
||||
|
||||
def _check_003(self, engine, data):
|
||||
images = db_utils.get_table(engine, 'images')
|
||||
self.assertTrue('type' not in images.c,
|
||||
"'type' column found in images table columns! "
|
||||
"images table columns reported by metadata: %s\n"
|
||||
% images.c.keys())
|
||||
self.assertNotIn('type', images.c,
|
||||
"'type' column found in images table columns! "
|
||||
"images table columns reported by metadata: %s\n"
|
||||
% images.c.keys())
|
||||
images_prop = db_utils.get_table(engine, 'image_properties')
|
||||
result = images_prop.select().execute()
|
||||
types = []
|
||||
@ -530,10 +530,10 @@ class MigrationsMixin(test_migrations.WalkVersionsMixin):
|
||||
|
||||
def _check_016(self, engine, data):
|
||||
image_members = db_utils.get_table(engine, 'image_members')
|
||||
self.assertTrue('status' in image_members.c,
|
||||
"'status' column found in image_members table "
|
||||
"columns! image_members table columns: %s"
|
||||
% image_members.c.keys())
|
||||
self.assertIn('status', image_members.c,
|
||||
"'status' column found in image_members table "
|
||||
"columns! image_members table columns: %s"
|
||||
% image_members.c.keys())
|
||||
|
||||
def test_legacy_parse_swift_uri_017(self):
|
||||
metadata_encryption_key = 'a' * 16
|
||||
|
@ -913,9 +913,9 @@ class TestGlanceAPI(base.IsolatedUnitTest):
|
||||
# Test that the Location: header is set to the URI to
|
||||
# edit the newly-created image, as required by APP.
|
||||
# See LP Bug #719825
|
||||
self.assertTrue('location' in res.headers,
|
||||
"'location' not in response headers.\n"
|
||||
"res.headerlist = %r" % res.headerlist)
|
||||
self.assertIn('location', res.headers,
|
||||
"'location' not in response headers.\n"
|
||||
"res.headerlist = %r" % res.headerlist)
|
||||
res_body = jsonutils.loads(res.body)['image']
|
||||
self.assertIn('/images/%s' % res_body['id'], res.headers['location'])
|
||||
self.assertEqual('active', res_body['status'])
|
||||
@ -1495,7 +1495,7 @@ class TestGlanceAPI(base.IsolatedUnitTest):
|
||||
req.method = 'DELETE'
|
||||
res = req.get_response(self.api)
|
||||
self.assertEqual(403, res.status_int)
|
||||
self.assertTrue('Forbidden to delete image' in res.body)
|
||||
self.assertIn('Forbidden to delete image', res.body)
|
||||
|
||||
# check image metadata is still there with active state
|
||||
req = webob.Request.blank("/images/%s" % UUID2)
|
||||
@ -1723,9 +1723,9 @@ class TestGlanceAPI(base.IsolatedUnitTest):
|
||||
|
||||
res = req.get_response(self.api)
|
||||
self.assertEqual(200, res.status_int)
|
||||
self.assertTrue('x-image-meta-property-key1' in res.headers,
|
||||
"Did not find required property in headers. "
|
||||
"Got headers: %r" % res.headers)
|
||||
self.assertIn('x-image-meta-property-key1', res.headers,
|
||||
"Did not find required property in headers. "
|
||||
"Got headers: %r" % res.headers)
|
||||
self.assertEqual("active", res.headers['x-image-meta-status'])
|
||||
|
||||
def test_upload_image_raises_store_disabled(self):
|
||||
@ -1800,11 +1800,11 @@ class TestGlanceAPI(base.IsolatedUnitTest):
|
||||
self.assertEqual(201, res.status_int)
|
||||
res_body = jsonutils.loads(res.body)['image']
|
||||
|
||||
self.assertTrue('id' in res_body)
|
||||
self.assertIn('id', res_body)
|
||||
|
||||
self.image_id = res_body['id']
|
||||
self.assertTrue('/images/%s' %
|
||||
self.image_id in res.headers['location'])
|
||||
self.assertIn('/images/%s' %
|
||||
self.image_id, res.headers['location'])
|
||||
|
||||
# Verify the status is 'queued'
|
||||
self.assertEqual('queued', res_body['status'])
|
||||
@ -2016,10 +2016,10 @@ class TestGlanceAPI(base.IsolatedUnitTest):
|
||||
|
||||
res = req.get_response(self.api)
|
||||
self.assertEqual(200, res.status_int)
|
||||
self.assertTrue('x-image-meta-property-key2' in res.headers,
|
||||
"Did not find required property in headers. "
|
||||
"Got headers: %r" % res.headers)
|
||||
self.assertFalse('x-image-meta-property-key1' in res.headers,
|
||||
self.assertIn('x-image-meta-property-key2', res.headers,
|
||||
"Did not find required property in headers. "
|
||||
"Got headers: %r" % res.headers)
|
||||
self.assertNotIn('x-image-meta-property-key1', res.headers,
|
||||
"Found property in headers that was not expected. "
|
||||
"Got headers: %r" % res.headers)
|
||||
|
||||
@ -2040,12 +2040,12 @@ class TestGlanceAPI(base.IsolatedUnitTest):
|
||||
|
||||
res = req.get_response(self.api)
|
||||
self.assertEqual(200, res.status_int)
|
||||
self.assertTrue('x-image-meta-property-key2' in res.headers,
|
||||
"Did not find required property in headers. "
|
||||
"Got headers: %r" % res.headers)
|
||||
self.assertTrue('x-image-meta-property-key3' in res.headers,
|
||||
"Did not find required property in headers. "
|
||||
"Got headers: %r" % res.headers)
|
||||
self.assertIn('x-image-meta-property-key2', res.headers,
|
||||
"Did not find required property in headers. "
|
||||
"Got headers: %r" % res.headers)
|
||||
self.assertIn('x-image-meta-property-key3', res.headers,
|
||||
"Did not find required property in headers. "
|
||||
"Got headers: %r" % res.headers)
|
||||
|
||||
def test_publicize_image_unauthorized(self):
|
||||
"""Create a non-public image then fail to make public"""
|
||||
@ -2636,9 +2636,9 @@ class TestGlanceAPI(base.IsolatedUnitTest):
|
||||
self.assertEqual(200, res.status_int)
|
||||
|
||||
for key in expected_headers.keys():
|
||||
self.assertTrue(key in res.headers,
|
||||
"required header '%s' missing from "
|
||||
"returned headers" % key)
|
||||
self.assertIn(key, res.headers,
|
||||
"required header '%s' missing from "
|
||||
"returned headers" % key)
|
||||
for key, value in six.iteritems(expected_headers):
|
||||
self.assertEqual(value, res.headers[key])
|
||||
|
||||
|
@ -1777,7 +1777,7 @@ class TestRegistryAPI(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn):
|
||||
req.method = 'GET'
|
||||
res = req.get_response(self.api)
|
||||
self.assertEqual(405, res.status_int)
|
||||
self.assertTrue(('Allow', 'PUT, DELETE') in res.headerlist)
|
||||
self.assertIn(('Allow', 'PUT, DELETE'), res.headerlist)
|
||||
|
||||
def test_get_images_bad_urls(self):
|
||||
"""Check that routes collections are not on (LP bug 1185828)"""
|
||||
|
@ -1479,7 +1479,7 @@ class TestRegistryRPC(base.IsolatedUnitTest):
|
||||
# on any exception status_int is always 200, so have to check _error
|
||||
# dict
|
||||
code, res_dict = self._send_request(command, kwargs, method)
|
||||
self.assertTrue('_error' in res_dict)
|
||||
self.assertIn('_error', res_dict)
|
||||
self.assertEqual(error_cls, res_dict['_error']['cls'])
|
||||
return res_dict
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user