diff options
| author | Huanxuan Ao <huanxuan.ao@easystack.cn> | 2016-08-16 10:52:26 +0800 |
|---|---|---|
| committer | Huanxuan Ao <huanxuan.ao@easystack.cn> | 2016-09-22 13:55:12 +0800 |
| commit | ddf84429f297b34ce7067250d834ea897e37f37c (patch) | |
| tree | 2a10b2f1b65b9f8b4ae595553039871064916c18 /openstackclient/tests | |
| parent | 69c4f605ecce597af3a574d2f7c27c1dbaa17989 (diff) | |
| download | python-openstackclient-ddf84429f297b34ce7067250d834ea897e37f37c.tar.gz | |
Add "volume backup set" command in volume v2
Add "volume backup set" command in volume v2 (v2 only)
to set backup name, description and state
Change-Id: If17e8457db9a4704fb5bb9c75921ed82fd0069cf
Closes-Bug: #1613261
Diffstat (limited to 'openstackclient/tests')
| -rw-r--r-- | openstackclient/tests/unit/volume/v2/test_backup.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/openstackclient/tests/unit/volume/v2/test_backup.py b/openstackclient/tests/unit/volume/v2/test_backup.py index 45633870..306c9eb3 100644 --- a/openstackclient/tests/unit/volume/v2/test_backup.py +++ b/openstackclient/tests/unit/volume/v2/test_backup.py @@ -336,6 +336,75 @@ class TestBackupRestore(TestBackup): self.assertIsNone(result) +class TestBackupSet(TestBackup): + + backup = volume_fakes.FakeBackup.create_one_backup() + + def setUp(self): + super(TestBackupSet, self).setUp() + + self.backups_mock.get.return_value = self.backup + + # Get the command object to test + self.cmd = backup.SetVolumeBackup(self.app, None) + + def test_backup_set_name(self): + arglist = [ + '--name', 'new_name', + self.backup.id, + ] + verifylist = [ + ('name', 'new_name'), + ('backup', self.backup.id), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + # In base command class ShowOne in cliff, abstract method take_action() + # returns nothing + result = self.cmd.take_action(parsed_args) + self.backups_mock.update.assert_called_once_with( + self.backup.id, **{'name': 'new_name'}) + self.assertIsNone(result) + + def test_backup_set_state(self): + arglist = [ + '--state', 'error', + self.backup.id + ] + verifylist = [ + ('state', 'error'), + ('backup', self.backup.id) + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + result = self.cmd.take_action(parsed_args) + self.backups_mock.reset_state.assert_called_once_with( + self.backup.id, 'error') + self.assertIsNone(result) + + def test_backup_set_state_failed(self): + self.backups_mock.reset_state.side_effect = exceptions.CommandError() + arglist = [ + '--state', 'error', + self.backup.id + ] + verifylist = [ + ('state', 'error'), + ('backup', self.backup.id) + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + try: + self.cmd.take_action(parsed_args) + self.fail('CommandError should be raised.') + except exceptions.CommandError as e: + self.assertEqual('One or more of the set operations failed', + str(e)) + self.backups_mock.reset_state.assert_called_with( + self.backup.id, 'error') + + class TestBackupShow(TestBackup): backup = volume_fakes.FakeBackup.create_one_backup() |
