diff options
author | Zuul <zuul@review.openstack.org> | 2018-07-24 23:12:51 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2018-07-24 23:12:51 +0000 |
commit | d80f24f2fd3f80994f109cdabe3c778b77c18472 (patch) | |
tree | 64a68875c439f1bf8912bb4c529d834e9386001b /tests/unit/test_shell.py | |
parent | 6872b95560ab77b200fde9e322af30bba99c99eb (diff) | |
parent | da362a653e9c70cb6ae17a7c3764887b4fd3fcf2 (diff) | |
download | python-swiftclient-d80f24f2fd3f80994f109cdabe3c778b77c18472.tar.gz |
Merge "Back out some version bumps"
Diffstat (limited to 'tests/unit/test_shell.py')
-rw-r--r-- | tests/unit/test_shell.py | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/tests/unit/test_shell.py b/tests/unit/test_shell.py index 8c995e5..91496b8 100644 --- a/tests/unit/test_shell.py +++ b/tests/unit/test_shell.py @@ -14,8 +14,8 @@ # limitations under the License. from __future__ import unicode_literals +import contextlib from genericpath import getmtime - import getpass import hashlib import json @@ -27,7 +27,6 @@ import unittest import textwrap from time import localtime, mktime, strftime, strptime -from requests.packages.urllib3.exceptions import InsecureRequestWarning import six import sys @@ -44,6 +43,10 @@ from swiftclient.utils import ( EMPTY_ETAG, EXPIRES_ISO8601_FORMAT, SHORT_EXPIRES_ISO8601_FORMAT, TIME_ERRMSG) +try: + from requests.packages.urllib3.exceptions import InsecureRequestWarning +except ImportError: + InsecureRequestWarning = None if six.PY2: BUILTIN_OPEN = '__builtin__.open' @@ -114,6 +117,20 @@ def _make_cmd(cmd, opts, os_opts, use_env=False, flags=None, cmd_args=None): return args, env +@contextlib.contextmanager +def patch_disable_warnings(): + if InsecureRequestWarning is None: + # If InsecureRequestWarning isn't available, disbale_warnings won't + # be either; they both came in with + # https://github.com/requests/requests/commit/811ee4e and left again + # in https://github.com/requests/requests/commit/8e17600 + yield None + else: + with mock.patch('requests.packages.urllib3.disable_warnings') \ + as patched: + yield patched + + @mock.patch.dict(os.environ, mocked_os_environ) class TestShell(unittest.TestCase): def setUp(self): @@ -2529,8 +2546,7 @@ class TestKeystoneOptions(MockHttpTest): _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: + patch_disable_warnings() as mock_disable_warnings: try: swiftclient.shell.main(args) except SystemExit as e: @@ -2538,11 +2554,12 @@ class TestKeystoneOptions(MockHttpTest): 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 InsecureRequestWarning is not None: + 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 |