Add test for timeout being passed to keystone client
Extends existing unit test for timeout being passed to get_auth to cover v2.0 auth when keystone client should get the timeout kwarg. Related-Bug: 1447847 Change-Id: Ie9cfc86fa2156b94b45d290ac12e3f71b20d6c4f
This commit is contained in:
parent
e2f41a6635
commit
a39e18ff5a
tests/unit
@ -31,7 +31,8 @@ import swiftclient.utils
|
|||||||
|
|
||||||
from os.path import basename, dirname
|
from os.path import basename, dirname
|
||||||
from tests.unit.test_swiftclient import MockHttpTest
|
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
|
from swiftclient.utils import EMPTY_ETAG
|
||||||
|
|
||||||
|
|
||||||
@ -1134,55 +1135,6 @@ class TestParsing(TestBase):
|
|||||||
self.assertTrue(out.find('--os-username=<auth-user-name>') > 0)
|
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):
|
class TestKeystoneOptions(MockHttpTest):
|
||||||
"""
|
"""
|
||||||
Tests to check that options are passed from the command line or
|
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.urllib.parse import urlparse
|
||||||
from six.moves import reload_module
|
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.utils import EMPTY_ETAG
|
||||||
from swiftclient import client as c
|
from swiftclient import client as c
|
||||||
@ -1443,6 +1444,7 @@ class TestConnection(MockHttpTest):
|
|||||||
conn._request = my_request_handler
|
conn._request = my_request_handler
|
||||||
return url, conn
|
return url, conn
|
||||||
|
|
||||||
|
# v1 auth
|
||||||
conn = c.Connection(
|
conn = c.Connection(
|
||||||
'http://auth.example.com', 'user', 'password', timeout=33.0)
|
'http://auth.example.com', 'user', 'password', timeout=33.0)
|
||||||
with mock.patch.multiple('swiftclient.client',
|
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
|
# 1 call is through get_auth, 1 call is HEAD for account
|
||||||
self.assertEqual(timeouts, [33.0, 33.0])
|
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):
|
def test_reset_stream(self):
|
||||||
|
|
||||||
class LocalContents(object):
|
class LocalContents(object):
|
||||||
|
@ -480,3 +480,52 @@ class CaptureOutput(object):
|
|||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
return getattr(self.out, 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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user