summaryrefslogtreecommitdiff
path: root/openstackclient/tests/unit/volume/v2
diff options
context:
space:
mode:
authorHuanxuan Ao <huanxuan.ao@easystack.cn>2016-08-15 19:03:50 +0800
committerHuanxuan Ao <huanxuan.ao@easystack.cn>2016-09-11 11:41:05 +0800
commit10e665a148efec0cf75bd5dd07decf23a36a52e0 (patch)
tree595d092e5e03ce2ebaeb5973c0bdffba38a76920 /openstackclient/tests/unit/volume/v2
parent676a0e9696ba7550132e4501bdbf3160608faed6 (diff)
downloadpython-openstackclient-10e665a148efec0cf75bd5dd07decf23a36a52e0.tar.gz
Error handling of multi REST API calls for "snapshot set" command
Support multi REST API calls error handling for "snapshot set" command follow the rule in doc/source/command-errors.rst. Also add a unit test for testing the error handling Change-Id: I0c6214271bc54a25b051c0a62438c3344c8b51d7
Diffstat (limited to 'openstackclient/tests/unit/volume/v2')
-rw-r--r--openstackclient/tests/unit/volume/v2/test_snapshot.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/openstackclient/tests/unit/volume/v2/test_snapshot.py b/openstackclient/tests/unit/volume/v2/test_snapshot.py
index 333d8d72..d355662d 100644
--- a/openstackclient/tests/unit/volume/v2/test_snapshot.py
+++ b/openstackclient/tests/unit/volume/v2/test_snapshot.py
@@ -376,6 +376,55 @@ class TestSnapshotSet(TestSnapshot):
self.snapshot.id, "error")
self.assertIsNone(result)
+ def test_volume_set_state_failed(self):
+ self.snapshots_mock.reset_state.side_effect = exceptions.CommandError()
+ arglist = [
+ '--state', 'error',
+ self.snapshot.id
+ ]
+ verifylist = [
+ ('state', 'error'),
+ ('snapshot', self.snapshot.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.snapshots_mock.reset_state.assert_called_once_with(
+ self.snapshot.id, 'error')
+
+ def test_volume_set_name_and_state_failed(self):
+ self.snapshots_mock.reset_state.side_effect = exceptions.CommandError()
+ arglist = [
+ '--state', 'error',
+ "--name", "new_snapshot",
+ self.snapshot.id
+ ]
+ verifylist = [
+ ('state', 'error'),
+ ("name", "new_snapshot"),
+ ('snapshot', self.snapshot.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))
+ kwargs = {
+ "name": "new_snapshot",
+ }
+ self.snapshots_mock.update.assert_called_once_with(
+ self.snapshot.id, **kwargs)
+ self.snapshots_mock.reset_state.assert_called_once_with(
+ self.snapshot.id, 'error')
+
class TestSnapshotShow(TestSnapshot):