From d8a537c7fe9b1e455831d05d9ba0ab67e03fb3a5 Mon Sep 17 00:00:00 2001 From: Kevin McDonald Date: Tue, 14 May 2013 10:31:45 -0500 Subject: [PATCH] Removes extra slash on endpoints without a path Change-Id: I5ce54117c5ac276fb9629c71eb16db88e078c947 Fixes: bug #1179984 --- glanceclient/common/http.py | 4 +++- tests/test_http.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/glanceclient/common/http.py b/glanceclient/common/http.py index f6fb4d8c..e609f8c8 100644 --- a/glanceclient/common/http.py +++ b/glanceclient/common/http.py @@ -180,7 +180,9 @@ class HTTPClient(object): kwargs['headers'] = self.encode_headers(kwargs['headers']) try: - conn_url = posixpath.normpath('%s/%s' % (self.endpoint_path, url)) + if self.endpoint_path: + url = '%s/%s' % (self.endpoint_path, url) + conn_url = posixpath.normpath(url) # Note(flaper87): Ditto, headers / url # encoding to make httplib happy. conn_url = strutils.safe_encode(conn_url) diff --git a/tests/test_http.py b/tests/test_http.py index 2d048c83..d424cee5 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -89,6 +89,27 @@ class TestClient(testtools.TestCase): encoded = self.client.encode_headers(headers) self.assertEqual(encoded["test"], "ni\xc3\xb1o") + def test_raw_request(self): + " Verify the path being used for HTTP requests reflects accurately. " + + def check_request(method, path, **kwargs): + self.assertEqual(method, 'GET') + # NOTE(kmcdonald): See bug #1179984 for more details. + self.assertEqual(path, '/v1/images/detail') + + httplib.HTTPConnection.request( + mox.IgnoreArg(), + mox.IgnoreArg(), + headers=mox.IgnoreArg()).WithSideEffects(check_request) + + # fake the response returned by httplib + fake = utils.FakeResponse({}, StringIO.StringIO('Ok')) + httplib.HTTPConnection.getresponse().AndReturn(fake) + self.mock.ReplayAll() + + resp, body = self.client.raw_request('GET', '/v1/images/detail') + self.assertEqual(resp, fake) + def test_connection_refused_raw_request(self): """ Should receive a CommunicationError if connection refused.