Use more specific asserts in tests

Instead of assertTrue and assertFalse use more specific asserts.
They are compatible with Python 2.7[1] and 3.4[2]

[1]: https://docs.python.org/2.7/library/unittest.html
[2]: https://docs.python.org/3.4/library/unittest.html

Change-Id: I9b07cc324757f35b1e8431b715412bf5d7fa8ecb
This commit is contained in:
Béla Vancsics 2017-02-06 08:40:13 +01:00
parent 95052ba73d
commit ff733ceced
10 changed files with 36 additions and 36 deletions

View File

@ -1378,7 +1378,7 @@ class DataTableTests(test.TestCase):
'<Cell: status, my_table__row__1>',
])
# can_be_selected = False
self.assertTrue(row.get_cells()[0].data == "")
self.assertEqual("", row.get_cells()[0].data)
# can_be_selected = True
self.assertIn('checkbox', row1.get_cells()[0].data)
# status

View File

@ -51,7 +51,7 @@ class FloatingIpViewTests(test.TestCase):
workflow = res.context['workflow']
choices = dict(workflow.steps[0].action.fields['ip_id'].choices)
# Verify that our "associated" floating IP isn't in the choices list.
self.assertTrue(self.floating_ips.first() not in choices)
self.assertNotIn(self.floating_ips.first(), choices)
@test.create_stubs({api.network: ('floating_ip_target_list',
'floating_ip_target_get_by_instance',
@ -74,7 +74,7 @@ class FloatingIpViewTests(test.TestCase):
workflow = res.context['workflow']
choices = dict(workflow.steps[0].action.fields['ip_id'].choices)
# Verify that our "associated" floating IP isn't in the choices list.
self.assertTrue(self.floating_ips.first() not in choices)
self.assertNotIn(self.floating_ips.first(), choices)
@test.create_stubs({api.network: ('floating_ip_target_list',
'tenant_floating_ip_list',)})
@ -95,7 +95,7 @@ class FloatingIpViewTests(test.TestCase):
workflow = res.context['workflow']
choices = dict(workflow.steps[0].action.fields['ip_id'].choices)
# Verify that our "associated" floating IP isn't in the choices list.
self.assertTrue(self.floating_ips.first() not in choices)
self.assertNotIn(self.floating_ips.first(), choices)
@test.create_stubs({api.network: ('floating_ip_associate',
'floating_ip_target_list',
@ -290,8 +290,8 @@ class FloatingIpViewTests(test.TestCase):
allocate_action = self.getAndAssertTableAction(res, 'floating_ips',
'allocate')
self.assertTrue('disabled' in allocate_action.classes,
'The create button should be disabled')
self.assertIn('disabled', allocate_action.classes,
'The create button should be disabled')
self.assertEqual('Allocate IP To Project (Quota exceeded)',
six.text_type(allocate_action.verbose_name))

View File

@ -66,8 +66,8 @@ class ImagesAndSnapshotsTests(test.TestCase):
self.assertEqual(len(row_actions), 5)
row_actions = images_table.get_row_actions(images[1])
self.assertEqual(len(row_actions), 3)
self.assertTrue('delete_image' not in
[a.name for a in row_actions])
self.assertNotIn('delete_image',
[a.name for a in row_actions])
row_actions = images_table.get_row_actions(images[2])
self.assertEqual(len(row_actions), 4)
@ -416,8 +416,8 @@ class SeleniumTests(test.SeleniumTestCase):
copyfrom.send_keys("http://www.test.com/test.iso")
formats = self.ui.Select(driver.find_element_by_id("id_disk_format"))
body = formats.first_selected_option
self.assertTrue("ISO" in body.text,
"ISO should be selected when the extension is *.iso")
self.assertIn("ISO", body.text,
"ISO should be selected when the extension is *.iso")
@unittest.skipIf(os.environ.get('SELENIUM_PHANTOMJS'),
"PhantomJS cannot test file upload widgets.")
@ -451,8 +451,8 @@ class SeleniumTests(test.SeleniumTestCase):
driver.find_element_by_id("id_image_file").send_keys("/tmp/test.iso")
formats = self.ui.Select(driver.find_element_by_id("id_disk_format"))
body = formats.first_selected_option
self.assertTrue("ISO" in body.text,
"ISO should be selected when the extension is *.iso")
self.assertIn("ISO", body.text,
"ISO should be selected when the extension is *.iso")
@test.create_stubs({api.glance: ('image_list_detailed',)})
def test_create_image_from_url(self):
@ -478,8 +478,8 @@ class SeleniumTests(test.SeleniumTestCase):
copyfrom.send_keys("http://www.test.com/test.iso")
formats = self.ui.Select(driver.find_element_by_id("id_disk_format"))
body = formats.first_selected_option
self.assertTrue("ISO" in body.text,
"ISO should be selected when the extension is *.iso")
self.assertIn("ISO", body.text,
"ISO should be selected when the extension is *.iso")
@unittest.skipIf(os.environ.get('SELENIUM_PHANTOMJS'),
"PhantomJS cannot test file upload widgets.")
@ -506,5 +506,5 @@ class SeleniumTests(test.SeleniumTestCase):
driver.find_element_by_id("id_image_file").send_keys("/tmp/test.iso")
formats = self.ui.Select(driver.find_element_by_id("id_disk_format"))
body = formats.first_selected_option
self.assertTrue("ISO" in body.text,
"ISO should be selected when the extension is *.iso")
self.assertIn("ISO", body.text,
"ISO should be selected when the extension is *.iso")

View File

@ -3657,8 +3657,8 @@ class InstanceTests(helpers.ResetImageAPIVersionMixin, helpers.TestCase):
launch_action = self.getAndAssertTableAction(
res, 'instances', 'launch-ng')
self.assertTrue('disabled' in launch_action.classes,
'The launch button should be disabled')
self.assertIn('disabled', launch_action.classes,
'The launch button should be disabled')
self.assertEqual('Launch Instance (Quota exceeded)',
six.text_type(launch_action.verbose_name))

View File

@ -141,7 +141,7 @@ class APIDictWrapperTests(test.TestCase):
msg="Test assumption broken. "
"Find new missing attribute.")
# We're primarily interested in this test NOT raising a TypeError.
self.assertFalse('missing' in resource)
self.assertNotIn('missing', resource)
def test_in_not_there_non_str(self):
resource = APIDict.get_instance()
@ -149,7 +149,7 @@ class APIDictWrapperTests(test.TestCase):
msg="Test assumption broken. "
"Find new missing attribute.")
# We're primarily interested in this test NOT raising a TypeError.
self.assertFalse(0 in resource)
self.assertNotIn(0, resource)
class ApiVersionTests(test.TestCase):

View File

@ -555,7 +555,7 @@ class ComputeApiTests(test.APITestCase):
self.assertEqual(flavor.disk, api_flavor.disk)
self.assertEqual(0, api_flavor.ephemeral)
self.assertEqual(0, api_flavor.swap)
self.assertEqual(True, api_flavor.is_public)
self.assertTrue(api_flavor.is_public)
self.assertEqual(1, api_flavor.rxtx_factor)
def test_flavor_delete(self):

View File

@ -55,7 +55,7 @@ class SwiftRestTestCase(test.TestCase):
self.assertStatusCode(response, 200)
self.assertEqual(u'container one%\u6346',
response.json['items'][0]['name'])
self.assertEqual(False, response.json['has_more'])
self.assertFalse(response.json['has_more'])
nc.swift_get_containers.assert_called_once_with(request)
#
@ -126,8 +126,8 @@ class SwiftRestTestCase(test.TestCase):
self.assertEqual(u'test folder%\u6346/test.txt',
response.json['items'][3]['path'])
self.assertEqual('test.txt', response.json['items'][3]['name'])
self.assertEqual(True, response.json['items'][3]['is_object'])
self.assertEqual(False, response.json['items'][3]['is_subdir'])
self.assertTrue(response.json['items'][3]['is_object'])
self.assertFalse(response.json['items'][3]['is_subdir'])
self.assertEqual(u'test folder%\u6346/test.txt',
response.json['items'][3]['path'])
@ -135,8 +135,8 @@ class SwiftRestTestCase(test.TestCase):
response.json['items'][4]['path'])
self.assertEqual(u'test folder%\u6346',
response.json['items'][4]['name'])
self.assertEqual(False, response.json['items'][4]['is_object'])
self.assertEqual(True, response.json['items'][4]['is_subdir'])
self.assertFalse(response.json['items'][4]['is_object'])
self.assertTrue(response.json['items'][4]['is_subdir'])
nc.swift_get_objects.assert_called_once_with(request,
u'container one%\u6346',
@ -149,8 +149,8 @@ class SwiftRestTestCase(test.TestCase):
response = swift.Objects().get(request, u'container one%\u6346')
self.assertStatusCode(response, 200)
self.assertEqual(1, len(response.json['items']))
self.assertEqual(True, response.json['items'][0]['is_object'])
self.assertEqual(False, response.json['items'][0]['is_subdir'])
self.assertTrue(response.json['items'][0]['is_object'])
self.assertFalse(response.json['items'][0]['is_subdir'])
nc.swift_get_objects.assert_called_once_with(
request,
u'container one%\u6346', prefix=u'test folder%\u6346/'

View File

@ -321,8 +321,8 @@ class TestCase(horizon_helpers.TestCase):
row_actions))
msg_args = (action_name, table_name, row_id)
self.assertTrue(
len(actions) > 0,
self.assertGreater(
len(actions), 0,
"No action named '%s' found in '%s' table for id '%s'" % msg_args)
self.assertEqual(
@ -339,8 +339,8 @@ class TestCase(horizon_helpers.TestCase):
actions = list(moves.filter(lambda x: x.name == action_name,
table_actions))
msg_args = (action_name, table_name)
self.assertTrue(
len(actions) > 0,
self.assertGreater(
len(actions), 0,
"No action named '%s' found in '%s' table" % msg_args)
self.assertEqual(

View File

@ -267,7 +267,7 @@ class TestVolumesActions(helpers.TestCase):
self.assertTrue(self.volumes_page.is_volume_status(self.VOLUME_NAME,
'Available'))
new_size = self.volumes_page.get_size(self.VOLUME_NAME)
self.assertFalse(orig_size >= new_size)
self.assertLess(orig_size, new_size)
@decorators.skip_because(bugs=['1584057'])
def test_volume_upload_to_image(self):

View File

@ -37,7 +37,7 @@ class TemplateRenderTest(test.TestCase):
context,
template.Context(context))
self.assertFalse("&amp;" in out)
self.assertNotIn("&amp;", out)
self.assertIn("ENG Perf R&D", out)
def test_openrc_html_evil_shell_escape(self):
@ -65,8 +65,8 @@ class TemplateRenderTest(test.TestCase):
context,
template.Context(context))
self.assertFalse('o\"' in out)
self.assertFalse('o"' in out)
self.assertNotIn('o\"', out)
self.assertNotIn('o"', out)
self.assertIn('\\"', out)
def test_openrc_set_region(self):