diff options
author | Chmouel Boudjnah <chmouel@enovance.com> | 2014-02-21 12:59:03 +0100 |
---|---|---|
committer | Chmouel Boudjnah <chmouel@enovance.com> | 2014-03-14 17:31:10 +0100 |
commit | 24b7e7fc1a4e3486a7bd1bdc3e720c0a571ce283 (patch) | |
tree | 63e28ce7eddfa6d97a17fefcb9f537c9638d6737 | |
parent | aa30e4642a5e71b6149dfc29821d4d85da410cc9 (diff) | |
download | python-heatclient-24b7e7fc1a4e3486a7bd1bdc3e720c0a571ce283.tar.gz |
Add new tests to cover most of the requests port
After the merge to requests there was a few tests to be added to
properly cover the port and now reach 97% for coverage of
heatclient/common/http.
Change-Id: I8282459718968337f1bcd650d540509c418020c5
-rw-r--r-- | heatclient/tests/test_common_http.py | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/heatclient/tests/test_common_http.py b/heatclient/tests/test_common_http.py index e15510b..08822e7 100644 --- a/heatclient/tests/test_common_http.py +++ b/heatclient/tests/test_common_http.py @@ -225,6 +225,36 @@ class HttpClientTest(testtools.TestCase): self.assertEqual({}, body) self.m.VerifyAll() + def test_http_json_request_argument_passed_to_requests(self): + """Check that we have sent the proper arguments to requests.""" + # Record a 200 + mock_conn = http.requests.request( + 'GET', 'http://example.com:8004', + allow_redirects=False, + cert=('RANDOM_CERT_FILE', 'RANDOM_KEY_FILE'), + verify=True, + data='"text"', + headers={'Content-Type': 'application/json', + 'Accept': 'application/json', + 'X-Auth-Url': 'http://AUTH_URL', + 'User-Agent': 'python-heatclient'}) + mock_conn.AndReturn( + fakes.FakeHTTPResponse( + 200, 'OK', + {'content-type': 'application/json'}, + '{}')) + # Replay, create client, assert + self.m.ReplayAll() + client = http.HTTPClient('http://example.com:8004') + client.verify_cert = True + client.cert_file = 'RANDOM_CERT_FILE' + client.key_file = 'RANDOM_KEY_FILE' + client.auth_url = 'http://AUTH_URL' + resp, body = client.json_request('GET', '', data='text') + self.assertEqual(200, resp.status_code) + self.assertEqual({}, body) + self.m.VerifyAll() + def test_http_json_request_w_req_body(self): # Record a 200 mock_conn = http.requests.request( @@ -403,6 +433,24 @@ class HttpClientTest(testtools.TestCase): client.json_request, 'DELETE', '') self.m.VerifyAll() + def test_http_manual_redirect_error_without_location(self): + mock_conn = http.requests.request( + 'DELETE', 'http://example.com:8004/foo', + allow_redirects=False, + headers={'Content-Type': 'application/json', + 'Accept': 'application/json', + 'User-Agent': 'python-heatclient'}) + mock_conn.AndReturn( + fakes.FakeHTTPResponse( + 302, 'Found', + {}, + '')) + self.m.ReplayAll() + client = http.HTTPClient('http://example.com:8004/foo') + self.assertRaises(exc.InvalidEndpoint, + client.json_request, 'DELETE', '') + self.m.VerifyAll() + def test_http_json_request_redirect(self): # Record the 302 mock_conn = http.requests.request( @@ -503,14 +551,15 @@ class HttpClientTest(testtools.TestCase): mock_logging_debug = logging.Logger.debug( "curl -i -X GET -H 'key: value' --key TEST_KEY " "--cert TEST_CERT --cacert TEST_CA " - "-k http://foo/bar" + "-k -d 'text' http://foo/bar" ) mock_logging_debug.AndReturn(None) self.m.ReplayAll() client = http.HTTPClient('http://foo') client.ssl_connection_params = ssl_connection_params - client.log_curl_request('GET', '/bar', {'headers': headers}) + client.log_curl_request('GET', '/bar', {'headers': headers, + 'data': 'text'}) self.m.VerifyAll() |