From 1eb3bc803e87119a808e123a2edc7a0341e70480 Mon Sep 17 00:00:00 2001 From: Zhongyue Luo Date: Fri, 30 Aug 2013 13:33:22 +0800 Subject: [PATCH] Utilizes assertIn and assertNotIn Using assertTrue and the 'in' operator to test if an element is in a sequence is too python2.4. Our unit testing framework 'testtools' support assertIn and assertNotIn, included from python 2.7, which were created for these types of tests. Let's use assertIn or assertNotIn for these tests. Change-Id: I8b43f7ff5f306e1ce57296d89679333ce24e4b64 --- cinder/tests/api/contrib/test_backups.py | 2 +- cinder/tests/api/contrib/test_quotas.py | 2 +- .../api/contrib/test_types_extra_specs.py | 2 +- .../api/contrib/test_volume_host_attribute.py | 6 ++--- .../test_volume_migration_status_attribute.py | 12 +++++----- .../contrib/test_volume_tenant_attribute.py | 6 ++--- .../tests/api/contrib/test_volume_transfer.py | 10 ++++----- .../contrib/test_volume_type_encryption.py | 2 +- cinder/tests/api/middleware/test_faults.py | 10 ++++----- cinder/tests/api/openstack/test_wsgi.py | 2 +- cinder/tests/api/test_xmlutil.py | 8 +++---- cinder/tests/api/v1/test_limits.py | 2 +- cinder/tests/api/v1/test_snapshots.py | 18 +++++++-------- cinder/tests/api/v1/test_types.py | 8 +++---- cinder/tests/api/v1/test_volumes.py | 12 +++++----- cinder/tests/api/v2/test_limits.py | 2 +- cinder/tests/api/v2/test_snapshots.py | 18 +++++++-------- cinder/tests/api/v2/test_types.py | 8 +++---- cinder/tests/api/v2/test_volumes.py | 12 +++++----- cinder/tests/image/test_glance.py | 4 ++-- cinder/tests/integrated/test_volumes.py | 2 +- .../tests/scheduler/test_filter_scheduler.py | 2 +- cinder/tests/test_conf.py | 8 +++---- cinder/tests/test_db_api.py | 2 +- cinder/tests/test_hds.py | 4 ++-- cinder/tests/test_migrations.py | 22 +++++++++---------- cinder/tests/test_qos_specs.py | 4 ++-- cinder/tests/test_volume.py | 4 ++-- cinder/tests/test_volume_rpcapi.py | 2 +- cinder/tests/test_volume_types.py | 12 +++++----- cinder/tests/test_volume_utils.py | 3 +-- cinder/tests/test_wsgi.py | 8 +++---- cinder/tests/test_xenapi_sm.py | 2 +- 33 files changed, 110 insertions(+), 111 deletions(-) diff --git a/cinder/tests/api/contrib/test_backups.py b/cinder/tests/api/contrib/test_backups.py index fdc57aabc..8dcb154ed 100644 --- a/cinder/tests/api/contrib/test_backups.py +++ b/cinder/tests/api/contrib/test_backups.py @@ -375,7 +375,7 @@ class BackupsAPITestCase(test.TestCase): LOG.info(res_dict) self.assertEqual(res.status_int, 202) - self.assertTrue('id' in res_dict['backup']) + self.assertIn('id', res_dict['backup']) db.volume_destroy(context.get_admin_context(), volume_id) diff --git a/cinder/tests/api/contrib/test_quotas.py b/cinder/tests/api/contrib/test_quotas.py index 549ec1223..69deae5b8 100644 --- a/cinder/tests/api/contrib/test_quotas.py +++ b/cinder/tests/api/contrib/test_quotas.py @@ -118,5 +118,5 @@ class QuotaSerializerTest(test.TestCase): self.assertEqual(tree.get('id'), quota_set['id']) body = make_body(root=False, tenant_id=None) for node in tree: - self.assertTrue(node.tag in body) + self.assertIn(node.tag, body) self.assertEquals(str(body[node.tag]), node.text) diff --git a/cinder/tests/api/contrib/test_types_extra_specs.py b/cinder/tests/api/contrib/test_types_extra_specs.py index 608d837dd..f44dcfd76 100644 --- a/cinder/tests/api/contrib/test_types_extra_specs.py +++ b/cinder/tests/api/contrib/test_types_extra_specs.py @@ -224,7 +224,7 @@ class VolumeTypeExtraSpecsSerializerTest(test.TestCase): self.assertEqual(len(extra_specs), len(tree)) seen = set(extra_specs.keys()) for child in tree: - self.assertTrue(child.tag in seen) + self.assertIn(child.tag, seen) self.assertEqual(extra_specs[child.tag], child.text) seen.remove(child.tag) self.assertEqual(len(seen), 0) diff --git a/cinder/tests/api/contrib/test_volume_host_attribute.py b/cinder/tests/api/contrib/test_volume_host_attribute.py index 57b01a0f6..23b6004cb 100644 --- a/cinder/tests/api/contrib/test_volume_host_attribute.py +++ b/cinder/tests/api/contrib/test_volume_host_attribute.py @@ -85,7 +85,7 @@ class VolumeHostAttributeTest(test.TestCase): req.environ['cinder.context'] = ctx res = req.get_response(app()) vol = json.loads(res.body)['volume'] - self.assertFalse('os-vol-host-attr:host' in vol) + self.assertNotIn('os-vol-host-attr:host', vol) def test_list_detail_volumes_allowed(self): ctx = context.RequestContext('admin', 'fake', True) @@ -103,7 +103,7 @@ class VolumeHostAttributeTest(test.TestCase): req.environ['cinder.context'] = ctx res = req.get_response(app()) vol = json.loads(res.body)['volumes'] - self.assertFalse('os-vol-host-attr:host' in vol[0]) + self.assertNotIn('os-vol-host-attr:host', vol[0]) def test_list_simple_volumes_no_host(self): ctx = context.RequestContext('admin', 'fake', True) @@ -112,7 +112,7 @@ class VolumeHostAttributeTest(test.TestCase): req.environ['cinder.context'] = ctx res = req.get_response(app()) vol = json.loads(res.body)['volumes'] - self.assertFalse('os-vol-host-attr:host' in vol[0]) + self.assertNotIn('os-vol-host-attr:host', vol[0]) def test_get_volume_xml(self): ctx = context.RequestContext('admin', 'fake', True) diff --git a/cinder/tests/api/contrib/test_volume_migration_status_attribute.py b/cinder/tests/api/contrib/test_volume_migration_status_attribute.py index 21b6db1d7..ee390cc0e 100644 --- a/cinder/tests/api/contrib/test_volume_migration_status_attribute.py +++ b/cinder/tests/api/contrib/test_volume_migration_status_attribute.py @@ -81,8 +81,8 @@ class VolumeMigStatusAttributeTest(test.TestCase): req.environ['cinder.context'] = ctx res = req.get_response(app()) vol = json.loads(res.body)['volume'] - self.assertFalse('os-vol-mig-status-attr:migstat' in vol) - self.assertFalse('os-vol-mig-status-attr:name_id' in vol) + self.assertNotIn('os-vol-mig-status-attr:migstat', vol) + self.assertNotIn('os-vol-mig-status-attr:name_id', vol) def test_list_detail_volumes_allowed(self): ctx = context.RequestContext('admin', 'fake', True) @@ -101,8 +101,8 @@ class VolumeMigStatusAttributeTest(test.TestCase): req.environ['cinder.context'] = ctx res = req.get_response(app()) vol = json.loads(res.body)['volumes'] - self.assertFalse('os-vol-mig-status-attr:migstat' in vol[0]) - self.assertFalse('os-vol-mig-status-attr:name_id' in vol[0]) + self.assertNotIn('os-vol-mig-status-attr:migstat', vol[0]) + self.assertNotIn('os-vol-mig-status-attr:name_id', vol[0]) def test_list_simple_volumes_no_migration_status(self): ctx = context.RequestContext('admin', 'fake', True) @@ -111,8 +111,8 @@ class VolumeMigStatusAttributeTest(test.TestCase): req.environ['cinder.context'] = ctx res = req.get_response(app()) vol = json.loads(res.body)['volumes'] - self.assertFalse('os-vol-mig-status-attr:migstat' in vol[0]) - self.assertFalse('os-vol-mig-status-attr:name_id' in vol[0]) + self.assertNotIn('os-vol-mig-status-attr:migstat', vol[0]) + self.assertNotIn('os-vol-mig-status-attr:name_id', vol[0]) def test_get_volume_xml(self): ctx = context.RequestContext('admin', 'fake', True) diff --git a/cinder/tests/api/contrib/test_volume_tenant_attribute.py b/cinder/tests/api/contrib/test_volume_tenant_attribute.py index 46c3bc8c6..f11932859 100644 --- a/cinder/tests/api/contrib/test_volume_tenant_attribute.py +++ b/cinder/tests/api/contrib/test_volume_tenant_attribute.py @@ -85,7 +85,7 @@ class VolumeTenantAttributeTest(test.TestCase): req.environ['cinder.context'] = ctx res = req.get_response(app()) vol = json.loads(res.body)['volume'] - self.assertFalse('os-vol-tenant-attr:tenant_id' in vol) + self.assertNotIn('os-vol-tenant-attr:tenant_id', vol) def test_list_detail_volumes_allowed(self): ctx = context.RequestContext('admin', 'fake', True) @@ -103,7 +103,7 @@ class VolumeTenantAttributeTest(test.TestCase): req.environ['cinder.context'] = ctx res = req.get_response(app()) vol = json.loads(res.body)['volumes'] - self.assertFalse('os-vol-tenant-attr:tenant_id' in vol[0]) + self.assertNotIn('os-vol-tenant-attr:tenant_id', vol[0]) def test_list_simple_volumes_no_tenant_id(self): ctx = context.RequestContext('admin', 'fake', True) @@ -112,7 +112,7 @@ class VolumeTenantAttributeTest(test.TestCase): req.environ['cinder.context'] = ctx res = req.get_response(app()) vol = json.loads(res.body)['volumes'] - self.assertFalse('os-vol-tenant-attr:tenant_id' in vol[0]) + self.assertNotIn('os-vol-tenant-attr:tenant_id', vol[0]) def test_get_volume_xml(self): ctx = context.RequestContext('admin', 'fake', True) diff --git a/cinder/tests/api/contrib/test_volume_transfer.py b/cinder/tests/api/contrib/test_volume_transfer.py index 4cf247807..6526777a4 100644 --- a/cinder/tests/api/contrib/test_volume_transfer.py +++ b/cinder/tests/api/contrib/test_volume_transfer.py @@ -251,11 +251,11 @@ class VolumeTransferAPITestCase(test.TestCase): LOG.info(res_dict) self.assertEqual(res.status_int, 202) - self.assertTrue('id' in res_dict['transfer']) - self.assertTrue('auth_key' in res_dict['transfer']) - self.assertTrue('created_at' in res_dict['transfer']) - self.assertTrue('name' in res_dict['transfer']) - self.assertTrue('volume_id' in res_dict['transfer']) + self.assertIn('id', res_dict['transfer']) + self.assertIn('auth_key', res_dict['transfer']) + self.assertIn('created_at', res_dict['transfer']) + self.assertIn('name', res_dict['transfer']) + self.assertIn('volume_id', res_dict['transfer']) db.volume_destroy(context.get_admin_context(), volume_id) diff --git a/cinder/tests/api/contrib/test_volume_type_encryption.py b/cinder/tests/api/contrib/test_volume_type_encryption.py index a6b1b8efb..a6c45e562 100644 --- a/cinder/tests/api/contrib/test_volume_type_encryption.py +++ b/cinder/tests/api/contrib/test_volume_type_encryption.py @@ -215,7 +215,7 @@ class VolumeTypeEncryptionTest(test.TestCase): self.assertEquals(len(test_notifier.NOTIFICATIONS), 1) # check response - self.assertTrue('encryption' in res_dict) + self.assertIn('encryption', res_dict) self.assertEqual(cipher, res_dict['encryption']['cipher']) self.assertEqual(control_location, res_dict['encryption']['control_location']) diff --git a/cinder/tests/api/middleware/test_faults.py b/cinder/tests/api/middleware/test_faults.py index 7be3b05fc..1e9e1ea2e 100644 --- a/cinder/tests/api/middleware/test_faults.py +++ b/cinder/tests/api/middleware/test_faults.py @@ -94,7 +94,7 @@ class TestFaults(test.TestCase): resp = req.get_response(raiser) self.assertEqual(resp.content_type, "application/xml") self.assertEqual(resp.status_int, 404) - self.assertTrue('whut?' in resp.body) + self.assertIn('whut?', resp.body) def test_raise_403(self): """Ensure the ability to raise :class:`Fault` in WSGI-ified methods.""" @@ -106,8 +106,8 @@ class TestFaults(test.TestCase): resp = req.get_response(raiser) self.assertEqual(resp.content_type, "application/xml") self.assertEqual(resp.status_int, 403) - self.assertTrue('resizeNotAllowed' not in resp.body) - self.assertTrue('forbidden' in resp.body) + self.assertNotIn('resizeNotAllowed', resp.body) + self.assertIn('forbidden', resp.body) def test_raise_localized_explanation(self): params = ('blah', ) @@ -127,7 +127,7 @@ class TestFaults(test.TestCase): resp = req.get_response(raiser) self.assertEqual(resp.content_type, "application/xml") self.assertEqual(resp.status_int, 404) - self.assertTrue(("Mensaje traducido") in resp.body) + self.assertIn(("Mensaje traducido"), resp.body) self.stubs.UnsetAll() def test_fault_has_status_int(self): @@ -143,7 +143,7 @@ class TestFaults(test.TestCase): fault = wsgi.Fault(webob.exc.HTTPBadRequest(explanation='scram')) response = request.get_response(fault) - self.assertTrue(common.XML_NS_V1 in response.body) + self.assertIn(common.XML_NS_V1, response.body) self.assertEqual(response.content_type, "application/xml") self.assertEqual(response.status_int, 400) diff --git a/cinder/tests/api/openstack/test_wsgi.py b/cinder/tests/api/openstack/test_wsgi.py index 69161189a..bce238d45 100644 --- a/cinder/tests/api/openstack/test_wsgi.py +++ b/cinder/tests/api/openstack/test_wsgi.py @@ -796,7 +796,7 @@ class ResponseObjectTest(test.TestCase): robj = wsgi.ResponseObject({}) robj['Header'] = 'foo' del robj['hEADER'] - self.assertFalse('header' in robj.headers) + self.assertNotIn('header', robj.headers) def test_header_isolation(self): robj = wsgi.ResponseObject({}) diff --git a/cinder/tests/api/test_xmlutil.py b/cinder/tests/api/test_xmlutil.py index c0bd45af5..64c596fed 100644 --- a/cinder/tests/api/test_xmlutil.py +++ b/cinder/tests/api/test_xmlutil.py @@ -196,7 +196,7 @@ class TemplateElementTest(test.TestCase): # Verify that the child was added self.assertEqual(len(elem), 1) self.assertEqual(elem[0], child) - self.assertEqual('child' in elem, True) + self.assertIn('child', elem) self.assertEqual(elem['child'], child) # Ensure that multiple children of the same name are rejected @@ -222,7 +222,7 @@ class TemplateElementTest(test.TestCase): self.assertEqual(len(elem), 3) for idx in range(len(elem)): self.assertEqual(children[idx], elem[idx]) - self.assertEqual(children[idx].tag in elem, True) + self.assertIn(children[idx].tag, elem) self.assertEqual(elem[children[idx].tag], children[idx]) # Ensure that multiple children of the same name are rejected @@ -260,7 +260,7 @@ class TemplateElementTest(test.TestCase): children.insert(1, child) for idx in range(len(elem)): self.assertEqual(children[idx], elem[idx]) - self.assertEqual(children[idx].tag in elem, True) + self.assertIn(children[idx].tag, elem) self.assertEqual(elem[children[idx].tag], children[idx]) # Ensure that multiple children of the same name are rejected @@ -298,7 +298,7 @@ class TemplateElementTest(test.TestCase): self.assertEqual(len(elem), 2) self.assertEqual(elem[0], children[0]) self.assertEqual(elem[1], children[2]) - self.assertEqual('child2' in elem, False) + self.assertNotIn('child2', elem) # Ensure the child cannot be retrieved by name def get_key(elem, key): diff --git a/cinder/tests/api/v1/test_limits.py b/cinder/tests/api/v1/test_limits.py index 4440234b7..bae6f9d00 100644 --- a/cinder/tests/api/v1/test_limits.py +++ b/cinder/tests/api/v1/test_limits.py @@ -270,7 +270,7 @@ class LimitMiddlewareTest(BaseLimitTestSuite): response = request.get_response(self.app) self.assertEqual(response.status_int, 413) - self.assertTrue('Retry-After' in response.headers) + self.assertIn('Retry-After', response.headers) retry_after = int(response.headers['Retry-After']) self.assertAlmostEqual(retry_after, 60, 1) diff --git a/cinder/tests/api/v1/test_snapshots.py b/cinder/tests/api/v1/test_snapshots.py index 9f56ad8cd..dba2f2a42 100644 --- a/cinder/tests/api/v1/test_snapshots.py +++ b/cinder/tests/api/v1/test_snapshots.py @@ -94,7 +94,7 @@ class SnapshotApiTest(test.TestCase): req = fakes.HTTPRequest.blank('/v1/snapshots') resp_dict = self.controller.create(req, body) - self.assertTrue('snapshot' in resp_dict) + self.assertIn('snapshot', resp_dict) self.assertEqual(resp_dict['snapshot']['display_name'], snapshot['display_name']) self.assertEqual(resp_dict['snapshot']['display_description'], @@ -113,7 +113,7 @@ class SnapshotApiTest(test.TestCase): req = fakes.HTTPRequest.blank('/v1/snapshots') resp_dict = self.controller.create(req, body) - self.assertTrue('snapshot' in resp_dict) + self.assertIn('snapshot', resp_dict) self.assertEqual(resp_dict['snapshot']['display_name'], snapshot['display_name']) self.assertEqual(resp_dict['snapshot']['display_description'], @@ -195,7 +195,7 @@ class SnapshotApiTest(test.TestCase): req = fakes.HTTPRequest.blank('/v1/snapshots/%s' % UUID) resp_dict = self.controller.show(req, UUID) - self.assertTrue('snapshot' in resp_dict) + self.assertIn('snapshot', resp_dict) self.assertEqual(resp_dict['snapshot']['id'], UUID) def test_snapshot_show_invalid_id(self): @@ -213,7 +213,7 @@ class SnapshotApiTest(test.TestCase): req = fakes.HTTPRequest.blank('/v1/snapshots/detail') resp_dict = self.controller.detail(req) - self.assertTrue('snapshots' in resp_dict) + self.assertIn('snapshots', resp_dict) resp_snapshots = resp_dict['snapshots'] self.assertEqual(len(resp_snapshots), 1) @@ -311,7 +311,7 @@ class SnapshotApiTest(test.TestCase): use_admin_context=True) res = self.controller.index(req) - self.assertTrue('snapshots' in res) + self.assertIn('snapshots', res) self.assertEqual(1, len(res['snapshots'])) def test_list_snapshots_with_limit_and_offset(self): @@ -331,7 +331,7 @@ class SnapshotApiTest(test.TestCase): use_admin_context=is_admin) res = self.controller.index(req) - self.assertTrue('snapshots' in res) + self.assertIn('snapshots', res) self.assertEqual(1, len(res['snapshots'])) self.assertEqual(2, res['snapshots'][0]['id']) @@ -344,19 +344,19 @@ class SnapshotApiTest(test.TestCase): req = fakes.HTTPRequest.blank('/v1/fake/snapshots?all_tenants=1', use_admin_context=True) res = self.controller.index(req) - self.assertTrue('snapshots' in res) + self.assertIn('snapshots', res) self.assertEqual(3, len(res['snapshots'])) def test_all_tenants_non_admin_gets_all_tenants(self): req = fakes.HTTPRequest.blank('/v1/fake/snapshots?all_tenants=1') res = self.controller.index(req) - self.assertTrue('snapshots' in res) + self.assertIn('snapshots', res) self.assertEqual(1, len(res['snapshots'])) def test_non_admin_get_by_project(self): req = fakes.HTTPRequest.blank('/v1/fake/snapshots') res = self.controller.index(req) - self.assertTrue('snapshots' in res) + self.assertIn('snapshots', res) self.assertEqual(1, len(res['snapshots'])) diff --git a/cinder/tests/api/v1/test_types.py b/cinder/tests/api/v1/test_types.py index 9ca05fa6b..db95a89d5 100644 --- a/cinder/tests/api/v1/test_types.py +++ b/cinder/tests/api/v1/test_types.py @@ -119,7 +119,7 @@ class VolumeTypesApiTest(test.TestCase): request = fakes.HTTPRequest.blank("/v1") output = view_builder.show(request, raw_volume_type) - self.assertTrue('volume_type' in output) + self.assertIn('volume_type', output) expected_volume_type = dict(name='new_type', extra_specs={}, id=42) @@ -142,7 +142,7 @@ class VolumeTypesApiTest(test.TestCase): request = fakes.HTTPRequest.blank("/v1") output = view_builder.index(request, raw_volume_types) - self.assertTrue('volume_types' in output) + self.assertIn('volume_types', output) for i in range(0, 10): expected_volume_type = dict(name='new_type', extra_specs={}, @@ -161,7 +161,7 @@ class VolumeTypesSerializerTest(test.TestCase): self.assertEqual('extra_specs', extra_specs.tag) seen = set(vtype['extra_specs'].keys()) for child in extra_specs: - self.assertTrue(child.tag in seen) + self.assertIn(child.tag, seen) self.assertEqual(vtype['extra_specs'][child.tag], child.text) seen.remove(child.tag) self.assertEqual(len(seen), 0) @@ -179,7 +179,7 @@ class VolumeTypesSerializerTest(test.TestCase): self.assertEqual(len(vtypes), len(tree)) for child in tree: name = child.get('name') - self.assertTrue(name in vtypes) + self.assertIn(name, vtypes) self._verify_volume_type(vtypes[name], child) def test_voltype_serializer(self): diff --git a/cinder/tests/api/v1/test_volumes.py b/cinder/tests/api/v1/test_volumes.py index cc12869f5..74c7bd250 100644 --- a/cinder/tests/api/v1/test_volumes.py +++ b/cinder/tests/api/v1/test_volumes.py @@ -598,26 +598,26 @@ class VolumeApiTest(test.TestCase): use_admin_context=True) res = self.controller.index(req) - self.assertTrue('volumes' in res) + self.assertIn('volumes', res) self.assertEqual(1, len(res['volumes'])) def test_admin_list_volumes_all_tenants(self): req = fakes.HTTPRequest.blank('/v1/fake/volumes?all_tenants=1', use_admin_context=True) res = self.controller.index(req) - self.assertTrue('volumes' in res) + self.assertIn('volumes', res) self.assertEqual(3, len(res['volumes'])) def test_all_tenants_non_admin_gets_all_tenants(self): req = fakes.HTTPRequest.blank('/v1/fake/volumes?all_tenants=1') res = self.controller.index(req) - self.assertTrue('volumes' in res) + self.assertIn('volumes', res) self.assertEqual(1, len(res['volumes'])) def test_non_admin_get_by_project(self): req = fakes.HTTPRequest.blank('/v1/fake/volumes') res = self.controller.index(req) - self.assertTrue('volumes' in res) + self.assertIn('volumes', res) self.assertEqual(1, len(res['volumes'])) @@ -635,7 +635,7 @@ class VolumeSerializerTest(test.TestCase): self.assertEqual(str(vol[attr]), tree.get(attr)) for child in tree: - self.assertTrue(child.tag in (NS + 'attachments', NS + 'metadata')) + self.assertIn(child.tag, (NS + 'attachments', NS + 'metadata')) if child.tag == 'attachments': self.assertEqual(1, len(child)) self.assertEqual('attachment', child[0].tag) @@ -643,7 +643,7 @@ class VolumeSerializerTest(test.TestCase): elif child.tag == 'metadata': not_seen = set(vol['metadata'].keys()) for gr_child in child: - self.assertTrue(gr_child.get("key") in not_seen) + self.assertIn(gr_child.get("key"), not_seen) self.assertEqual(str(vol['metadata'][gr_child.get("key")]), gr_child.text) not_seen.remove(gr_child.get('key')) diff --git a/cinder/tests/api/v2/test_limits.py b/cinder/tests/api/v2/test_limits.py index 50a281259..35d657ce3 100644 --- a/cinder/tests/api/v2/test_limits.py +++ b/cinder/tests/api/v2/test_limits.py @@ -270,7 +270,7 @@ class LimitMiddlewareTest(BaseLimitTestSuite): response = request.get_response(self.app) self.assertEqual(response.status_int, 413) - self.assertTrue('Retry-After' in response.headers) + self.assertIn('Retry-After', response.headers) retry_after = int(response.headers['Retry-After']) self.assertAlmostEqual(retry_after, 60, 1) diff --git a/cinder/tests/api/v2/test_snapshots.py b/cinder/tests/api/v2/test_snapshots.py index 222842f35..4bb5092eb 100644 --- a/cinder/tests/api/v2/test_snapshots.py +++ b/cinder/tests/api/v2/test_snapshots.py @@ -101,7 +101,7 @@ class SnapshotApiTest(test.TestCase): req = fakes.HTTPRequest.blank('/v2/snapshots') resp_dict = self.controller.create(req, body) - self.assertTrue('snapshot' in resp_dict) + self.assertIn('snapshot', resp_dict) self.assertEqual(resp_dict['snapshot']['name'], snapshot_name) self.assertEqual(resp_dict['snapshot']['description'], @@ -123,7 +123,7 @@ class SnapshotApiTest(test.TestCase): req = fakes.HTTPRequest.blank('/v2/snapshots') resp_dict = self.controller.create(req, body) - self.assertTrue('snapshot' in resp_dict) + self.assertIn('snapshot', resp_dict) self.assertEqual(resp_dict['snapshot']['name'], snapshot_name) self.assertEqual(resp_dict['snapshot']['description'], @@ -209,7 +209,7 @@ class SnapshotApiTest(test.TestCase): req = fakes.HTTPRequest.blank('/v2/snapshots/%s' % UUID) resp_dict = self.controller.show(req, UUID) - self.assertTrue('snapshot' in resp_dict) + self.assertIn('snapshot', resp_dict) self.assertEqual(resp_dict['snapshot']['id'], UUID) def test_snapshot_show_invalid_id(self): @@ -224,7 +224,7 @@ class SnapshotApiTest(test.TestCase): req = fakes.HTTPRequest.blank('/v2/snapshots/detail') resp_dict = self.controller.detail(req) - self.assertTrue('snapshots' in resp_dict) + self.assertIn('snapshots', resp_dict) resp_snapshots = resp_dict['snapshots'] self.assertEqual(len(resp_snapshots), 1) @@ -322,7 +322,7 @@ class SnapshotApiTest(test.TestCase): use_admin_context=True) res = self.controller.index(req) - self.assertTrue('snapshots' in res) + self.assertIn('snapshots', res) self.assertEqual(1, len(res['snapshots'])) def test_list_snapshots_with_limit_and_offset(self): @@ -342,7 +342,7 @@ class SnapshotApiTest(test.TestCase): use_admin_context=is_admin) res = self.controller.index(req) - self.assertTrue('snapshots' in res) + self.assertIn('snapshots', res) self.assertEqual(1, len(res['snapshots'])) self.assertEqual(2, res['snapshots'][0]['id']) @@ -355,19 +355,19 @@ class SnapshotApiTest(test.TestCase): req = fakes.HTTPRequest.blank('/v2/fake/snapshots?all_tenants=1', use_admin_context=True) res = self.controller.index(req) - self.assertTrue('snapshots' in res) + self.assertIn('snapshots', res) self.assertEqual(3, len(res['snapshots'])) def test_all_tenants_non_admin_gets_all_tenants(self): req = fakes.HTTPRequest.blank('/v2/fake/snapshots?all_tenants=1') res = self.controller.index(req) - self.assertTrue('snapshots' in res) + self.assertIn('snapshots', res) self.assertEqual(1, len(res['snapshots'])) def test_non_admin_get_by_project(self): req = fakes.HTTPRequest.blank('/v2/fake/snapshots') res = self.controller.index(req) - self.assertTrue('snapshots' in res) + self.assertIn('snapshots', res) self.assertEqual(1, len(res['snapshots'])) def _create_snapshot_bad_body(self, body): diff --git a/cinder/tests/api/v2/test_types.py b/cinder/tests/api/v2/test_types.py index 1a3849f82..962499354 100644 --- a/cinder/tests/api/v2/test_types.py +++ b/cinder/tests/api/v2/test_types.py @@ -129,7 +129,7 @@ class VolumeTypesApiTest(test.TestCase): request = fakes.HTTPRequest.blank("/v2") output = view_builder.show(request, raw_volume_type) - self.assertTrue('volume_type' in output) + self.assertIn('volume_type', output) expected_volume_type = dict( name='new_type', extra_specs={}, @@ -158,7 +158,7 @@ class VolumeTypesApiTest(test.TestCase): request = fakes.HTTPRequest.blank("/v2") output = view_builder.index(request, raw_volume_types) - self.assertTrue('volume_types' in output) + self.assertIn('volume_types', output) for i in range(0, 10): expected_volume_type = dict( name='new_type', @@ -179,7 +179,7 @@ class VolumeTypesSerializerTest(test.TestCase): self.assertEqual('extra_specs', extra_specs.tag) seen = set(vtype['extra_specs'].keys()) for child in extra_specs: - self.assertTrue(child.tag in seen) + self.assertIn(child.tag, seen) self.assertEqual(vtype['extra_specs'][child.tag], child.text) seen.remove(child.tag) self.assertEqual(len(seen), 0) @@ -197,7 +197,7 @@ class VolumeTypesSerializerTest(test.TestCase): self.assertEqual(len(vtypes), len(tree)) for child in tree: name = child.get('name') - self.assertTrue(name in vtypes) + self.assertIn(name, vtypes) self._verify_volume_type(vtypes[name], child) def test_voltype_serializer(self): diff --git a/cinder/tests/api/v2/test_volumes.py b/cinder/tests/api/v2/test_volumes.py index dd4df71b9..3505f1457 100644 --- a/cinder/tests/api/v2/test_volumes.py +++ b/cinder/tests/api/v2/test_volumes.py @@ -773,26 +773,26 @@ class VolumeApiTest(test.TestCase): use_admin_context=True) res = self.controller.index(req) - self.assertTrue('volumes' in res) + self.assertIn('volumes', res) self.assertEqual(1, len(res['volumes'])) def test_admin_list_volumes_all_tenants(self): req = fakes.HTTPRequest.blank('/v2/fake/volumes?all_tenants=1', use_admin_context=True) res = self.controller.index(req) - self.assertTrue('volumes' in res) + self.assertIn('volumes', res) self.assertEqual(3, len(res['volumes'])) def test_all_tenants_non_admin_gets_all_tenants(self): req = fakes.HTTPRequest.blank('/v2/fake/volumes?all_tenants=1') res = self.controller.index(req) - self.assertTrue('volumes' in res) + self.assertIn('volumes', res) self.assertEqual(1, len(res['volumes'])) def test_non_admin_get_by_project(self): req = fakes.HTTPRequest.blank('/v2/fake/volumes') res = self.controller.index(req) - self.assertTrue('volumes' in res) + self.assertIn('volumes', res) self.assertEqual(1, len(res['volumes'])) def _create_volume_bad_request(self, body): @@ -828,7 +828,7 @@ class VolumeSerializerTest(test.TestCase): self.assertEqual(str(vol[attr]), tree.get(attr)) for child in tree: - self.assertTrue(child.tag in (NS + 'attachments', NS + 'metadata')) + self.assertIn(child.tag, (NS + 'attachments', NS + 'metadata')) if child.tag == 'attachments': self.assertEqual(1, len(child)) self.assertEqual('attachment', child[0].tag) @@ -836,7 +836,7 @@ class VolumeSerializerTest(test.TestCase): elif child.tag == 'metadata': not_seen = set(vol['metadata'].keys()) for gr_child in child: - self.assertTrue(gr_child.get("key") in not_seen) + self.assertIn(gr_child.get("key"), not_seen) self.assertEqual(str(vol['metadata'][gr_child.get("key")]), gr_child.text) not_seen.remove(gr_child.get('key')) diff --git a/cinder/tests/image/test_glance.py b/cinder/tests/image/test_glance.py index 71ebfb6da..0f564fbe8 100644 --- a/cinder/tests/image/test_glance.py +++ b/cinder/tests/image/test_glance.py @@ -632,7 +632,7 @@ class TestGlanceImageServiceClient(test.TestCase): def __init__(inst, version, *args, **kwargs): self.assertEqual('1', version) self.assertEqual('http://fake_host:9292', args[0]) - self.assertFalse('token' in kwargs) + self.assertNotIn('token', kwargs) self.assertEqual(60, kwargs['timeout']) self.stubs.Set(glance.glanceclient, 'Client', MyGlanceStubClient) @@ -649,7 +649,7 @@ class TestGlanceImageServiceClient(test.TestCase): self.assertEqual("1", version) self.assertEqual("http://fake_host:9292", args[0]) self.assertEqual(True, kwargs['token']) - self.assertFalse('timeout' in kwargs) + self.assertNotIn('timeout', kwargs) self.stubs.Set(glance.glanceclient, 'Client', MyGlanceStubClient) client = glance._create_glance_client(self.context, 'fake_host:9292', diff --git a/cinder/tests/integrated/test_volumes.py b/cinder/tests/integrated/test_volumes.py index ead43ad84..68ceadbc4 100644 --- a/cinder/tests/integrated/test_volumes.py +++ b/cinder/tests/integrated/test_volumes.py @@ -98,7 +98,7 @@ class VolumesTest(integrated_helpers._IntegratedTestBase): # It should also be in the all-volume list volumes = self.api.get_volumes() volume_names = [volume['id'] for volume in volumes] - self.assertTrue(created_volume_id in volume_names) + self.assertIn(created_volume_id, volume_names) # Wait (briefly) for creation. Delay is due to the 'message queue' found_volume = self._poll_while(created_volume_id, ['creating']) diff --git a/cinder/tests/scheduler/test_filter_scheduler.py b/cinder/tests/scheduler/test_filter_scheduler.py index a821dc139..e9f673ce8 100644 --- a/cinder/tests/scheduler/test_filter_scheduler.py +++ b/cinder/tests/scheduler/test_filter_scheduler.py @@ -122,7 +122,7 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase): filter_properties=filter_properties) # should not have retry info in the populated filter properties: - self.assertFalse("retry" in filter_properties) + self.assertNotIn("retry", filter_properties) def test_retry_attempt_one(self): # Test retry logic on initial scheduling attempt. diff --git a/cinder/tests/test_conf.py b/cinder/tests/test_conf.py index 766d10240..cf1906df9 100644 --- a/cinder/tests/test_conf.py +++ b/cinder/tests/test_conf.py @@ -35,9 +35,9 @@ class ConfigTestCase(test.TestCase): super(ConfigTestCase, self).setUp() def test_declare(self): - self.assert_('answer' not in CONF) + self.assertNotIn('answer', CONF) CONF.import_opt('answer', 'cinder.tests.declare_conf') - self.assert_('answer' in CONF) + self.assertIn('answer', CONF) self.assertEqual(CONF.answer, 42) # Make sure we don't overwrite anything @@ -47,9 +47,9 @@ class ConfigTestCase(test.TestCase): self.assertEqual(CONF.answer, 256) def test_runtime_and_unknown_conf(self): - self.assert_('runtime_answer' not in CONF) + self.assertNotIn('runtime_answer', CONF) import cinder.tests.runtime_conf - self.assert_('runtime_answer' in CONF) + self.assertIn('runtime_answer', CONF) self.assertEqual(CONF.runtime_answer, 54) def test_long_vs_short_conf(self): diff --git a/cinder/tests/test_db_api.py b/cinder/tests/test_db_api.py index 283029d91..49eda1c70 100644 --- a/cinder/tests/test_db_api.py +++ b/cinder/tests/test_db_api.py @@ -722,7 +722,7 @@ class DBAPIQuotaTestCase(BaseTest): res_names = ['gigabytes', 'volumes'] for uuid in reservations: reservation = db.reservation_get(self.ctxt, uuid) - self.assertTrue(reservation.resource in res_names) + self.assertIn(reservation.resource, res_names) res_names.remove(reservation.resource) def test_quota_destroy_all_by_project(self): diff --git a/cinder/tests/test_hds.py b/cinder/tests/test_hds.py index 7491d60c0..00f814843 100644 --- a/cinder/tests/test_hds.py +++ b/cinder/tests/test_hds.py @@ -276,8 +276,8 @@ class HUSiSCSIDriverTest(test.TestCase): vol = self.test_create_volume() self.mox.StubOutWithMock(self.driver, '_update_vol_location') conn = self.driver.initialize_connection(vol, connector) - self.assertTrue('hitachi' in conn['data']['target_iqn']) - self.assertTrue('3260' in conn['data']['target_portal']) + self.assertIn('hitachi', conn['data']['target_iqn']) + self.assertIn('3260', conn['data']['target_portal']) vol['provider_location'] = conn['data']['provider_location'] return (vol, connector) diff --git a/cinder/tests/test_migrations.py b/cinder/tests/test_migrations.py index 9536d3561..3d0f85f98 100644 --- a/cinder/tests/test_migrations.py +++ b/cinder/tests/test_migrations.py @@ -514,7 +514,7 @@ class TestMigrations(test.TestCase): for metadata in self.metadatas_downgraded_from(6): snapshots = sqlalchemy.Table('snapshots', metadata, autoload=True) - self.assertTrue('provider_location' not in snapshots.c) + self.assertNotIn('provider_location', snapshots.c) def test_upgrade_007_adds_fk(self): for metadata in self.metadatas_upgraded_to(7): @@ -716,7 +716,7 @@ class TestMigrations(test.TestCase): volumes = sqlalchemy.Table('volumes', metadata, autoload=True) - self.assertTrue('bootable' not in volumes.c) + self.assertNotIn('bootable', volumes.c) # Make sure we put all the columns back for column in volumes_v10.c: @@ -746,7 +746,7 @@ class TestMigrations(test.TestCase): volumes = sqlalchemy.Table('volumes', metadata, autoload=True) - self.assertTrue('attached_host' not in volumes.c) + self.assertNotIn('attached_host', volumes.c) def test_migration_013(self): """Test that adding provider_geometry column works correctly.""" @@ -772,7 +772,7 @@ class TestMigrations(test.TestCase): volumes = sqlalchemy.Table('volumes', metadata, autoload=True) - self.assertTrue('provider_geometry' not in volumes.c) + self.assertNotIn('provider_geometry', volumes.c) def test_migration_014(self): """Test that adding _name_id column works correctly.""" @@ -798,7 +798,7 @@ class TestMigrations(test.TestCase): volumes = sqlalchemy.Table('volumes', metadata, autoload=True) - self.assertTrue('_name_id' not in volumes.c) + self.assertNotIn('_name_id', volumes.c) def test_migration_015(self): """Test removing migrations table works correctly.""" @@ -858,15 +858,15 @@ class TestMigrations(test.TestCase): # encryption key UUID volumes = sqlalchemy.Table('volumes', metadata, autoload=True) - self.assertTrue('encryption_key_id' in volumes.c) + self.assertIn('encryption_key_id', volumes.c) self.assertTrue(isinstance(volumes.c.encryption_key_id.type, sqlalchemy.types.VARCHAR)) snapshots = sqlalchemy.Table('snapshots', metadata, autoload=True) - self.assertTrue('encryption_key_id' in snapshots.c) + self.assertIn('encryption_key_id', snapshots.c) self.assertTrue(isinstance(snapshots.c.encryption_key_id.type, sqlalchemy.types.VARCHAR)) - self.assertTrue('volume_type_id' in snapshots.c) + self.assertIn('volume_type_id', snapshots.c) self.assertTrue(isinstance(snapshots.c.volume_type_id.type, sqlalchemy.types.VARCHAR)) @@ -889,10 +889,10 @@ class TestMigrations(test.TestCase): metadata.bind = engine volumes = sqlalchemy.Table('volumes', metadata, autoload=True) - self.assertTrue('encryption_key_id' not in volumes.c) + self.assertNotIn('encryption_key_id', volumes.c) snapshots = sqlalchemy.Table('snapshots', metadata, autoload=True) - self.assertTrue('encryption_key_id' not in snapshots.c) + self.assertNotIn('encryption_key_id', snapshots.c) self.assertFalse(engine.dialect.has_table(engine.connect(), 'encryption')) @@ -959,7 +959,7 @@ class TestMigrations(test.TestCase): volumes = sqlalchemy.Table('volumes', metadata, autoload=True) - self.assertTrue('migration_status' not in volumes.c) + self.assertNotIn('migration_status', volumes.c) def test_migration_020(self): """Test adding volume_admin_metadata table works correctly.""" diff --git a/cinder/tests/test_qos_specs.py b/cinder/tests/test_qos_specs.py index 9143665c9..067fa3193 100644 --- a/cinder/tests/test_qos_specs.py +++ b/cinder/tests/test_qos_specs.py @@ -179,8 +179,8 @@ class QoSSpecsTestCase(test.TestCase): type_ref['id']) res = qos_specs.get_associations(self.ctxt, specs_id) self.assertEquals(len(res[specs_id].keys()), 1) - self.assertTrue('TypeName' in res[specs_id].keys()) - self.assertTrue(type_ref['id'] in res[specs_id].values()) + self.assertIn('TypeName', res[specs_id].keys()) + self.assertIn(type_ref['id'], res[specs_id].values()) self.stubs.Set(db, 'qos_specs_associate', fake_db_associate) diff --git a/cinder/tests/test_volume.py b/cinder/tests/test_volume.py index 4c358c5e0..1b5667ebf 100644 --- a/cinder/tests/test_volume.py +++ b/cinder/tests/test_volume.py @@ -807,7 +807,7 @@ class VolumeTestCase(BaseVolumeTestCase): admin_context = context.get_admin_context() iscsi_target = db.volume_get_iscsi_target_num(admin_context, volume_id) - self.assert_(iscsi_target not in targets) + self.assertNotIn(iscsi_target, targets) targets.append(iscsi_target) total_slots = CONF.iscsi_num_targets @@ -1418,7 +1418,7 @@ class VolumeTestCase(BaseVolumeTestCase): def fake_reschedule_or_error(self, context, *args, **kwargs): self.assertFalse(context.is_admin) - self.assertFalse('admin' in context.roles) + self.assertNotIn('admin', context.roles) #compare context passed in with the context we saved self.assertDictMatch(self.saved_ctxt.__dict__, context.__dict__) diff --git a/cinder/tests/test_volume_rpcapi.py b/cinder/tests/test_volume_rpcapi.py index 16b178c70..dead83eff 100644 --- a/cinder/tests/test_volume_rpcapi.py +++ b/cinder/tests/test_volume_rpcapi.py @@ -56,7 +56,7 @@ class VolumeRpcAPITestCase(test.TestCase): self.fake_snapshot = jsonutils.to_primitive(snapshot) def test_serialized_volume_has_id(self): - self.assertTrue('id' in self.fake_volume) + self.assertIn('id', self.fake_volume) def _test_volume_api(self, method, rpc_method, **kwargs): ctxt = context.RequestContext('fake_user', 'fake_project') diff --git a/cinder/tests/test_volume_types.py b/cinder/tests/test_volume_types.py index 743746071..b41913d79 100644 --- a/cinder/tests/test_volume_types.py +++ b/cinder/tests/test_volume_types.py @@ -146,7 +146,7 @@ class VolumeTypeTestCase(test.TestCase): search_opts={'extra_specs': {"key1": "val1"}}) LOG.info("vol_types: %s" % vol_types) self.assertEqual(len(vol_types), 1) - self.assertTrue("type1" in vol_types.keys()) + self.assertIn("type1", vol_types.keys()) self.assertEqual(vol_types['type1']['extra_specs'], {"key1": "val1", "key2": "val2"}) @@ -155,15 +155,15 @@ class VolumeTypeTestCase(test.TestCase): search_opts={'extra_specs': {"key2": "val2"}}) LOG.info("vol_types: %s" % vol_types) self.assertEqual(len(vol_types), 2) - self.assertTrue("type1" in vol_types.keys()) - self.assertTrue("type2" in vol_types.keys()) + self.assertIn("type1", vol_types.keys()) + self.assertIn("type2", vol_types.keys()) vol_types = volume_types.get_all_types( self.ctxt, search_opts={'extra_specs': {"key3": "val3"}}) LOG.info("vol_types: %s" % vol_types) self.assertEqual(len(vol_types), 1) - self.assertTrue("type2" in vol_types.keys()) + self.assertIn("type2", vol_types.keys()) def test_volume_type_search_by_extra_spec_multiple(self): """Ensure volume types get by extra spec returns correct type.""" @@ -182,8 +182,8 @@ class VolumeTypeTestCase(test.TestCase): "key3": "val3"}}) LOG.info("vol_types: %s" % vol_types) self.assertEqual(len(vol_types), 2) - self.assertTrue("type1" in vol_types.keys()) - self.assertTrue("type3" in vol_types.keys()) + self.assertIn("type1", vol_types.keys()) + self.assertIn("type3", vol_types.keys()) self.assertEqual(vol_types['type1']['extra_specs'], {"key1": "val1", "key2": "val2", "key3": "val3"}) self.assertEqual(vol_types['type3']['extra_specs'], diff --git a/cinder/tests/test_volume_utils.py b/cinder/tests/test_volume_utils.py index 32584eaaf..bd70a4b63 100644 --- a/cinder/tests/test_volume_utils.py +++ b/cinder/tests/test_volume_utils.py @@ -93,8 +93,7 @@ class UsageInfoTestCase(test.TestCase): for attr in ('display_name', 'created_at', 'launched_at', 'status', 'audit_period_beginning', 'audit_period_ending'): - self.assertTrue(attr in payload, - msg="Key %s not in payload" % attr) + self.assertIn(attr, payload) db.volume_destroy(context.get_admin_context(), volume['id']) def test_get_host_from_queue_simple(self): diff --git a/cinder/tests/test_wsgi.py b/cinder/tests/test_wsgi.py index e8ac5cc8b..76af3f8d5 100644 --- a/cinder/tests/test_wsgi.py +++ b/cinder/tests/test_wsgi.py @@ -200,11 +200,11 @@ class ExceptionTest(test.TestCase): api = self._wsgi_app(fail) resp = webob.Request.blank('/').get_response(api) - self.assertTrue('{"computeFault' in resp.body, resp.body) + self.assertIn('{"computeFault', resp.body) expected = ('ExceptionWithSafety: some explanation' if expose else 'The server has either erred or is incapable ' 'of performing the requested operation.') - self.assertTrue(expected in resp.body, resp.body) + self.assertIn(expected, resp.body) self.assertEqual(resp.status_int, 500, resp.body) def test_safe_exceptions_are_described_in_faults(self): @@ -220,12 +220,12 @@ class ExceptionTest(test.TestCase): api = self._wsgi_app(fail) resp = webob.Request.blank('/').get_response(api) - self.assertTrue(msg in resp.body, resp.body) + self.assertIn(msg, resp.body) self.assertEqual(resp.status_int, exception_type.code, resp.body) if hasattr(exception_type, 'headers'): for (key, value) in exception_type.headers.iteritems(): - self.assertTrue(key in resp.headers) + self.assertIn(key, resp.headers) self.assertEquals(resp.headers[key], value) def test_quota_error_mapping(self): diff --git a/cinder/tests/test_xenapi_sm.py b/cinder/tests/test_xenapi_sm.py index ba5cc1adb..79203d6e7 100644 --- a/cinder/tests/test_xenapi_sm.py +++ b/cinder/tests/test_xenapi_sm.py @@ -470,7 +470,7 @@ class DriverTestCase(test.TestCase): ] for metric in required_metrics: - self.assertTrue(metric in stats) + self.assertIn(metric, stats) def test_get_volume_stats_reports_unknown_cap(self): drv = get_configured_driver() -- 2.45.2