use urlparse.quote to catch RFC1738 issues in the mocker
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/792713e6 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/792713e6 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/792713e6 Branch: refs/heads/trunk Commit: 792713e69df6356e90de9a0680dd125fcb0f30c5 Parents: 50f47c8 Author: Anthony Shaw <anthonys...@apache.org> Authored: Thu Apr 13 11:13:14 2017 +1000 Committer: Anthony Shaw <anthonys...@apache.org> Committed: Thu Apr 13 11:13:14 2017 +1000 ---------------------------------------------------------------------- libcloud/test/__init__.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/792713e6/libcloud/test/__init__.py ---------------------------------------------------------------------- diff --git a/libcloud/test/__init__.py b/libcloud/test/__init__.py index d5c295b..6ee0da1 100644 --- a/libcloud/test/__init__.py +++ b/libcloud/test/__init__.py @@ -137,13 +137,20 @@ class MockHttp(LibcloudConnection): r_status, r_body, r_headers, r_reason = self._get_request(method, url, body, headers) if r_body is None: r_body = '' + # this is to catch any special chars e.g. ~ in the request. URL + url = urlparse.quote(url) with requests_mock.mock() as m: m.register_uri(method, url, text=r_body, reason=r_reason, headers=r_headers, status_code=r_status) - super(MockHttp, self).request( - method=method, url=url, body=body, headers=headers, - raw=raw, stream=stream) + try: + super(MockHttp, self).request( + method=method, url=url, body=body, headers=headers, + raw=raw, stream=stream) + except requests_mock.exceptions.NoMockAddress as nma: + raise AttributeError("Failed to mock out URL {0} - {1}".format( + url, nma.request.url + )) def prepared_request(self, method, url, body=None, headers=None, raw=False, stream=False):