summaryrefslogtreecommitdiff
path: root/tests/test_swiftclient.py
diff options
context:
space:
mode:
authorDarrell Bishop <darrell@swiftstack.com>2013-06-28 21:26:54 -0700
committerDarrell Bishop <darrell@swiftstack.com>2013-07-05 14:12:59 -0500
commit1d4d51b218ed14b85d1e46d3e7142fb52ea179d5 (patch)
tree1fdbf15ee1f10c10a72fc4d49d6e27addc19de89 /tests/test_swiftclient.py
parent6f7458a2903f6be2bf3271825e837d30b4e9f737 (diff)
downloadpython-swiftclient-1d4d51b218ed14b85d1e46d3e7142fb52ea179d5.tar.gz
Allow storage url override for both auth vers.
When --os-storage-url is specified on the command-line to bin/swift, it will override the used storage URL regardless of authentication for both authentication version 1 and version 2. This can be used to bypass a load-balancer to hit a specific proxy server for testing/debugging purposes. Within the client library, this feature is accessed by passing the desired storage URL into swiftclient.client.Conection.__init__() via the os_options keyword argument. For example: conn = Connection(auth_url, user, key, os_options={ 'object_storage_url': 'http://overridden.storage.url/AUTH_foo'}) This patch also adds a dependency on mock>=0.8.0, which is the same as openstack/swift. Change-Id: Id2a36ed6abffd65e7762b6beea5bbfc6c036e848
Diffstat (limited to 'tests/test_swiftclient.py')
-rw-r--r--tests/test_swiftclient.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/test_swiftclient.py b/tests/test_swiftclient.py
index 84d165b..e0fa400 100644
--- a/tests/test_swiftclient.py
+++ b/tests/test_swiftclient.py
@@ -14,6 +14,7 @@
# limitations under the License.
# TODO: More tests
+import mock
import httplib
import socket
import StringIO
@@ -123,8 +124,12 @@ class MockHttpTest(testtools.TestCase):
_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, 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)()
@@ -649,6 +654,33 @@ class TestConnection(MockHttpTest):
conn = c.Connection(**args)
self.assertEquals(type(conn), c.Connection)
+ def test_storage_url_override(self):
+ static_url = 'http://overridden.storage.url'
+ c.http_connection = self.fake_http_connection(
+ 200, body='[]', storage_url=static_url)
+ conn = c.Connection('http://auth.url/', 'some_user', 'some_key',
+ os_options={
+ 'object_storage_url': static_url})
+ method_signatures = (
+ (conn.head_account, []),
+ (conn.get_account, []),
+ (conn.head_container, ('asdf',)),
+ (conn.get_container, ('asdf',)),
+ (conn.put_container, ('asdf',)),
+ (conn.delete_container, ('asdf',)),
+ (conn.head_object, ('asdf', 'asdf')),
+ (conn.get_object, ('asdf', 'asdf')),
+ (conn.put_object, ('asdf', 'asdf', 'asdf')),
+ (conn.post_object, ('asdf', 'asdf', {})),
+ (conn.delete_object, ('asdf', 'asdf')),
+ )
+
+ with mock.patch('swiftclient.client.get_auth_1_0') as mock_get_auth:
+ mock_get_auth.return_value = ('http://auth.storage.url', 'tToken')
+
+ for method, args in method_signatures:
+ method(*args)
+
def test_retry(self):
c.http_connection = self.fake_http_connection(500)