Skip to content

Commit ba7e956

Browse files
committed
Merge pull request #542 from sudorandom/issue-541
Fixes bug when prompting users for confirmation
2 parents 6ece889 + f6f1445 commit ba7e956

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

SoftLayer/CLI/formatting.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ def no_going_back(confirmation):
192192
prompt = ('This action cannot be undone! Type "%s" or press Enter '
193193
'to abort' % confirmation)
194194

195-
ans = click.confirm(prompt, default='', show_default=False).lower()
196-
if ans == str(confirmation):
195+
ans = click.prompt(prompt, default='', show_default=False)
196+
if ans.lower() == str(confirmation):
197197
return True
198198

199199
return False

SoftLayer/managers/messaging.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,12 @@ def _make_request(self, method, path, **kwargs):
168168

169169
url = '/'.join((self.endpoint, 'v1', self.account_id, path))
170170
resp = requests.request(method, url, **kwargs)
171-
resp.raise_for_status()
171+
try:
172+
resp.raise_for_status()
173+
except requests.HTTPError as ex:
174+
content = json.loads(ex.response.content)
175+
raise exceptions.SoftLayerAPIError(ex.response.status_code,
176+
content['message'])
172177
return resp
173178

174179
def authenticate(self, username, api_key, auth_token=None):

SoftLayer/tests/CLI/helper_tests.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,21 @@ def test_fail(self):
4141

4242
class PromptTests(testing.TestCase):
4343

44-
@mock.patch('click.confirm')
45-
def test_do_or_die(self, confirm_mock):
44+
@mock.patch('click.prompt')
45+
def test_do_or_die(self, prompt_mock):
4646
confirmed = '37347373737'
47-
confirm_mock.return_value = confirmed
47+
prompt_mock.return_value = confirmed
4848
result = formatting.no_going_back(confirmed)
4949
self.assertTrue(result)
5050

5151
# no_going_back should cast int's to str()
5252
confirmed = '4712309182309'
53-
confirm_mock.return_value = confirmed
53+
prompt_mock.return_value = confirmed
5454
result = formatting.no_going_back(int(confirmed))
5555
self.assertTrue(result)
5656

5757
confirmed = None
58-
confirm_mock.return_value = ''
58+
prompt_mock.return_value = ''
5959
result = formatting.no_going_back(confirmed)
6060
self.assertFalse(result)
6161

0 commit comments

Comments
 (0)