Merge "Add test for timeout being passed to keystone client"

This commit is contained in:
Jenkins 2015-05-21 00:44:51 +00:00 committed by Gerrit Code Review
commit 53432b5739
3 changed files with 74 additions and 51 deletions

@ -31,7 +31,8 @@ import swiftclient.utils
from os.path import basename, dirname
from tests.unit.test_swiftclient import MockHttpTest
from tests.unit.utils import CaptureOutput, fake_get_auth_keystone
from tests.unit.utils import (CaptureOutput, fake_get_auth_keystone,
_make_fake_import_keystone_client, FakeKeystone)
from swiftclient.utils import EMPTY_ETAG
@ -1134,55 +1135,6 @@ class TestParsing(TestBase):
self.assertTrue(out.find('--os-username=<auth-user-name>') > 0)
class FakeKeystone(object):
'''
Fake keystone client module. Returns given endpoint url and auth token.
'''
def __init__(self, endpoint, token):
self.calls = []
self.auth_version = None
self.endpoint = endpoint
self.token = token
class _Client():
def __init__(self, endpoint, token, **kwargs):
self.auth_token = token
self.endpoint = endpoint
self.service_catalog = self.ServiceCatalog(endpoint)
class ServiceCatalog(object):
def __init__(self, endpoint):
self.calls = []
self.endpoint_url = endpoint
def url_for(self, **kwargs):
self.calls.append(kwargs)
return self.endpoint_url
def Client(self, **kwargs):
self.calls.append(kwargs)
self.client = self._Client(endpoint=self.endpoint, token=self.token,
**kwargs)
return self.client
class Unauthorized(Exception):
pass
class AuthorizationFailure(Exception):
pass
class EndpointNotFound(Exception):
pass
def _make_fake_import_keystone_client(fake_import):
def _fake_import_keystone_client(auth_version):
fake_import.auth_version = auth_version
return fake_import, fake_import
return _fake_import_keystone_client
class TestKeystoneOptions(MockHttpTest):
"""
Tests to check that options are passed from the command line or

@ -30,7 +30,8 @@ from hashlib import md5
from six.moves.urllib.parse import urlparse
from six.moves import reload_module
from .utils import MockHttpTest, fake_get_auth_keystone, StubResponse
from .utils import (MockHttpTest, fake_get_auth_keystone, StubResponse,
FakeKeystone, _make_fake_import_keystone_client)
from swiftclient.utils import EMPTY_ETAG
from swiftclient import client as c
@ -1443,6 +1444,7 @@ class TestConnection(MockHttpTest):
conn._request = my_request_handler
return url, conn
# v1 auth
conn = c.Connection(
'http://auth.example.com', 'user', 'password', timeout=33.0)
with mock.patch.multiple('swiftclient.client',
@ -1453,6 +1455,26 @@ class TestConnection(MockHttpTest):
# 1 call is through get_auth, 1 call is HEAD for account
self.assertEqual(timeouts, [33.0, 33.0])
# v2 auth
timeouts = []
conn = c.Connection(
'http://auth.example.com', 'user', 'password', timeout=33.0,
os_options=dict(tenant_name='tenant'), auth_version=2.0)
fake_ks = FakeKeystone(endpoint='http://some_url', token='secret')
with mock.patch('swiftclient.client._import_keystone_client',
_make_fake_import_keystone_client(fake_ks)):
with mock.patch.multiple('swiftclient.client',
http_connection=shim_connection,
sleep=mock.DEFAULT):
conn.head_account()
# check timeout is passed to keystone client
self.assertEqual(1, len(fake_ks.calls))
self.assertTrue('timeout' in fake_ks.calls[0])
self.assertEqual(33.0, fake_ks.calls[0].get('timeout'))
# check timeout passed to HEAD for account
self.assertEqual(timeouts, [33.0])
def test_reset_stream(self):
class LocalContents(object):

@ -487,3 +487,52 @@ class CaptureOutput(object):
def __getattr__(self, name):
return getattr(self.out, name)
class FakeKeystone(object):
'''
Fake keystone client module. Returns given endpoint url and auth token.
'''
def __init__(self, endpoint, token):
self.calls = []
self.auth_version = None
self.endpoint = endpoint
self.token = token
class _Client():
def __init__(self, endpoint, token, **kwargs):
self.auth_token = token
self.endpoint = endpoint
self.service_catalog = self.ServiceCatalog(endpoint)
class ServiceCatalog(object):
def __init__(self, endpoint):
self.calls = []
self.endpoint_url = endpoint
def url_for(self, **kwargs):
self.calls.append(kwargs)
return self.endpoint_url
def Client(self, **kwargs):
self.calls.append(kwargs)
self.client = self._Client(endpoint=self.endpoint, token=self.token,
**kwargs)
return self.client
class Unauthorized(Exception):
pass
class AuthorizationFailure(Exception):
pass
class EndpointNotFound(Exception):
pass
def _make_fake_import_keystone_client(fake_import):
def _fake_import_keystone_client(auth_version):
fake_import.auth_version = auth_version
return fake_import, fake_import
return _fake_import_keystone_client