From 656b80bef38db8eda148288a4cb5c9fbd3a0da4b Mon Sep 17 00:00:00 2001 From: Steven Hardy <shardy@redhat.com> Date: Tue, 23 Oct 2012 09:18:29 +0100 Subject: [PATCH] swiftclient Connection : default optional arguments to None Default the authurl/user/key constructor arguments for the Connection class to None, as these are not required in the preauthurl/preauthtoken case Change-Id: I445a5d365212c365ecc691c0a670a226e2b7954a --- swiftclient/client.py | 10 ++++++---- tests/test_swiftclient.py | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/swiftclient/client.py b/swiftclient/client.py index 2fda8ab7..896dd354 100644 --- a/swiftclient/client.py +++ b/swiftclient/client.py @@ -921,9 +921,10 @@ def delete_object(url, token=None, container=None, name=None, http_conn=None, class Connection(object): """Convenience class to make requests that will also retry the request""" - def __init__(self, authurl, user, key, retries=5, preauthurl=None, - preauthtoken=None, snet=False, starting_backoff=1, - tenant_name=None, os_options=None, auth_version="1"): + def __init__(self, authurl=None, user=None, key=None, retries=5, + preauthurl=None, preauthtoken=None, snet=False, + starting_backoff=1, tenant_name=None, os_options=None, + auth_version="1"): """ :param authurl: authentication URL :param user: user name to authenticate as @@ -931,7 +932,8 @@ class Connection(object): :param retries: Number of times to retry the request before failing :param preauthurl: storage URL (if you have already authenticated) :param preauthtoken: authentication token (if you have already - authenticated) + authenticated) note authurl/user/key/tenant_name + are not required when specifying preauthtoken :param snet: use SERVICENET internal network default is False :param auth_version: OpenStack auth version, default is 1.0 :param tenant_name: The tenant/account name, required when connecting diff --git a/tests/test_swiftclient.py b/tests/test_swiftclient.py index 80e7a22b..121456c1 100644 --- a/tests/test_swiftclient.py +++ b/tests/test_swiftclient.py @@ -407,6 +407,20 @@ class TestConnection(MockHttpTest): conn = c.Connection('http://www.test.com', 'asdf', 'asdf') self.assertEquals(conn.retries, 5) + def test_instance_kwargs(self): + args = {'user': 'ausername', + 'key': 'secretpass', + 'authurl': 'http://www.test.com', + 'tenant_name': 'atenant'} + conn = c.Connection(**args) + self.assertEquals(type(conn), c.Connection) + + def test_instance_kwargs_token(self): + args = {'preauthtoken': 'atoken123', + 'preauthurl': 'http://www.test.com:8080/v1/AUTH_123456'} + conn = c.Connection(**args) + self.assertEquals(type(conn), c.Connection) + def test_retry(self): c.http_connection = self.fake_http_connection(500)