diff options
| author | Dean Troyer <dtroyer@gmail.com> | 2012-11-16 17:43:05 -0600 |
|---|---|---|
| committer | Dean Troyer <dtroyer@gmail.com> | 2012-12-18 15:30:43 -0600 |
| commit | 51dc6a0cef657cf9fa110da11d81d1c3f13194fa (patch) | |
| tree | 80bda5aa2974db6102a60b06ea7422e107034940 /tests/test_https.py | |
| parent | 581264757e5ac8c5313acc35e5dc94247c7a80ff (diff) | |
| download | python-keystoneclient-51dc6a0cef657cf9fa110da11d81d1c3f13194fa.tar.gz | |
Use requests module for HTTP/HTTPS
* Implement correct certificate verification
* Add requests to tools/pip-requires
* Fix OS_CACERT env var help text
* Add info to README
* Rework tests to use requests
Pinned requests module to < 1.0 as 1.0.2 is now current in pipi
as of 17Dec2012.
Change-Id: I120d2c12d6f20ebe2fd7182ec8988cc73f623b80
Diffstat (limited to 'tests/test_https.py')
| -rw-r--r-- | tests/test_https.py | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/tests/test_https.py b/tests/test_https.py index a812bca..bef1db4 100644 --- a/tests/test_https.py +++ b/tests/test_https.py @@ -1,13 +1,17 @@ -import httplib2 +import copy import mock +import requests + from keystoneclient import client from tests import utils -FAKE_RESPONSE = httplib2.Response({"status": 200}) -FAKE_BODY = '{"hi": "there"}' -MOCK_REQUEST = mock.Mock(return_value=(FAKE_RESPONSE, FAKE_BODY)) +FAKE_RESPONSE = utils.TestResponse({ + "status_code": 200, + "text": '{"hi": "there"}', +}) +MOCK_REQUEST = mock.Mock(return_value=(FAKE_RESPONSE)) def get_client(): @@ -29,26 +33,38 @@ class ClientTest(utils.TestCase): def test_get(self): cl = get_authed_client() - with mock.patch.object(httplib2.Http, "request", MOCK_REQUEST): + with mock.patch.object(requests, "request", MOCK_REQUEST): with mock.patch('time.time', mock.Mock(return_value=1234)): resp, body = cl.get("/hi") headers = {"X-Auth-Token": "token", "User-Agent": cl.USER_AGENT} - MOCK_REQUEST.assert_called_with("https://127.0.0.1:5000/hi", - "GET", headers=headers) + kwargs = copy.copy(self.TEST_REQUEST_BASE) + kwargs['cert'] = ('cert.pem', 'key.pem') + kwargs['verify'] = 'ca.pem' + MOCK_REQUEST.assert_called_with( + "GET", + "https://127.0.0.1:5000/hi", + headers=headers, + **kwargs) # Automatic JSON parsing self.assertEqual(body, {"hi": "there"}) def test_post(self): cl = get_authed_client() - with mock.patch.object(httplib2.Http, "request", MOCK_REQUEST): + with mock.patch.object(requests, "request", MOCK_REQUEST): cl.post("/hi", body=[1, 2, 3]) headers = { "X-Auth-Token": "token", "Content-Type": "application/json", "User-Agent": cl.USER_AGENT } - MOCK_REQUEST.assert_called_with("https://127.0.0.1:5000/hi", - "POST", headers=headers, - body='[1, 2, 3]') + kwargs = copy.copy(self.TEST_REQUEST_BASE) + kwargs['cert'] = ('cert.pem', 'key.pem') + kwargs['verify'] = 'ca.pem' + MOCK_REQUEST.assert_called_with( + "POST", + "https://127.0.0.1:5000/hi", + headers=headers, + data='[1, 2, 3]', + **kwargs) |
