From 95899799da4ec8567e4d135e9feb9f6e54e8978d Mon Sep 17 00:00:00 2001 From: Michal Dulko Date: Thu, 25 Jun 2015 11:50:26 +0200 Subject: [PATCH] Add set_management_url to cinderclient.client set_management_url was used in authenticate method but wasn't defined in the HTTPClient. This commit implements missing method and adds regression unit tests. Change-Id: I605a5d1bcf6cc2dc5720820d8a8122dd17089ffa Closes-Bug: 1418580 --- cinderclient/client.py | 3 ++ cinderclient/tests/unit/test_auth_plugins.py | 30 ++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/cinderclient/client.py b/cinderclient/client.py index 142bd9587..6a1c62fdf 100644 --- a/cinderclient/client.py +++ b/cinderclient/client.py @@ -394,6 +394,9 @@ class HTTPClient(object): return self._extract_service_catalog(url, resp, body, extract_token=False) + def set_management_url(self, url): + self.management_url = url + def authenticate(self): magic_tuple = urlparse.urlsplit(self.auth_url) scheme, netloc, path, query, frag = magic_tuple diff --git a/cinderclient/tests/unit/test_auth_plugins.py b/cinderclient/tests/unit/test_auth_plugins.py index 8c41d52d1..a16981456 100644 --- a/cinderclient/tests/unit/test_auth_plugins.py +++ b/cinderclient/tests/unit/test_auth_plugins.py @@ -199,8 +199,9 @@ class DeprecatedAuthPluginTest(utils.TestCase): class AuthPluginTest(utils.TestCase): @mock.patch.object(requests, "request") @mock.patch.object(pkg_resources, "iter_entry_points") - def test_auth_system_success(self, mock_iter_entry_points, mock_request): - """Test that we can authenticate using the auth system.""" + def _test_auth_success(self, mock_iter_entry_points, mock_request, + **client_kwargs): + """Generic test that we can authenticate using the auth system.""" class MockEntrypoint(pkg_resources.EntryPoint): def load(self): return FakePlugin @@ -218,7 +219,7 @@ class AuthPluginTest(utils.TestCase): plugin = auth_plugin.load_plugin("fake") cs = client.Client("username", "password", "project_id", "auth_url/v2.0", auth_system="fake", - auth_plugin=plugin) + auth_plugin=plugin, **client_kwargs) cs.client.authenticate() headers = requested_headers(cs) @@ -232,6 +233,29 @@ class AuthPluginTest(utils.TestCase): allow_redirects=True, **self.TEST_REQUEST_BASE) + return cs.client + + def test_auth_system_success(self): + """Test that we can authenticate using the auth system.""" + c = self._test_auth_success() + self.assertIsNone(c.bypass_url) + self.assertIsNone(c.proxy_token) + + def test_auth_bypass_url(self): + """Test that we can authenticate with bypass URL.""" + c = self._test_auth_success(bypass_url='auth_url2/v2.0') + self.assertEqual('auth_url2/v2.0', c.bypass_url) + self.assertEqual('auth_url2/v2.0', c.management_url) + self.assertIsNone(c.proxy_token) + + def test_auth_bypass_url_proxy_token(self): + """Test that we can authenticate with bypass URL and proxy token.""" + c = self._test_auth_success(proxy_token='abc', + bypass_url='auth_url2/v2.0') + self.assertEqual('auth_url2/v2.0', c.bypass_url) + self.assertEqual('auth_url2/v2.0', c.management_url) + self.assertEqual('abc', c.proxy_token) + @mock.patch.object(pkg_resources, "iter_entry_points") def test_discover_auth_system_options(self, mock_iter_entry_points): """Test that we can load the auth system options."""