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: Iea7306f8ab6e3253fd68007829b7e8b51afb790a
This commit is contained in:
parent
beb14094d4
commit
09adb96836
@ -52,12 +52,12 @@ class TestExposedAPIMethodsCheckPolicy(test_base.TestCase):
|
||||
|
||||
for func in self.exposed_methods:
|
||||
src = inspect.getsource(func)
|
||||
self.assertTrue('policy.authorize' in src,
|
||||
'policy.authorize call not found in exposed '
|
||||
'method %s' % func)
|
||||
self.assertTrue('context.to_policy_values' in src,
|
||||
'context.to_policy_values call not found in '
|
||||
'exposed method %s' % func)
|
||||
self.assertIn('policy.authorize', src,
|
||||
'policy.authorize call not found in exposed '
|
||||
'method %s' % func)
|
||||
self.assertIn('context.to_policy_values', src,
|
||||
'context.to_policy_values call not found in '
|
||||
'exposed method %s' % func)
|
||||
|
||||
def test_chasis_api_policy(self):
|
||||
self._test('ironic.api.controllers.v1.chassis')
|
||||
|
@ -147,7 +147,7 @@ class APINotifyTestCase(tests_base.TestCase):
|
||||
self.assertEqual('11:22:33:77:88:99', payload.address)
|
||||
self.assertEqual({'a': 25}, payload.local_link_connection)
|
||||
self.assertEqual({'as': 34}, payload.extra)
|
||||
self.assertEqual(False, payload.pxe_enabled)
|
||||
self.assertIs(False, payload.pxe_enabled)
|
||||
|
||||
def test_portgroup_notification(self):
|
||||
node_uuid = uuidutils.generate_uuid()
|
||||
|
@ -855,7 +855,7 @@ class TestPatch(test_api_base.BaseApiTest):
|
||||
headers=self.headers)
|
||||
self.assertEqual('application/json', response.content_type)
|
||||
self.assertEqual(http_client.OK, response.status_code)
|
||||
self.assertEqual(False, response.json['standalone_ports_supported'])
|
||||
self.assertIs(False, response.json['standalone_ports_supported'])
|
||||
|
||||
def test_update_portgroup_standalone_ports_supported_bad_api_version(
|
||||
self, mock_upd):
|
||||
|
@ -32,7 +32,7 @@ class StatesTest(base.TestCase):
|
||||
# Assumption: A state variable name is all UPPERCASE and contents
|
||||
# are a string.
|
||||
if key.upper() == key and isinstance(value, six.string_types):
|
||||
self.assertTrue(
|
||||
(len(value) <= 15),
|
||||
self.assertLessEqual(
|
||||
len(value), 15,
|
||||
"Value for state: {} is greater than 15 characters".format(
|
||||
key))
|
||||
|
@ -139,7 +139,7 @@ class DracPeriodicTaskTestCase(db_base.DbTestCase):
|
||||
self.assertEqual(['42'],
|
||||
self.node.driver_internal_info['raid_config_job_ids'])
|
||||
self.assertEqual({}, self.node.raid_config)
|
||||
self.assertEqual(False, self.node.maintenance)
|
||||
self.assertIs(False, self.node.maintenance)
|
||||
|
||||
@mock.patch.object(drac_common, 'get_drac_client', spec_set=True,
|
||||
autospec=True)
|
||||
|
@ -390,7 +390,7 @@ class IloManagementTestCase(db_base.DbTestCase):
|
||||
'fw_location_for_another_filepath', 'chassis'),
|
||||
]
|
||||
clean_step_mock.assert_has_calls(calls)
|
||||
self.assertTrue(clean_step_mock.call_count == 5)
|
||||
self.assertEqual(5, clean_step_mock.call_count)
|
||||
|
||||
def test_update_firmware_throws_if_invalid_update_mode_provided(self):
|
||||
with task_manager.acquire(self.context, self.node.uuid,
|
||||
|
@ -240,7 +240,7 @@ class OneViewPeriodicTasks(db_base.DbTestCase):
|
||||
self.assertTrue(self.node.maintenance)
|
||||
self.assertEqual(common.NODE_IN_USE_BY_ONEVIEW,
|
||||
self.node.maintenance_reason)
|
||||
self.assertFalse('oneview_error' in self.node.driver_internal_info)
|
||||
self.assertNotIn('oneview_error', self.node.driver_internal_info)
|
||||
|
||||
def test_node_stay_clean_failed_when_no_oneview_error(
|
||||
self, mock_is_node_in_use_by_oneview, mock_node_get
|
||||
@ -256,7 +256,7 @@ class OneViewPeriodicTasks(db_base.DbTestCase):
|
||||
self.assertFalse(self.node.maintenance)
|
||||
self.assertNotEqual(common.NODE_IN_USE_BY_ONEVIEW,
|
||||
self.node.maintenance_reason)
|
||||
self.assertFalse('oneview_error' in self.node.driver_internal_info)
|
||||
self.assertNotIn('oneview_error', self.node.driver_internal_info)
|
||||
|
||||
|
||||
@mock.patch.object(common, 'get_oneview_client', spec_set=True, autospec=True)
|
||||
|
@ -110,12 +110,12 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase):
|
||||
'/rest/server-profiles/1234556789'
|
||||
task.node.driver_info = driver_info
|
||||
|
||||
self.assertTrue(
|
||||
'applied_server_profile_uri' in task.node.driver_info
|
||||
self.assertIn(
|
||||
'applied_server_profile_uri', task.node.driver_info
|
||||
)
|
||||
deploy_utils.tear_down(ov_client, task)
|
||||
self.assertFalse(
|
||||
'applied_server_profile_uri' in task.node.driver_info
|
||||
self.assertNotIn(
|
||||
'applied_server_profile_uri', task.node.driver_info
|
||||
)
|
||||
self.assertTrue(
|
||||
ov_client.delete_server_profile.called
|
||||
@ -403,8 +403,8 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase):
|
||||
oneview_client, task.node
|
||||
)
|
||||
self.assertTrue(oneview_client.delete_server_profile.called)
|
||||
self.assertTrue(
|
||||
'applied_server_profile_uri' not in task.node.driver_info
|
||||
self.assertNotIn(
|
||||
'applied_server_profile_uri', task.node.driver_info
|
||||
)
|
||||
|
||||
@mock.patch.object(objects.Node, 'save')
|
||||
@ -439,6 +439,6 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase):
|
||||
task.node
|
||||
)
|
||||
self.assertTrue(ov_client.delete_server_profile.called)
|
||||
self.assertTrue(
|
||||
'applied_server_profile_uri' in task.node.driver_info
|
||||
self.assertIn(
|
||||
'applied_server_profile_uri', task.node.driver_info
|
||||
)
|
||||
|
@ -1625,9 +1625,9 @@ class AgentMethodsTestCase(db_base.DbTestCase):
|
||||
utils.agent_add_clean_params(task)
|
||||
self.assertEqual(2, task.node.driver_internal_info[
|
||||
'agent_erase_devices_iterations'])
|
||||
self.assertEqual(False, task.node.driver_internal_info[
|
||||
self.assertIs(False, task.node.driver_internal_info[
|
||||
'agent_erase_devices_zeroize'])
|
||||
self.assertEqual(True, task.node.driver_internal_info[
|
||||
self.assertIs(True, task.node.driver_internal_info[
|
||||
'agent_continue_if_ata_erase_failed'])
|
||||
|
||||
@mock.patch.object(pxe.PXEBoot, 'prepare_ramdisk', autospec=True)
|
||||
@ -1649,8 +1649,8 @@ class AgentMethodsTestCase(db_base.DbTestCase):
|
||||
power_mock.assert_called_once_with(task, states.REBOOT)
|
||||
self.assertEqual(1, task.node.driver_internal_info[
|
||||
'agent_erase_devices_iterations'])
|
||||
self.assertEqual(True, task.node.driver_internal_info[
|
||||
'agent_erase_devices_zeroize'])
|
||||
self.assertIs(True, task.node.driver_internal_info[
|
||||
'agent_erase_devices_zeroize'])
|
||||
if manage_boot:
|
||||
prepare_ramdisk_mock.assert_called_once_with(
|
||||
mock.ANY, mock.ANY, {'a': 'b'})
|
||||
|
@ -2057,7 +2057,7 @@ class IPMIToolDriverTestCase(db_base.DbTestCase):
|
||||
self.info['force_boot_device'] = True
|
||||
self.driver.management.set_boot_device(task, boot_devices.PXE)
|
||||
task.node.refresh()
|
||||
self.assertEqual(
|
||||
self.assertIs(
|
||||
False,
|
||||
task.node.driver_internal_info['is_next_boot_persistent']
|
||||
)
|
||||
|
@ -169,7 +169,7 @@ class UtilsTestCase(db_base.DbTestCase):
|
||||
ret = driver_utils.force_persistent_boot(task, 'pxe', False)
|
||||
self.assertIsNone(ret)
|
||||
task.node.refresh()
|
||||
self.assertEqual(
|
||||
self.assertIs(
|
||||
False,
|
||||
task.node.driver_internal_info['is_next_boot_persistent'])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user