summaryrefslogtreecommitdiff
path: root/heatclient/tests/unit/test_shell.py
diff options
context:
space:
mode:
Diffstat (limited to 'heatclient/tests/unit/test_shell.py')
-rw-r--r--heatclient/tests/unit/test_shell.py159
1 files changed, 113 insertions, 46 deletions
diff --git a/heatclient/tests/unit/test_shell.py b/heatclient/tests/unit/test_shell.py
index 383ee2c..b9ec014 100644
--- a/heatclient/tests/unit/test_shell.py
+++ b/heatclient/tests/unit/test_shell.py
@@ -32,6 +32,7 @@ import testscenarios
import testtools
import yaml
+from heatclient._i18n import _
from heatclient.common import http
from heatclient.common import utils
from heatclient import exc
@@ -126,25 +127,25 @@ class TestCase(testtools.TestCase):
mockfixture = self.useFixture(mockpatch.Patch(target, **kwargs))
return mockfixture.mock
- def stack_list_resp_dict(self, show_nested=False):
- resp_dict = {"stacks": [
- {
- "id": "1",
- "stack_name": "teststack",
- "stack_owner": "testowner",
- "project": "testproject",
- "stack_status": 'CREATE_COMPLETE',
- "creation_time": "2012-10-25T01:58:47Z"
- },
- {
- "id": "2",
- "stack_name": "teststack2",
- "stack_owner": "testowner",
- "project": "testproject",
- "stack_status": 'IN_PROGRESS',
- "creation_time": "2012-10-25T01:58:47Z"
- }]
- }
+ def stack_list_resp_dict(self, show_nested=False, include_project=False):
+ stack1 = {
+ "id": "1",
+ "stack_name": "teststack",
+ "stack_owner": "testowner",
+ "stack_status": 'CREATE_COMPLETE',
+ "creation_time": "2012-10-25T01:58:47Z"}
+ stack2 = {
+ "id": "2",
+ "stack_name": "teststack2",
+ "stack_owner": "testowner",
+ "stack_status": 'IN_PROGRESS',
+ "creation_time": "2012-10-25T01:58:47Z"
+ }
+ if include_project:
+ stack1['project'] = 'testproject'
+ stack1['project'] = 'testproject'
+
+ resp_dict = {"stacks": [stack1, stack2]}
if show_nested:
nested = {
"id": "3",
@@ -153,6 +154,8 @@ class TestCase(testtools.TestCase):
"creation_time": "2012-10-25T01:58:47Z",
"parent": "theparentof3"
}
+ if include_project:
+ nested['project'] = 'testproject'
resp_dict["stacks"].append(nested)
return resp_dict
@@ -211,7 +214,7 @@ class TestCase(testtools.TestCase):
{"href": "http://heat.example.com:8004/foo3",
"rel": "stack"}],
"logical_resource_id": "aResource",
- "physical_resource_id": None,
+ "physical_resource_id": 'foo3',
"resource_name": stack_name,
"resource_status": "%s_IN_PROGRESS" % action,
"resource_status_reason": "state changed"})
@@ -225,7 +228,7 @@ class TestCase(testtools.TestCase):
{"href": "http://heat.example.com:8004/foo3",
"rel": "stack"}],
"logical_resource_id": "aResource",
- "physical_resource_id": None,
+ "physical_resource_id": 'foo3',
"resource_name": stack_name,
"resource_status": "%s_%s" % (action, final_state),
"resource_status_reason": "state changed"})
@@ -561,7 +564,7 @@ class ShellTestNoMox(TestCase):
rsrc_eventid2=eventid2
)
- self.requests.get('http://heat.example.com/stacks/myStack%2F60f83b5e/'
+ self.requests.get('http://heat.example.com/stacks/myStack/60f83b5e/'
'resources/myDeployment/events',
headers={'Content-Type': 'application/json'},
json=resp_dict)
@@ -618,7 +621,8 @@ class ShellTestEndpointType(TestCase):
'region_name': '',
'username': 'username',
'password': 'password',
- 'include_pass': False
+ 'include_pass': False,
+ 'endpoint_override': mox.IgnoreArg(),
}
http._construct_http_client(**kwargs)
heatclient.v1.shell.do_stack_list(mox.IgnoreArg(), mox.IgnoreArg())
@@ -637,7 +641,8 @@ class ShellTestEndpointType(TestCase):
'region_name': '',
'username': 'username',
'password': 'password',
- 'include_pass': False
+ 'include_pass': False,
+ 'endpoint_override': mox.IgnoreArg(),
}
http._construct_http_client(**kwargs)
heatclient.v1.shell.do_stack_list(mox.IgnoreArg(), mox.IgnoreArg())
@@ -658,7 +663,8 @@ class ShellTestEndpointType(TestCase):
'region_name': '',
'username': 'username',
'password': 'password',
- 'include_pass': False
+ 'include_pass': False,
+ 'endpoint_override': mox.IgnoreArg(),
}
http._construct_http_client(**kwargs)
heatclient.v1.shell.do_stack_list(mox.IgnoreArg(), mox.IgnoreArg())
@@ -2220,6 +2226,65 @@ class ShellTestUserPass(ShellBase):
resp = self.shell('snapshot-show teststack/1 2')
self.assertEqual(resp_dict, jsonutils.loads(resp))
+ # the main thing this @mock.patch is doing here is keeping
+ # sys.stdin untouched for later tests
+ @mock.patch('sys.stdin', new_callable=six.StringIO)
+ def test_snapshot_delete_prompt_with_tty(self, ms):
+ self.register_keystone_auth_fixture()
+ resp_dict = {"snapshot": {
+ "id": "2",
+ "creation_time": "2012-10-25T01:58:47Z"
+ }}
+
+ mock_stdin = mock.Mock()
+ mock_stdin.isatty = mock.Mock()
+ mock_stdin.isatty.return_value = True
+ mock_stdin.readline = mock.Mock()
+ mock_stdin.readline.return_value = 'n'
+ sys.stdin = mock_stdin
+
+ self.mock_request_delete('/stacks/teststack/1/snapshots/2', resp_dict)
+
+ self.m.ReplayAll()
+
+ resp = self.shell('snapshot-delete teststack/1 2')
+ resp_text = ('Are you sure you want to delete the snapshot of '
+ 'this stack [Y/N]?')
+ self.assertEqual(resp_text, resp)
+ self.m.ReplayAll()
+
+ mock_stdin.readline.return_value = 'Y'
+ resp = self.shell('snapshot-delete teststack/1 2')
+ msg = _("Request to delete the snapshot 2 of the stack "
+ "teststack/1 has been accepted.")
+ self.assertRegex(resp, msg)
+
+ # the main thing this @mock.patch is doing here is keeping
+ # sys.stdin untouched for later tests
+ @mock.patch('sys.stdin', new_callable=six.StringIO)
+ def test_snapshot_delete_prompt_with_tty_y(self, ms):
+ self.register_keystone_auth_fixture()
+ resp_dict = {"snapshot": {
+ "id": "2",
+ "creation_time": "2012-10-25T01:58:47Z"
+ }}
+
+ mock_stdin = mock.Mock()
+ mock_stdin.isatty = mock.Mock()
+ mock_stdin.isatty.return_value = True
+ mock_stdin.readline = mock.Mock()
+ mock_stdin.readline.return_value = ''
+ sys.stdin = mock_stdin
+
+ self.mock_request_delete('/stacks/teststack/1/snapshots/2', resp_dict)
+
+ self.m.ReplayAll()
+ # -y from the shell should skip the n/y prompt
+ resp = self.shell('snapshot-delete -y teststack/1 2')
+ msg = _("Request to delete the snapshot 2 of the stack "
+ "teststack/1 has been accepted.")
+ self.assertRegex(resp, msg)
+
def test_snapshot_delete(self):
self.register_keystone_auth_fixture()
@@ -2231,7 +2296,9 @@ class ShellTestUserPass(ShellBase):
self.m.ReplayAll()
resp = self.shell('snapshot-delete teststack/1 2')
- self.assertEqual("", resp)
+ msg = _("Request to delete the snapshot 2 of the stack "
+ "teststack/1 has been accepted.")
+ self.assertRegex(resp, msg)
def test_stack_restore(self):
self.register_keystone_auth_fixture()
@@ -2617,9 +2684,9 @@ class ShellTestEvents(ShellBase):
resource_name = 'testresource/1'
self.mock_request_get(
'/stacks/%s/resources/%s/events?sort_dir=asc' % (
- parse.quote(stack_id, ''),
+ parse.quote(stack_id),
parse.quote(encodeutils.safe_encode(
- resource_name), '')),
+ resource_name))),
resp_dict)
self.m.ReplayAll()
@@ -2693,10 +2760,10 @@ class ShellTestEvents(ShellBase):
self.mock_request_get(
'/stacks/%s/resources/%s/events/%s' %
(
- parse.quote(stack_id, ''),
+ parse.quote(stack_id),
parse.quote(encodeutils.safe_encode(
- resource_name), ''),
- parse.quote(self.event_id_one, '')
+ resource_name)),
+ parse.quote(self.event_id_one)
),
resp_dict)
@@ -3276,9 +3343,9 @@ class ShellTestResources(ShellBase):
self.mock_request_get(
'/stacks/%s/resources/%s?with_attr=attr_a&with_attr=attr_b' %
(
- parse.quote(stack_id, ''),
+ parse.quote(stack_id),
parse.quote(encodeutils.safe_encode(
- resource_name), '')
+ resource_name))
), resp_dict)
self.m.ReplayAll()
@@ -3318,9 +3385,9 @@ class ShellTestResources(ShellBase):
self.mock_request_post(
'/stacks/%s/resources/%s/signal' %
(
- parse.quote(stack_id, ''),
+ parse.quote(stack_id),
parse.quote(encodeutils.safe_encode(
- resource_name), '')
+ resource_name))
),
'',
data={'message': 'Content'}
@@ -3340,9 +3407,9 @@ class ShellTestResources(ShellBase):
self.mock_request_post(
'/stacks/%s/resources/%s/signal' %
(
- parse.quote(stack_id, ''),
+ parse.quote(stack_id),
parse.quote(encodeutils.safe_encode(
- resource_name), '')
+ resource_name))
),
'',
data=None
@@ -3400,9 +3467,9 @@ class ShellTestResources(ShellBase):
self.mock_request_post(
'/stacks/%s/resources/%s/signal' %
(
- parse.quote(stack_id, ''),
+ parse.quote(stack_id),
parse.quote(encodeutils.safe_encode(
- resource_name), '')
+ resource_name))
),
'',
data={'message': 'Content'}
@@ -3425,9 +3492,9 @@ class ShellTestResources(ShellBase):
self.mock_request_patch(
'/stacks/%s/resources/%s' %
(
- parse.quote(stack_id, ''),
+ parse.quote(stack_id),
parse.quote(encodeutils.safe_encode(
- resource_name), '')
+ resource_name))
),
'',
req_headers=False,
@@ -3448,9 +3515,9 @@ class ShellTestResources(ShellBase):
self.mock_request_patch(
'/stacks/%s/resources/%s' %
(
- parse.quote(stack_id, ''),
+ parse.quote(stack_id),
parse.quote(encodeutils.safe_encode(
- resource_name), '')
+ resource_name))
),
'',
req_headers=False,
@@ -3471,9 +3538,9 @@ class ShellTestResources(ShellBase):
self.mock_request_patch(
'/stacks/%s/resources/%s' %
(
- parse.quote(stack_id, ''),
+ parse.quote(stack_id),
parse.quote(encodeutils.safe_encode(
- resource_name), '')
+ resource_name))
),
'',
req_headers=False,
@@ -4206,7 +4273,7 @@ class MockShellTestUserPass(MockShellBase):
def test_stack_list_with_args(self):
self.register_keystone_auth_fixture()
- resp_dict = self.stack_list_resp_dict()
+ resp_dict = self.stack_list_resp_dict(include_project=True)
resp = fakes.FakeHTTPResponse(
200,
'success, you',