diff options
| author | Huanxuan Ao <huanxuan.ao@easystack.cn> | 2016-09-22 17:10:32 +0800 |
|---|---|---|
| committer | Stephen Finucane <sfinucan@redhat.com> | 2022-03-10 12:04:11 +0000 |
| commit | de4a69a29ff4657d0c3cd95ca9f35ff24f653b5f (patch) | |
| tree | bf53a4f91a0afeddf809297d6f54effe94a6cfa0 /openstackclient/tests/unit/volume/v1 | |
| parent | 8c975ba09790f9fe57c32293fb4320bf5c56e012 (diff) | |
| download | python-openstackclient-de4a69a29ff4657d0c3cd95ca9f35ff24f653b5f.tar.gz | |
Refactor "volume backup restore" command
Make the positional argument "volume" optional and add a "--force"
option (volume v2 only) to the "volume backup restore" command.
Closes-Bug: #1597189
Change-Id: If944e10158bd18e8331be63e96187a23e23095d7
Diffstat (limited to 'openstackclient/tests/unit/volume/v1')
| -rw-r--r-- | openstackclient/tests/unit/volume/v1/test_volume_backup.py | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/openstackclient/tests/unit/volume/v1/test_volume_backup.py b/openstackclient/tests/unit/volume/v1/test_volume_backup.py index f25a5ffa..2f568929 100644 --- a/openstackclient/tests/unit/volume/v1/test_volume_backup.py +++ b/openstackclient/tests/unit/volume/v1/test_volume_backup.py @@ -319,29 +319,69 @@ class TestBackupRestore(TestBackup): attrs={'volume_id': volume.id}) def setUp(self): - super(TestBackupRestore, self).setUp() + super().setUp() self.backups_mock.get.return_value = self.backup self.volumes_mock.get.return_value = self.volume - self.restores_mock.restore.return_value = None + self.restores_mock.restore.return_value = ( + volume_fakes.FakeVolume.create_one_volume( + {'id': self.volume['id']}, + ) + ) # Get the command object to mock self.cmd = volume_backup.RestoreVolumeBackup(self.app, None) def test_backup_restore(self): arglist = [ self.backup.id, - self.backup.volume_id ] verifylist = [ ("backup", self.backup.id), - ("volume", self.backup.volume_id) + ("volume", None), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) self.restores_mock.restore.assert_called_with(self.backup.id, - self.backup.volume_id) - self.assertIsNone(result) + None) + self.assertIsNotNone(result) + + def test_backup_restore_with_existing_volume(self): + arglist = [ + self.backup.id, + self.backup.volume_id, + ] + verifylist = [ + ("backup", self.backup.id), + ("volume", self.backup.volume_id), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + result = self.cmd.take_action(parsed_args) + self.restores_mock.restore.assert_called_with( + self.backup.id, self.backup.volume_id, + ) + self.assertIsNotNone(result) + + def test_backup_restore_with_invalid_volume(self): + arglist = [ + self.backup.id, + "unexist_volume", + ] + verifylist = [ + ("backup", self.backup.id), + ("volume", "unexist_volume"), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + with mock.patch.object( + utils, 'find_resource', + side_effect=exceptions.CommandError(), + ): + self.assertRaises( + exceptions.CommandError, + self.cmd.take_action, + parsed_args, + ) class TestBackupShow(TestBackup): |
