Tests: RBD: Refactor mocks
This makes the test methods more readable by
avoiding excessive indentation.
@@ -867,21 +867,20 @@ class RBDTestCase(test.TestCase):
self.mock_rbd.RBD.return_value.remove.side_effect = (
self.mock_rbd.ImageBusy)
- with mock.patch.object(self.driver, '_get_clone_info') as \
- mock_get_clone_info:
+ mock_get_clone_info = self.mock_object(self.driver, '_get_clone_info')
mock_get_clone_info.return_value = (None, None, None)
- with mock.patch.object(self.driver, '_delete_backup_snaps') as \
- mock_delete_backup_snaps:
- with mock.patch.object(driver, 'RADOSClient') as \
- mock_rados_client:
+
+ mock_delete_backup_snaps = self.mock_object(self.driver,
+ '_delete_backup_snaps')
+ mock_rados_client = self.mock_object(driver, 'RADOSClient')
+
self.driver.delete_volume(self.volume_a)
mock_get_clone_info.assert_called_once_with(
self.mock_rbd.Image.return_value,
self.volume_a.name,
None)
- (self.mock_rbd.Image.return_value.list_snaps
- .assert_called_once_with())
+ self.mock_rbd.Image.return_value.list_snaps.assert_called_once_with()
mock_rados_client.assert_called_once_with(self.driver)
mock_delete_backup_snaps.assert_called_once_with(
self.mock_rbd.Image.return_value)
@@ -947,20 +946,19 @@ class RBDTestCase(test.TestCase):
self.mock_rbd.RBD.return_value.remove.side_effect = (
self.mock_rbd.ImageNotFound)
- with mock.patch.object(self.driver, '_get_clone_info') as \
- mock_get_clone_info:
+ mock_delete_backup_snaps = self.mock_object(self.driver,
+ '_delete_backup_snaps')
+ mock_rados_client = self.mock_object(driver, 'RADOSClient')
+
+ mock_get_clone_info = self.mock_object(self.driver, '_get_clone_info')
mock_get_clone_info.return_value = (None, None, None)
- with mock.patch.object(self.driver, '_delete_backup_snaps') as \
- mock_delete_backup_snaps:
- with mock.patch.object(driver, 'RADOSClient') as \
- mock_rados_client:
+
self.assertIsNone(self.driver.delete_volume(self.volume_a))
mock_get_clone_info.assert_called_once_with(
self.mock_rbd.Image.return_value,
self.volume_a.name,
None)
- (self.mock_rbd.Image.return_value.list_snaps
- .assert_called_once_with())
+ self.mock_rbd.Image.return_value.list_snaps.assert_called_once_with()
mock_rados_client.assert_called_once_with(self.driver)
mock_delete_backup_snaps.assert_called_once_with(
self.mock_rbd.Image.return_value)
