summaryrefslogtreecommitdiff
path: root/heatclient/tests
diff options
context:
space:
mode:
authorricolin <rico.lin@easystack.cn>2016-11-16 11:48:54 +0800
committerricolin <rico.lin@easystack.cn>2017-04-26 12:22:54 +0800
commite2d92f7930a3f493510c098111d287c71ed9d96b (patch)
tree4b225ebfcdceb9de7c0afe3d9502cfd096769f41 /heatclient/tests
parent71b4fc35d0022d225479e60595cc96a778933f15 (diff)
downloadpython-heatclient-e2d92f7930a3f493510c098111d287c71ed9d96b.tar.gz
Add '--yes' for openstack stack snapshot delete
Add optional arguments '--yes' or '-y' in osc cli `openstack stack snapshot delete`. There is no judgement before use that cli So propose to add it in case that we delete the snapshot unintentionally. Closes-Bug: #1642874 Change-Id: If7b515dff64a18f56046b890279c2c59b0ab9dc7
Diffstat (limited to 'heatclient/tests')
-rw-r--r--heatclient/tests/unit/osc/v1/test_snapshot.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/heatclient/tests/unit/osc/v1/test_snapshot.py b/heatclient/tests/unit/osc/v1/test_snapshot.py
index f51a6ed..7f69c61 100644
--- a/heatclient/tests/unit/osc/v1/test_snapshot.py
+++ b/heatclient/tests/unit/osc/v1/test_snapshot.py
@@ -10,8 +10,9 @@
# License for the specific language governing permissions and limitations
# under the License.
#
-
+import mock
from osc_lib import exceptions as exc
+import six
from heatclient import exc as heat_exc
from heatclient.osc.v1 import snapshot
@@ -157,3 +158,28 @@ class TestSnapshotDelete(TestStack):
exc.CommandError,
self.cmd.take_action,
parsed_args)
+
+ @mock.patch('sys.stdin', spec=six.StringIO)
+ def test_snapshot_delete_prompt(self, mock_stdin):
+ arglist = ['my_stack', 'snapshot_id']
+ mock_stdin.isatty.return_value = True
+ mock_stdin.readline.return_value = 'y'
+ parsed_args = self.check_parser(self.cmd, arglist, [])
+
+ self.cmd.take_action(parsed_args)
+
+ mock_stdin.readline.assert_called_with()
+ self.stack_client.snapshot_delete.assert_called_with('my_stack',
+ 'snapshot_id')
+
+ @mock.patch('sys.stdin', spec=six.StringIO)
+ def test_snapshot_delete_prompt_no(self, mock_stdin):
+ arglist = ['my_stack', 'snapshot_id']
+ mock_stdin.isatty.return_value = True
+ mock_stdin.readline.return_value = 'n'
+ parsed_args = self.check_parser(self.cmd, arglist, [])
+
+ self.cmd.take_action(parsed_args)
+
+ mock_stdin.readline.assert_called_with()
+ self.stack_client.snapshot_delete.assert_not_called()