summaryrefslogtreecommitdiff
path: root/tests/unit/test_swiftclient.py
diff options
context:
space:
mode:
authorAlistair Coles <alistair.coles@hp.com>2015-06-02 21:02:42 +0100
committerAlistair Coles <alistair.coles@hp.com>2015-06-03 12:03:30 +0100
commitf0cc3be2ac2cb6474ba117da323f6369c1e6c791 (patch)
treeae083b8a968177640386c4695a7f0f020d674de9 /tests/unit/test_swiftclient.py
parent49483a3b111e55405f7e522a8896225aad8473ac (diff)
downloadpython-swiftclient-f0cc3be2ac2cb6474ba117da323f6369c1e6c791.tar.gz
Make default get_auth timeout be None
Setting timeout to a default of False in get_auth() results in a requests timeout of 0.0 in keystoneclient, which causes a connection failure. This bug will cause func tests to not run when using keystoneauth. Added unit tests to verify correct default timeout is set in get_auth(). Drive-by: remove what seems like a stale TODO comment Change-Id: I17c781ce160a682b1768d315422ade0cdd2df198
Diffstat (limited to 'tests/unit/test_swiftclient.py')
-rw-r--r--tests/unit/test_swiftclient.py55
1 files changed, 53 insertions, 2 deletions
diff --git a/tests/unit/test_swiftclient.py b/tests/unit/test_swiftclient.py
index 413da81..b90d99c 100644
--- a/tests/unit/test_swiftclient.py
+++ b/tests/unit/test_swiftclient.py
@@ -200,8 +200,6 @@ class TestHttpHelpers(MockHttpTest):
ua = req_headers.get('user-agent', 'XXX-MISSING-XXX')
self.assertEqual(ua, 'a-new-default')
-# TODO: following tests are placeholders, need more tests, better coverage
-
class TestGetAuth(MockHttpTest):
@@ -239,6 +237,59 @@ class TestGetAuth(MockHttpTest):
# the full plumbing into the requests's 'verify' option
self.assertIn('invalid_certificate', str(e))
+ def test_auth_v1_timeout(self):
+ # this test has some overlap with
+ # TestConnection.test_timeout_passed_down but is required to check that
+ # get_auth does the right thing when it is not passed a timeout arg
+ orig_http_connection = c.http_connection
+ timeouts = []
+
+ def fake_request_handler(*a, **kw):
+ if 'timeout' in kw:
+ timeouts.append(kw['timeout'])
+ else:
+ timeouts.append(None)
+ return MockHttpResponse(
+ status=200,
+ headers={
+ 'x-auth-token': 'a_token',
+ 'x-storage-url': 'http://files.example.com/v1/AUTH_user'})
+
+ def fake_connection(*a, **kw):
+ url, conn = orig_http_connection(*a, **kw)
+ conn._request = fake_request_handler
+ return url, conn
+
+ with mock.patch('swiftclient.client.http_connection', fake_connection):
+ c.get_auth('http://www.test.com', 'asdf', 'asdf',
+ auth_version="1.0", timeout=42.0)
+ c.get_auth('http://www.test.com', 'asdf', 'asdf',
+ auth_version="1.0", timeout=None)
+ c.get_auth('http://www.test.com', 'asdf', 'asdf',
+ auth_version="1.0")
+
+ self.assertEqual(timeouts, [42.0, None, None])
+
+ def test_auth_v2_timeout(self):
+ # this test has some overlap with
+ # TestConnection.test_timeout_passed_down but is required to check that
+ # get_auth does the right thing when it is not passed a timeout arg
+ fake_ks = FakeKeystone(endpoint='http://some_url', token='secret')
+ with mock.patch('swiftclient.client._import_keystone_client',
+ _make_fake_import_keystone_client(fake_ks)):
+ c.get_auth('http://www.test.com', 'asdf', 'asdf',
+ os_options=dict(tenant_name='tenant'),
+ auth_version="2.0", timeout=42.0)
+ c.get_auth('http://www.test.com', 'asdf', 'asdf',
+ os_options=dict(tenant_name='tenant'),
+ auth_version="2.0", timeout=None)
+ c.get_auth('http://www.test.com', 'asdf', 'asdf',
+ os_options=dict(tenant_name='tenant'),
+ auth_version="2.0")
+ self.assertEqual(3, len(fake_ks.calls))
+ timeouts = [call['timeout'] for call in fake_ks.calls]
+ self.assertEqual([42.0, None, None], timeouts)
+
def test_auth_v2_with_tenant_name(self):
os_options = {'tenant_name': 'asdf'}
req_args = {'auth_version': '2.0'}