Change assertTrue(isinstance()) by optimal assert

Some of tests use different method of assertTrue(isinstance(A, B)) or
assertEqual(type(A), B). The correct way is to use assertIsInstance(A,
B) provided by testtools.

Change-Id: Ie98c1aec65281fa1784070ce76e472caca7cfc47
Closes-bug: #1268480
This commit is contained in:
Shuquan Huang 2015-12-30 22:43:49 +08:00 committed by Jordan Pittier
parent 75996a570b
commit 29e9cab8c2
4 changed files with 14 additions and 14 deletions

View File

@ -138,14 +138,14 @@ class TestNodes(base.BaseBaremetalTest):
body = self.client.get_node_boot_device(self.node['uuid'])
self.assertIn('boot_device', body)
self.assertIn('persistent', body)
self.assertTrue(isinstance(body['boot_device'], six.string_types))
self.assertTrue(isinstance(body['persistent'], bool))
self.assertIsInstance(body['boot_device'], six.string_types)
self.assertIsInstance(body['persistent'], bool)
@test.idempotent_id('3622bc6f-3589-4bc2-89f3-50419c66b133')
def test_get_node_supported_boot_devices(self):
body = self.client.get_node_supported_boot_devices(self.node['uuid'])
self.assertIn('supported_boot_devices', body)
self.assertTrue(isinstance(body['supported_boot_devices'], list))
self.assertIsInstance(body['supported_boot_devices'], list)
@test.idempotent_id('f63b6288-1137-4426-8cfe-0d5b7eb87c06')
def test_get_console(self):

View File

@ -58,8 +58,8 @@ class TestDynamicCredentialProvider(base.TestCase):
def test_tempest_client(self):
creds = dynamic_creds.DynamicCredentialProvider(**self.fixed_params)
self.assertTrue(isinstance(creds.identity_admin_client,
json_iden_client.IdentityClient))
self.assertIsInstance(creds.identity_admin_client,
json_iden_client.IdentityClient)
def _get_fake_admin_creds(self):
return credentials.get_credentials(

View File

@ -325,7 +325,7 @@ class TestPreProvisionedCredentials(base.TestCase):
'id': 'fake-id',
'label': 'network-2'}]}):
creds = test_accounts_class.get_creds_by_roles(['role-7'])
self.assertTrue(isinstance(creds, cred_provider.TestResources))
self.assertIsInstance(creds, cred_provider.TestResources)
network = creds.network
self.assertIsNotNone(network)
self.assertIn('name', network)

View File

@ -93,29 +93,29 @@ class TestGlanceHTTPClient(base.TestCase):
self.assertEqual(httplib.HTTPConnection, conn_class)
def test_get_connection_http(self):
self.assertTrue(isinstance(self.client._get_connection(),
httplib.HTTPConnection))
self.assertIsInstance(self.client._get_connection(),
httplib.HTTPConnection)
def test_get_connection_https(self):
endpoint = 'https://fake_url.com'
self.fake_auth.base_url = mock.MagicMock(return_value=endpoint)
self.client = glance_http.HTTPClient(self.fake_auth, {})
self.assertTrue(isinstance(self.client._get_connection(),
glance_http.VerifiedHTTPSConnection))
self.assertIsInstance(self.client._get_connection(),
glance_http.VerifiedHTTPSConnection)
def test_get_connection_ipv4_https(self):
endpoint = 'https://127.0.0.1'
self.fake_auth.base_url = mock.MagicMock(return_value=endpoint)
self.client = glance_http.HTTPClient(self.fake_auth, {})
self.assertTrue(isinstance(self.client._get_connection(),
glance_http.VerifiedHTTPSConnection))
self.assertIsInstance(self.client._get_connection(),
glance_http.VerifiedHTTPSConnection)
def test_get_connection_ipv6_https(self):
endpoint = 'https://[::1]'
self.fake_auth.base_url = mock.MagicMock(return_value=endpoint)
self.client = glance_http.HTTPClient(self.fake_auth, {})
self.assertTrue(isinstance(self.client._get_connection(),
glance_http.VerifiedHTTPSConnection))
self.assertIsInstance(self.client._get_connection(),
glance_http.VerifiedHTTPSConnection)
def test_get_connection_url_not_fount(self):
self.useFixture(mockpatch.PatchObject(self.client, 'connection_class',