Merge "Fix 'has_calls' method calls in unit tests" into stable/queens

This commit is contained in:
Zuul 2019-10-17 10:33:30 +00:00 committed by Gerrit Code Review
commit a08a2a1f09
5 changed files with 25 additions and 17 deletions

View File

@ -239,9 +239,9 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
self.compute.update_available_resource(self.context)
get_db_nodes.assert_called_once_with(self.context, use_slave=True,
startup=False)
update_mock.has_calls(
[mock.call(self.context, node) for node in avail_nodes_l]
)
self.assertEqual(len(avail_nodes_l), update_mock.call_count)
update_mock.assert_has_calls(
[mock.call(self.context, node) for node in avail_nodes_l])
# First node in set should have been removed from DB
for db_node in db_nodes:
@ -483,7 +483,8 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
sec_groups = 'fake-sec-groups'
final_result = 'meow'
expected_sleep_times = [1, 2, 4, 8, 16, 30, 30, 30]
expected_sleep_times = [mock.call(t) for t in
(1, 2, 4, 8, 16, 30, 30)]
with mock.patch.object(
self.compute.network_api, 'allocate_for_instance',
@ -494,7 +495,8 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
sec_groups,
is_vpn)
mock_sleep.has_calls(expected_sleep_times)
self.assertEqual(7, mock_sleep.call_count)
mock_sleep.assert_has_calls(expected_sleep_times)
self.assertEqual(final_result, res)
# Ensure save is not called in while allocating networks, the instance
# is saved after the allocation.

View File

@ -66,7 +66,8 @@ class HostOpsTestCase(test_base.HyperVBaseTestCase):
expected = [mock.call(fkey)
for fkey in os_win_const.PROCESSOR_FEATURE.keys()]
self._hostops._hostutils.is_cpu_feature_present.has_calls(expected)
self._hostops._hostutils.is_cpu_feature_present.assert_has_calls(
expected, any_order=True)
expected_response = self._get_mock_cpu_info()
self.assertEqual(expected_response, response)

View File

@ -102,12 +102,15 @@ class SnapshotOpsTestCase(test_base.HyperVBaseTestCase):
else:
mock_save_glance_image.assert_called_once_with(
self.context, mock.sentinel.IMAGE_ID, dest_vhd_path)
self._snapshotops._pathutils.copyfile.has_calls(expected)
self.assertEqual(len(expected),
self._snapshotops._pathutils.copyfile.call_count)
self._snapshotops._pathutils.copyfile.assert_has_calls(expected)
self.assertEqual(2, mock_update.call_count)
expected_update = [
mock.call(task_state=task_states.IMAGE_PENDING_UPLOAD),
mock.call(task_state=task_states.IMAGE_UPLOADING,
expected_state=task_states.IMAGE_PENDING_UPLOAD)]
mock_update.has_calls(expected_update)
mock_update.assert_has_calls(expected_update)
self._snapshotops._vmutils.remove_vm_snapshot.assert_called_once_with(
fake_snapshot_path)
self._snapshotops._pathutils.rmtree.assert_called_once_with(

View File

@ -1422,10 +1422,11 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase):
self._vmops._pathutils.get_instance_dir.assert_called_once_with(
mock.sentinel.FAKE_VM_NAME,
remote_server=mock.sentinel.FAKE_DEST_HOST)
mock_copy.has_calls(mock.call(mock.sentinel.FAKE_DVD_PATH1,
mock.sentinel.FAKE_DEST_PATH),
mock.call(mock.sentinel.FAKE_DVD_PATH2,
mock.sentinel.FAKE_DEST_PATH))
self.assertEqual(2, mock_copy.call_count)
mock_copy.assert_has_calls([mock.call(mock.sentinel.FAKE_DVD_PATH1,
mock.sentinel.FAKE_DEST_PATH),
mock.call(mock.sentinel.FAKE_DVD_PATH2,
mock.sentinel.FAKE_DEST_PATH)])
def test_plug_vifs(self):
mock_instance = fake_instance.fake_instance_obj(self.context)

View File

@ -13663,19 +13663,20 @@ class LibvirtConnTestCase(test.NoDBTestCase,
expected_xml = [
('<hostdev mode="subsystem" type="pci" managed="yes">\n'
' <source>\n'
' <address bus="0x00" domain="0x0000" \
function="0x0" slot="0x00"/>\n'
' <address bus="0x00" domain="0x0000" '
'function="0x0" slot="0x00"/>\n'
' </source>\n'
'</hostdev>\n'),
('<hostdev mode="subsystem" type="pci" managed="yes">\n'
' <source>\n'
' <address bus="0x00" domain="0x0000" \
function="0x1" slot="0x00"/>\n'
' <address bus="0x00" domain="0x0000" '
'function="0x1" slot="0x00"/>\n'
' </source>\n'
'</hostdev>\n')
]
mock_detachDeviceFlags.has_calls([
self.assertEqual(2, mock_detachDeviceFlags.call_count)
mock_detachDeviceFlags.assert_has_calls([
mock.call(expected_xml[0], flags=1),
mock.call(expected_xml[1], flags=1)
])