summaryrefslogtreecommitdiff
path: root/openstackclient/tests/unit
diff options
context:
space:
mode:
authorzhiyong.dai <zhiyong.dai@easystack.cn>2017-01-02 17:55:32 +0800
committerDean Troyer <dtroyer@gmail.com>2017-01-25 17:32:58 -0600
commit26d50be79a401322f4e74b94c066257ddf0f287c (patch)
treeaeae1d1b5d451458e806b7a32ee4816c14afa17a /openstackclient/tests/unit
parentd5745eaaa79491728da656baee0451b861723cce (diff)
downloadpython-openstackclient-26d50be79a401322f4e74b94c066257ddf0f287c.tar.gz
Support "--no-property" option in volume snapshot set
Supporting "--no-property" option will apply user a convenient way to clean all properties of volume snapshot in a short command, and this kind of behavior is the recommended way to devref. The patch adds "--no-property" option in "volume snapshot set" command, and update related test cases and devref document. Change-Id: I5f10cc2b5814553699920c4343995b2e11416e4e Implements: blueprint allow-overwrite-set-options
Diffstat (limited to 'openstackclient/tests/unit')
-rw-r--r--openstackclient/tests/unit/volume/v1/test_snapshot.py13
-rw-r--r--openstackclient/tests/unit/volume/v2/test_snapshot.py63
2 files changed, 71 insertions, 5 deletions
diff --git a/openstackclient/tests/unit/volume/v1/test_snapshot.py b/openstackclient/tests/unit/volume/v1/test_snapshot.py
index fd878f45..87a62b0a 100644
--- a/openstackclient/tests/unit/volume/v1/test_snapshot.py
+++ b/openstackclient/tests/unit/volume/v1/test_snapshot.py
@@ -429,15 +429,17 @@ class TestSnapshotSet(TestSnapshot):
arglist = [
"--name", "new_snapshot",
"--description", "new_description",
- "--property", "x=y",
- "--property", "foo=foo",
+ "--property", "foo_1=foo_1",
+ "--property", "foo_2=foo_2",
+ "--no-property",
self.snapshot.id,
]
- new_property = {"x": "y", "foo": "foo"}
+ new_property = {"foo_1": "foo_1", "foo_2": "foo_2"}
verifylist = [
("name", "new_snapshot"),
("description", "new_description"),
("property", new_property),
+ ("no_property", True),
("snapshot", self.snapshot.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -449,8 +451,11 @@ class TestSnapshotSet(TestSnapshot):
"display_description": "new_description",
}
self.snapshot.update.assert_called_with(**kwargs)
+ self.snapshots_mock.delete_metadata.assert_called_with(
+ self.snapshot.id, ["foo"]
+ )
self.snapshots_mock.set_metadata.assert_called_with(
- self.snapshot.id, new_property
+ self.snapshot.id, {"foo_2": "foo_2", "foo_1": "foo_1"}
)
self.assertIsNone(result)
diff --git a/openstackclient/tests/unit/volume/v2/test_snapshot.py b/openstackclient/tests/unit/volume/v2/test_snapshot.py
index 8ce356ae..f3a6ed3c 100644
--- a/openstackclient/tests/unit/volume/v2/test_snapshot.py
+++ b/openstackclient/tests/unit/volume/v2/test_snapshot.py
@@ -499,7 +499,23 @@ class TestSnapshotSet(TestSnapshot):
# Get the command object to mock
self.cmd = volume_snapshot.SetVolumeSnapshot(self.app, None)
- def test_snapshot_set(self):
+ def test_snapshot_set_no_option(self):
+ arglist = [
+ self.snapshot.id,
+ ]
+ verifylist = [
+ ("snapshot", self.snapshot.id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+ self.snapshots_mock.get.assert_called_once_with(parsed_args.snapshot)
+ self.assertNotCalled(self.snapshots_mock.reset_state)
+ self.assertNotCalled(self.snapshots_mock.update)
+ self.assertNotCalled(self.snapshots_mock.set_metadata)
+ self.assertIsNone(result)
+
+ def test_snapshot_set_name_and_property(self):
arglist = [
"--name", "new_snapshot",
"--property", "x=y",
@@ -526,6 +542,51 @@ class TestSnapshotSet(TestSnapshot):
)
self.assertIsNone(result)
+ def test_snapshot_set_with_no_property(self):
+ arglist = [
+ "--no-property",
+ self.snapshot.id,
+ ]
+ verifylist = [
+ ("no_property", True),
+ ("snapshot", self.snapshot.id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+ self.snapshots_mock.get.assert_called_once_with(parsed_args.snapshot)
+ self.assertNotCalled(self.snapshots_mock.reset_state)
+ self.assertNotCalled(self.snapshots_mock.update)
+ self.assertNotCalled(self.snapshots_mock.set_metadata)
+ self.snapshots_mock.delete_metadata.assert_called_with(
+ self.snapshot.id, ["foo"]
+ )
+ self.assertIsNone(result)
+
+ def test_snapshot_set_with_no_property_and_property(self):
+ arglist = [
+ "--no-property",
+ "--property", "foo_1=bar_1",
+ self.snapshot.id,
+ ]
+ verifylist = [
+ ("no_property", True),
+ ("property", {"foo_1": "bar_1"}),
+ ("snapshot", self.snapshot.id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+ self.snapshots_mock.get.assert_called_once_with(parsed_args.snapshot)
+ self.assertNotCalled(self.snapshots_mock.reset_state)
+ self.assertNotCalled(self.snapshots_mock.update)
+ self.snapshots_mock.delete_metadata.assert_called_with(
+ self.snapshot.id, ["foo"]
+ )
+ self.snapshots_mock.set_metadata.assert_called_once_with(
+ self.snapshot.id, {"foo_1": "bar_1"})
+ self.assertIsNone(result)
+
def test_snapshot_set_state_to_error(self):
arglist = [
"--state", "error",