]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Utilizes assertIn and assertNotIn
authorZhongyue Luo <zhongyue.nah@intel.com>
Fri, 30 Aug 2013 05:33:22 +0000 (13:33 +0800)
committerZhongyue Luo <zhongyue.nah@intel.com>
Fri, 30 Aug 2013 14:52:31 +0000 (22:52 +0800)
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

33 files changed:
cinder/tests/api/contrib/test_backups.py
cinder/tests/api/contrib/test_quotas.py
cinder/tests/api/contrib/test_types_extra_specs.py
cinder/tests/api/contrib/test_volume_host_attribute.py
cinder/tests/api/contrib/test_volume_migration_status_attribute.py
cinder/tests/api/contrib/test_volume_tenant_attribute.py
cinder/tests/api/contrib/test_volume_transfer.py
cinder/tests/api/contrib/test_volume_type_encryption.py
cinder/tests/api/middleware/test_faults.py
cinder/tests/api/openstack/test_wsgi.py
cinder/tests/api/test_xmlutil.py
cinder/tests/api/v1/test_limits.py
cinder/tests/api/v1/test_snapshots.py
cinder/tests/api/v1/test_types.py
cinder/tests/api/v1/test_volumes.py
cinder/tests/api/v2/test_limits.py
cinder/tests/api/v2/test_snapshots.py
cinder/tests/api/v2/test_types.py
cinder/tests/api/v2/test_volumes.py
cinder/tests/image/test_glance.py
cinder/tests/integrated/test_volumes.py
cinder/tests/scheduler/test_filter_scheduler.py
cinder/tests/test_conf.py
cinder/tests/test_db_api.py
cinder/tests/test_hds.py
cinder/tests/test_migrations.py
cinder/tests/test_qos_specs.py
cinder/tests/test_volume.py
cinder/tests/test_volume_rpcapi.py
cinder/tests/test_volume_types.py
cinder/tests/test_volume_utils.py
cinder/tests/test_wsgi.py
cinder/tests/test_xenapi_sm.py

index fdc57aabc31e49568cc46c99181c006d946bf0fe..8dcb154ed5f30c6a191547ea9503ec21ab0fea06 100644 (file)
@@ -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)
 
index 549ec122318697db7ba99510d2336fe9262ca905..69deae5b8b69642432d1ba8984c27bfab7d0eb8c 100644 (file)
@@ -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)
index 608d837dd1780ac40bac63748ddafce25f7e3152..f44dcfd7624022fac8601073925107861885d57e 100644 (file)
@@ -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)
index 57b01a0f6cd3f49d47e2b3339ff0802c942d2f54..23b6004cb910d9b997f657324dded2bcde35e5c0 100644 (file)
@@ -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)
index 21b6db1d7fb8b0f0eb809414f041384d5271c845..ee390cc0e804990361f4d6dd08f2425cff682ada 100644 (file)
@@ -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)
index 46c3bc8c616ff89a697d999040875472dfadbefc..f11932859236b0486413444783cddbc3758d01f2 100644 (file)
@@ -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)
index 4cf24780752830a0fe0f3204fe6c11dfc2c538bc..6526777a4c30459e1791707e610ce867f940786f 100644 (file)
@@ -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)
 
index a6b1b8efbbc6279783d1280a03df4c26493d5785..a6c45e5628043822be97661ffc46cee829994ce9 100644 (file)
@@ -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'])
index 7be3b05fc4e869235298493e3f16b17c656e88b3..1e9e1ea2e0322e9127ed029e4f39896e6f40df96 100644 (file)
@@ -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)
 
index 69161189ac17d7debbc55e14ecb88e4a89263042..bce238d45d4cd7088f47ac460968a9a02164a096 100644 (file)
@@ -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({})
index c0bd45af59a226b23b0ca77c85dbfe250ff4d1ce..64c596fed23d0792656d47d9d07e835f1377aa2f 100644 (file)
@@ -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):
index 4440234b73ee22d5360fd3b9a45ddd1fb67ac28e..bae6f9d0069c719bfa1ab88c1ab9cac9f13c8cca 100644 (file)
@@ -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)
 
index 9f56ad8cd0bbfd492817315d70289713cb09e05f..dba2f2a425f8339563fc6c02ce532917faa9717f 100644 (file)
@@ -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']))
 
 
index 9ca05fa6bc5c7cd2a05849d99fca4d25e363ab55..db95a89d5dcc6015761fd7bc6c4a6d230bd3d2d4 100644 (file)
@@ -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):
index cc12869f5a4ff3595080d5751339c619fc401cd1..74c7bd2501f1377464faa513d339e9d21455264a 100644 (file)
@@ -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'))
index 50a281259baaae41c692c9d1e2a5d06d06a40c70..35d657ce34daa94355504983993637db20e6d297 100644 (file)
@@ -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)
 
index 222842f353602f5211c3e238d59c852dd0e97c5e..4bb5092ebea1c99fd914e2f43a96036c12f256de 100644 (file)
@@ -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):
index 1a3849f822490a01d688fa435598c79e3912fdd7..9624993544e6e0732ced40ab73409937a05f8dee 100644 (file)
@@ -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):
index dd4df71b915c82c36d4042dc0abadf7aa7703e30..3505f14579fcf1fc5c2421c0837ea36d66fc9f51 100644 (file)
@@ -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'))
index 71ebfb6da90aab9f47db030469f43ad71b779cfc..0f564fbe8b13daa579f02ccc1f3802ca012ce7c6 100644 (file)
@@ -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',
index ead43ad84b24ef56747278737f0020111553b230..68ceadbc4ae04bec8eda23b38368e1b10d63ffaa 100644 (file)
@@ -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'])
index a821dc13966d4472326680f9fd168f7cfe6a942a..e9f673ce8a4933fa464b617b3ea46c6966cec7ff 100644 (file)
@@ -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.
index 766d1024030944812547ab5804e3ee1bea268c39..cf1906df9f0c87796b77ae7f546886e5ccbb2504 100644 (file)
@@ -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):
index 283029d9169fac9c46add6530e11dc8b6bcda092..49eda1c704198e2b2103cff411a19dabf532928d 100644 (file)
@@ -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):
index 7491d60c089e2a81be27c667461bcfcfcb4792ab..00f8148434eb6607f5e0fde1d262896ec0100f7a 100644 (file)
@@ -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)
 
index 9536d3561f94206b790e4d9d90980881019615d7..3d0f85f985649751ce55656060825384ae4b80fb 100644 (file)
@@ -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."""
index 9143665c923dbdc99ce06fc6680d61ef2985ebee..067fa319367b097694a6f998d16580a1bd265f02 100644 (file)
@@ -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)
index 4c358c5e0cfafec653537d595bd66dac04dd2830..1b5667ebf4f7d97c41d082944bfc34ee1cb3462f 100644 (file)
@@ -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__)
index 16b178c708ea472e0e17dd47058cb86af945809d..dead83eff4477d924d6f98d703c79f26deb96dbe 100644 (file)
@@ -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')
index 743746071bb708b840a1ddd8ca973e40693f9171..b41913d7915f870e026c7e4e0f247105c8fcb34a 100644 (file)
@@ -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'],
index 32584eaaf974fc538892fe16bbe4d5e0cc288d60..bd70a4b635f431ff2f6601ce75795addea5cd94d 100644 (file)
@@ -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):
index e8ac5cc8b1fd822aaa708d4e42214dd3b8d2ad9e..76af3f8d574d552c9728dfea7c4bf9606aed8ba2 100644 (file)
@@ -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):
index ba5cc1adb65ae0d920f6a7be038cfd7da04f8456..79203d6e7ab2a19bda8088086b5b24da0ea5faa9 100644 (file)
@@ -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()