Replace assertTrue(isinstance()) with assertIsInstance()

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: Ib44771be349f359376e35d7673192bc62805b1c2
Closes-Bug: #1268480
This commit is contained in:
LiuNanke 2015-12-31 00:05:14 +08:00
parent 0c2b84321e
commit f96797a006
4 changed files with 13 additions and 13 deletions

View File

@ -100,7 +100,7 @@ class UsageViewTests(test.BaseAdminViewTests):
self.mox.ReplayAll()
res = self.client.get(reverse('horizon:admin:overview:index'))
self.assertTemplateUsed(res, 'admin/overview/usage.html')
self.assertTrue(isinstance(res.context['usage'], usage.GlobalUsage))
self.assertIsInstance(res.context['usage'], usage.GlobalUsage)
self.assertEqual(nova_stu_enabled,
res.context['simple_tenant_usage_enabled'])
@ -191,7 +191,7 @@ class UsageViewTests(test.BaseAdminViewTests):
csv_url = reverse('horizon:admin:overview:index') + "?format=csv"
res = self.client.get(csv_url)
self.assertTemplateUsed(res, 'admin/overview/usage.csv')
self.assertTrue(isinstance(res.context['usage'], usage.GlobalUsage))
self.assertIsInstance(res.context['usage'], usage.GlobalUsage)
hdr = 'Project Name,VCPUs,RAM (MB),Disk (GB),Usage (Hours)'
self.assertContains(res, '%s\r\n' % hdr)

View File

@ -1566,7 +1566,7 @@ class UsageViewTests(test.BaseAdminViewTests):
res = self.client.get(csv_url)
self.assertTemplateUsed(res, 'project/overview/usage.csv')
self.assertTrue(isinstance(res.context['usage'], usage.ProjectUsage))
self.assertIsInstance(res.context['usage'], usage.ProjectUsage)
hdr = ('Instance Name,VCPUs,RAM (MB),Disk (GB),Usage (Hours),'
'Time since created (Seconds),State')
self.assertContains(res, '%s\r\n' % hdr)

View File

@ -100,7 +100,7 @@ class UsageViewTests(test.TestCase):
res = self.client.get(reverse('horizon:project:overview:index'))
usages = res.context['usage']
self.assertTemplateUsed(res, 'project/overview/usage.html')
self.assertTrue(isinstance(usages, usage.ProjectUsage))
self.assertIsInstance(usages, usage.ProjectUsage)
self.assertEqual(nova_stu_enabled,
res.context['simple_tenant_usage_enabled'])
if nova_stu_enabled:
@ -184,7 +184,7 @@ class UsageViewTests(test.TestCase):
res = self.client.get(reverse('horizon:project:overview:index') +
"?format=csv")
self.assertTemplateUsed(res, 'project/overview/usage.csv')
self.assertTrue(isinstance(res.context['usage'], usage.ProjectUsage))
self.assertIsInstance(res.context['usage'], usage.ProjectUsage)
def test_usage_exception_usage(self):
self._stub_nova_api_calls(stu_exception=self.exceptions.nova)
@ -214,7 +214,7 @@ class UsageViewTests(test.TestCase):
res = self.client.get(reverse('horizon:project:overview:index'))
self.assertTemplateUsed(res, 'project/overview/usage.html')
self.assertTrue(isinstance(res.context['usage'], usage.ProjectUsage))
self.assertIsInstance(res.context['usage'], usage.ProjectUsage)
@test.update_settings(OPENSTACK_NEUTRON_NETWORK={'enable_quotas': True})
def test_usage_with_neutron(self):
@ -323,7 +323,7 @@ class UsageViewTests(test.TestCase):
res = self.client.get(reverse('horizon:project:overview:index'))
usages = res.context['usage']
self.assertTemplateUsed(res, 'project/overview/usage.html')
self.assertTrue(isinstance(usages, usage.ProjectUsage))
self.assertIsInstance(usages, usage.ProjectUsage)
if cinder_enabled:
self.assertEqual(usages.limits['totalVolumesUsed'], 1)
self.assertEqual(usages.limits['maxTotalVolumes'], 10)

View File

@ -943,8 +943,8 @@ class VolumeViewTests(test.TestCase):
self.assertEqual(len(form.fields['instance']._choices),
1)
self.assertEqual(res.status_code, 200)
self.assertTrue(isinstance(form.fields['device'].widget,
widgets.TextInput))
self.assertIsInstance(form.fields['device'].widget,
widgets.TextInput)
self.assertFalse(form.fields['device'].required)
@test.create_stubs({cinder: ('volume_get',), api.nova: ('server_list',)})
@ -969,8 +969,8 @@ class VolumeViewTests(test.TestCase):
args=[volume.id])
res = self.client.get(url)
form = res.context['form']
self.assertTrue(isinstance(form.fields['device'].widget,
widgets.TextInput))
self.assertIsInstance(form.fields['device'].widget,
widgets.TextInput)
self.assertFalse(form.fields['device'].required)
@test.create_stubs({cinder: ('volume_get',), api.nova: ('server_list',)})
@ -989,8 +989,8 @@ class VolumeViewTests(test.TestCase):
res = self.client.get(url)
# Assert the device field is hidden.
form = res.context['form']
self.assertTrue(isinstance(form.fields['device'].widget,
widgets.HiddenInput))
self.assertIsInstance(form.fields['device'].widget,
widgets.HiddenInput)
@test.create_stubs({cinder: ('volume_get',),
api.nova: ('server_list',)})