summaryrefslogtreecommitdiff
path: root/cinderclient/tests/unit/test_http.py
diff options
context:
space:
mode:
authorwangxiyuan <wangxiyuan@huawei.com>2016-11-30 14:36:16 +0800
committerwangxiyuan <wangxiyuan@huawei.com>2016-12-24 12:05:30 +0800
commite1014faed100537c4013142257d90ee24e8344c6 (patch)
tree73401a20bf2d3ebb03e00e77e0a2ef107a309c4b /cinderclient/tests/unit/test_http.py
parent4eb63b8ef278de2e82e3b4957b95ba6fd9032e4f (diff)
downloadpython-cinderclient-e1014faed100537c4013142257d90ee24e8344c6.tar.gz
Support Keystone V3 with HttpClient
The http way doesn't work with keystone v3. This patch update the HttpClient to support it. Closes-bug: #1546280 Change-Id: Iefa1aafb796609aca076ed6ab73d02c92b9198d0
Diffstat (limited to 'cinderclient/tests/unit/test_http.py')
-rw-r--r--cinderclient/tests/unit/test_http.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/cinderclient/tests/unit/test_http.py b/cinderclient/tests/unit/test_http.py
index 2a57e07..1336a03 100644
--- a/cinderclient/tests/unit/test_http.py
+++ b/cinderclient/tests/unit/test_http.py
@@ -11,6 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import json
import mock
import requests
@@ -25,6 +26,12 @@ fake_response = utils.TestResponse({
})
mock_request = mock.Mock(return_value=(fake_response))
+fake_201_response = utils.TestResponse({
+ "status_code": 201,
+ "text": '{"hi": "there"}',
+})
+mock_201_request = mock.Mock(return_value=(fake_201_response))
+
refused_response = utils.TestResponse({
"status_code": 400,
"text": '[Errno 111] Connection refused',
@@ -293,6 +300,47 @@ class ClientTest(utils.TestCase):
test_auth_call()
+ def test_auth_with_keystone_v3(self):
+ cl = get_authed_client()
+ cl.auth_url = 'http://example.com:5000/v3'
+
+ @mock.patch.object(cl, "_extract_service_catalog", mock.Mock())
+ @mock.patch.object(requests, "request", mock_201_request)
+ def test_auth_call():
+ cl.authenticate()
+ headers = {
+ "Content-Type": "application/json",
+ 'Accept': 'application/json',
+ "User-Agent": cl.USER_AGENT
+ }
+ data = {
+ "auth": {
+ "scope": {
+ "project": {
+ "domain": {"name": "Default"},
+ "name": "project_id"
+ }
+ },
+ "identity": {
+ "methods": ["password"],
+ "password": {
+ "user": {"domain": {"name": "Default"},
+ "password": "password", "name": "username"
+ }
+ }
+ }
+ }
+ }
+ mock_201_request.assert_called_with(
+ "POST",
+ "http://example.com:5000/v3/auth/tokens",
+ headers=headers,
+ allow_redirects=True,
+ data=json.dumps(data),
+ **self.TEST_REQUEST_BASE)
+
+ test_auth_call()
+
def test_get_retry_timeout_error(self):
cl = get_authed_client(retries=1)