summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-06-04 02:20:33 +0000
committerGerrit Code Review <review@openstack.org>2016-06-04 02:20:34 +0000
commite1e2678cd0a99955c280a813e10c6ce7494389cd (patch)
treea750d3dd78cfbc461f40063a420eb3bc7f21c5fe
parente05464fbfa03ee6d938c145ede111f4b1e828d58 (diff)
parentff505d72cdec8adfee45852d564985798a563d21 (diff)
downloadpython-swiftclient-e1e2678cd0a99955c280a813e10c6ce7494389cd.tar.gz
Merge "Suppress InsecureRequestWarning when using --insecure"
-rwxr-xr-xswiftclient/shell.py5
-rw-r--r--tests/unit/test_shell.py28
2 files changed, 23 insertions, 10 deletions
diff --git a/swiftclient/shell.py b/swiftclient/shell.py
index 5eafe0b..486dc48 100755
--- a/swiftclient/shell.py
+++ b/swiftclient/shell.py
@@ -1524,6 +1524,11 @@ Examples:
with OutputManager() as output:
parser.usage = globals()['st_%s_help' % args[0]]
+ if options['insecure']:
+ import requests
+ from requests.packages.urllib3.exceptions import \
+ InsecureRequestWarning
+ requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
try:
globals()['st_%s' % args[0]](parser, argv[1:], output)
except ClientException as err:
diff --git a/tests/unit/test_shell.py b/tests/unit/test_shell.py
index d82def6..0639ac1 100644
--- a/tests/unit/test_shell.py
+++ b/tests/unit/test_shell.py
@@ -23,7 +23,7 @@ import tempfile
import unittest
import textwrap
-
+from requests.packages.urllib3.exceptions import InsecureRequestWarning
import six
import swiftclient
@@ -1899,15 +1899,23 @@ class TestKeystoneOptions(MockHttpTest):
auth_token=token)
with mock.patch('swiftclient.client._import_keystone_client',
- _make_fake_import_keystone_client(fake_ks)):
- with mock.patch('swiftclient.client.http_connection', fake_conn):
- with mock.patch.dict(os.environ, env, clear=True):
- try:
- swiftclient.shell.main(args)
- except SystemExit as e:
- self.fail('Unexpected SystemExit: %s' % e)
- except SwiftError as err:
- self.fail('Unexpected SwiftError: %s' % err)
+ _make_fake_import_keystone_client(fake_ks)), \
+ mock.patch('swiftclient.client.http_connection', fake_conn), \
+ mock.patch.dict(os.environ, env, clear=True), \
+ mock.patch('requests.packages.urllib3.disable_warnings') as \
+ mock_disable_warnings:
+ try:
+ swiftclient.shell.main(args)
+ except SystemExit as e:
+ self.fail('Unexpected SystemExit: %s' % e)
+ except SwiftError as err:
+ self.fail('Unexpected SwiftError: %s' % err)
+
+ if 'insecure' in flags:
+ self.assertEqual([mock.call(InsecureRequestWarning)],
+ mock_disable_warnings.mock_calls)
+ else:
+ self.assertEqual([], mock_disable_warnings.mock_calls)
if no_auth:
# check that keystone client was not used and terminate tests