diff options
-rw-r--r-- | swiftclient/client.py | 2 | ||||
-rw-r--r-- | tests/unit/test_swiftclient.py | 22 |
2 files changed, 21 insertions, 3 deletions
diff --git a/swiftclient/client.py b/swiftclient/client.py index f13e829..78e2cfe 100644 --- a/swiftclient/client.py +++ b/swiftclient/client.py @@ -361,7 +361,7 @@ def get_auth(auth_url, user, key, **kwargs): if kwargs.get('tenant_name'): os_options['tenant_name'] = kwargs['tenant_name'] - if ('tenant_name' not in os_options): + if not (os_options.get('tenant_name') or os_options.get('tenant_id')): raise ClientException('No tenant specified') cacert = kwargs.get('cacert', None) diff --git a/tests/unit/test_swiftclient.py b/tests/unit/test_swiftclient.py index 283400e..d473765 100644 --- a/tests/unit/test_swiftclient.py +++ b/tests/unit/test_swiftclient.py @@ -285,7 +285,7 @@ class TestGetAuth(MockHttpTest): 'asdf', 'asdf', auth_version='1.0') - def test_auth_v2(self): + def test_auth_v2_with_tenant_name(self): os_options = {'tenant_name': 'asdf'} c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(os_options) url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf', @@ -294,13 +294,31 @@ class TestGetAuth(MockHttpTest): self.assertTrue(url.startswith("http")) self.assertTrue(token) - def test_auth_v2_no_tenant_name(self): + def test_auth_v2_with_tenant_id(self): + os_options = {'tenant_id': 'asdf'} + c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(os_options) + url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf', + os_options=os_options, + auth_version="2.0") + self.assertTrue(url.startswith("http")) + self.assertTrue(token) + + def test_auth_v2_no_tenant_name_or_tenant_id(self): c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0({}) self.assertRaises(c.ClientException, c.get_auth, 'http://www.tests.com', 'asdf', 'asdf', os_options={}, auth_version='2.0') + def test_auth_v2_with_tenant_name_none_and_tenant_id_none(self): + os_options = {'tenant_name': None, + 'tenant_id': None} + c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(os_options) + self.assertRaises(c.ClientException, c.get_auth, + 'http://www.tests.com', 'asdf', 'asdf', + os_options=os_options, + auth_version='2.0') + def test_auth_v2_with_tenant_user_in_user(self): tenant_option = {'tenant_name': 'foo'} c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(tenant_option) |