Test: use assert_has_calls() instead

Some of the assertions in cinder test are sequential, should better
use assert_has_calls() instead of assert_any_call().
And assert_has_calls() provide more clear messages in case of failure.

Change-Id: I66d74d1b84f939eb02d00c6f84813beb7e7311e4
This commit is contained in:
Chaozhe.Chen 2016-02-18 15:01:00 +08:00
parent adda63d013
commit 5a35c8abb4

View File

@ -1442,12 +1442,13 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
rpc_init.assert_called_once_with(CONF) rpc_init.assert_called_once_with(CONF)
last_completed_audit_period.assert_called_once_with() last_completed_audit_period.assert_called_once_with()
volume_get_active_by_window.assert_called_once_with(ctxt, begin, end) volume_get_active_by_window.assert_called_once_with(ctxt, begin, end)
notify_about_volume_usage.assert_any_call(ctxt, volume1, 'exists', notify_about_volume_usage.assert_has_calls([
extra_usage_info=extra_info) mock.call(ctxt, volume1, 'exists', extra_usage_info=extra_info),
notify_about_volume_usage.assert_any_call( mock.call(ctxt, volume1, 'create.start',
ctxt, volume1, 'create.start', extra_usage_info=local_extra_info) extra_usage_info=local_extra_info),
notify_about_volume_usage.assert_any_call( mock.call(ctxt, volume1, 'create.end',
ctxt, volume1, 'create.end', extra_usage_info=local_extra_info) extra_usage_info=local_extra_info)
])
@mock.patch('cinder.volume.utils.notify_about_volume_usage') @mock.patch('cinder.volume.utils.notify_about_volume_usage')
@mock.patch('cinder.db.volume_get_active_by_window') @mock.patch('cinder.db.volume_get_active_by_window')
@ -1508,20 +1509,17 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
rpc_init.assert_called_once_with(CONF) rpc_init.assert_called_once_with(CONF)
last_completed_audit_period.assert_called_once_with() last_completed_audit_period.assert_called_once_with()
volume_get_active_by_window.assert_called_once_with(ctxt, begin, end) volume_get_active_by_window.assert_called_once_with(ctxt, begin, end)
notify_about_volume_usage.assert_any_call( notify_about_volume_usage.assert_has_calls([
ctxt, volume1, 'exists', extra_usage_info=extra_info) mock.call(ctxt, volume1, 'exists', extra_usage_info=extra_info),
notify_about_volume_usage.assert_any_call( mock.call(ctxt, volume1, 'create.start',
ctxt, volume1, 'create.start', extra_usage_info=local_extra_info_create),
extra_usage_info=local_extra_info_create) mock.call(ctxt, volume1, 'create.end',
notify_about_volume_usage.assert_any_call( extra_usage_info=local_extra_info_create),
ctxt, volume1, 'create.end', mock.call(ctxt, volume1, 'delete.start',
extra_usage_info=local_extra_info_create) extra_usage_info=local_extra_info_delete),
notify_about_volume_usage.assert_any_call( mock.call(ctxt, volume1, 'delete.end',
ctxt, volume1, 'delete.start', extra_usage_info=local_extra_info_delete)
extra_usage_info=local_extra_info_delete) ])
notify_about_volume_usage.assert_any_call(
ctxt, volume1, 'delete.end',
extra_usage_info=local_extra_info_delete)
@mock.patch('cinder.volume.utils.notify_about_snapshot_usage') @mock.patch('cinder.volume.utils.notify_about_snapshot_usage')
@mock.patch('cinder.objects.snapshot.SnapshotList.get_active_by_window') @mock.patch('cinder.objects.snapshot.SnapshotList.get_active_by_window')
@ -1587,14 +1585,13 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
last_completed_audit_period.assert_called_once_with() last_completed_audit_period.assert_called_once_with()
volume_get_active_by_window.assert_called_once_with(ctxt, begin, end) volume_get_active_by_window.assert_called_once_with(ctxt, begin, end)
self.assertFalse(notify_about_volume_usage.called) self.assertFalse(notify_about_volume_usage.called)
notify_about_snapshot_usage.assert_any_call(ctxt, snapshot1, 'exists', notify_about_snapshot_usage.assert_has_calls([
extra_info) mock.call(ctxt, snapshot1, 'exists', extra_info),
notify_about_snapshot_usage.assert_any_call( mock.call(ctxt, snapshot1, 'create.start',
ctxt, snapshot1, 'create.start', extra_usage_info=local_extra_info_create),
extra_usage_info=local_extra_info_create) mock.call(ctxt, snapshot1, 'delete.start',
notify_about_snapshot_usage.assert_any_call( extra_usage_info=local_extra_info_delete)
ctxt, snapshot1, 'delete.start', ])
extra_usage_info=local_extra_info_delete)
@mock.patch('cinder.volume.utils.notify_about_snapshot_usage') @mock.patch('cinder.volume.utils.notify_about_snapshot_usage')
@mock.patch('cinder.objects.snapshot.SnapshotList.get_active_by_window') @mock.patch('cinder.objects.snapshot.SnapshotList.get_active_by_window')
@ -1663,32 +1660,26 @@ class TestCinderVolumeUsageAuditCmd(test.TestCase):
rpc_init.assert_called_once_with(CONF) rpc_init.assert_called_once_with(CONF)
last_completed_audit_period.assert_called_once_with() last_completed_audit_period.assert_called_once_with()
volume_get_active_by_window.assert_called_once_with(ctxt, begin, end) volume_get_active_by_window.assert_called_once_with(ctxt, begin, end)
notify_about_volume_usage.assert_any_call( notify_about_volume_usage.assert_has_calls([
ctxt, volume1, 'exists', extra_usage_info=extra_info) mock.call(ctxt, volume1, 'exists', extra_usage_info=extra_info),
notify_about_volume_usage.assert_any_call( mock.call(ctxt, volume1, 'create.start',
ctxt, volume1, 'create.start', extra_usage_info=extra_info_volume_create),
extra_usage_info=extra_info_volume_create) mock.call(ctxt, volume1, 'create.end',
notify_about_volume_usage.assert_any_call( extra_usage_info=extra_info_volume_create),
ctxt, volume1, 'create.end', mock.call(ctxt, volume1, 'delete.start',
extra_usage_info=extra_info_volume_create) extra_usage_info=extra_info_volume_delete),
notify_about_volume_usage.assert_any_call( mock.call(ctxt, volume1, 'delete.end',
ctxt, volume1, 'delete.start', extra_usage_info=extra_info_volume_delete)
extra_usage_info=extra_info_volume_delete) ])
notify_about_volume_usage.assert_any_call(
ctxt, volume1, 'delete.end',
extra_usage_info=extra_info_volume_delete)
notify_about_snapshot_usage.assert_any_call(ctxt, snapshot1, notify_about_snapshot_usage.assert_has_calls([
'exists', extra_info) mock.call(ctxt, snapshot1, 'exists', extra_info),
notify_about_snapshot_usage.assert_any_call( mock.call(ctxt, snapshot1, 'create.start',
ctxt, snapshot1, 'create.start', extra_usage_info=extra_info_snapshot_create),
extra_usage_info=extra_info_snapshot_create) mock.call(ctxt, snapshot1, 'create.end',
notify_about_snapshot_usage.assert_any_call( extra_usage_info=extra_info_snapshot_create),
ctxt, snapshot1, 'create.end', mock.call(ctxt, snapshot1, 'delete.start',
extra_usage_info=extra_info_snapshot_create) extra_usage_info=extra_info_snapshot_delete),
notify_about_snapshot_usage.assert_any_call( mock.call(ctxt, snapshot1, 'delete.end',
ctxt, snapshot1, 'delete.start', extra_usage_info=extra_info_snapshot_delete)
extra_usage_info=extra_info_snapshot_delete) ])
notify_about_snapshot_usage.assert_any_call(
ctxt, snapshot1, 'delete.end',
extra_usage_info=extra_info_snapshot_delete)