summaryrefslogtreecommitdiff
path: root/tests/unit/test_swiftclient.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/test_swiftclient.py')
-rw-r--r--tests/unit/test_swiftclient.py47
1 files changed, 1 insertions, 46 deletions
diff --git a/tests/unit/test_swiftclient.py b/tests/unit/test_swiftclient.py
index facd6d9..1a5c772 100644
--- a/tests/unit/test_swiftclient.py
+++ b/tests/unit/test_swiftclient.py
@@ -30,7 +30,7 @@ from six.moves.urllib.parse import urlparse
from six.moves import reload_module
# TODO: mock http connection class with more control over headers
-from .utils import fake_http_connect, fake_get_auth_keystone
+from .utils import MockHttpTest, fake_get_auth_keystone
from swiftclient import client as c
import swiftclient.utils
@@ -103,51 +103,6 @@ class TestJsonImport(testtools.TestCase):
self.assertEqual(loads, c.json_loads)
-class MockHttpTest(testtools.TestCase):
-
- def setUp(self):
- super(MockHttpTest, self).setUp()
-
- def fake_http_connection(*args, **kwargs):
- _orig_http_connection = c.http_connection
- return_read = kwargs.get('return_read')
- query_string = kwargs.get('query_string')
- storage_url = kwargs.get('storage_url')
-
- def wrapper(url, proxy=None, cacert=None, insecure=False,
- ssl_compression=True):
- if storage_url:
- self.assertEqual(storage_url, url)
-
- parsed, _conn = _orig_http_connection(url, proxy=proxy)
- conn = fake_http_connect(*args, **kwargs)()
-
- def request(method, url, *args, **kwargs):
- if query_string:
- self.assertTrue(url.endswith('?' + query_string))
- if url.endswith('invalid_cert') and not insecure:
- from swiftclient import client as c
- raise c.ClientException("invalid_certificate")
- return
- conn.request = request
-
- conn.has_been_read = False
- _orig_read = conn.read
-
- def read(*args, **kwargs):
- conn.has_been_read = True
- return _orig_read(*args, **kwargs)
- conn.read = return_read or read
-
- return parsed, conn
- return wrapper
- self.fake_http_connection = fake_http_connection
-
- def tearDown(self):
- super(MockHttpTest, self).tearDown()
- reload_module(c)
-
-
class MockHttpResponse():
def __init__(self, status=0):
self.status = status