diff options
| author | Steve Pulec <spulec@gmail.com> | 2013-03-16 19:48:58 -0400 |
|---|---|---|
| committer | Steve Pulec <spulec@gmail.com> | 2013-03-16 19:48:58 -0400 |
| commit | 4b1acaf8c8be472d79051c1f7f171d31b10ff9c8 (patch) | |
| tree | ad8ae64bed32b626f184c18a82a0fb2055784d56 | |
| parent | d3fe69469ae45ee08f865f8b9acaa11425c788e9 (diff) | |
| download | httpretty-4b1acaf8c8be472d79051c1f7f171d31b10ff9c8.tar.gz | |
Normalize urls matching for url quoting
| -rw-r--r-- | httpretty/__init__.py | 24 | ||||
| -rw-r--r-- | tests/functional/test_requests.py | 13 |
2 files changed, 33 insertions, 4 deletions
diff --git a/httpretty/__init__.py b/httpretty/__init__.py index 4b24a67..65da2fe 100644 --- a/httpretty/__init__.py +++ b/httpretty/__init__.py @@ -66,9 +66,10 @@ class Py3kObject(object): from datetime import datetime from datetime import timedelta try: - from urllib.parse import urlsplit, parse_qs + from urllib.parse import urlsplit, urlunsplit, parse_qs, quote, quote_plus except ImportError: - from urlparse import urlsplit, parse_qs + from urlparse import urlsplit, urlunsplit, parse_qs + from urllib import quote, quote_plus try: from http.server import BaseHTTPRequestHandler @@ -582,6 +583,13 @@ class Entry(Py3kObject): fk.seek(0) +def url_fix(s, charset='utf-8'): + scheme, netloc, path, querystring, fragment = urlsplit(s) + path = quote(path, '/%') + querystring = quote_plus(querystring, ':&=') + return urlunsplit((scheme, netloc, path, querystring, fragment)) + + class URIInfo(Py3kObject): def __init__(self, username='', @@ -626,8 +634,16 @@ class URIInfo(Py3kObject): return hash(text_type(self)) def __eq__(self, other): - self_tuple = (self.port, decode_utf8(self.hostname), decode_utf8(self.path)) - other_tuple = (other.port, decode_utf8(other.hostname), decode_utf8(other.path)) + self_tuple = ( + self.port, + decode_utf8(self.hostname), + url_fix(decode_utf8(self.path)), + ) + other_tuple = ( + other.port, + decode_utf8(other.hostname), + url_fix(decode_utf8(other.path)), + ) return self_tuple == other_tuple def full_url(self): diff --git a/tests/functional/test_requests.py b/tests/functional/test_requests.py index b682927..2aaa738 100644 --- a/tests/functional/test_requests.py +++ b/tests/functional/test_requests.py @@ -482,3 +482,16 @@ def test_httpretty_should_allow_multiple_responses_with_multiple_methods(): expect(requests.post(url).text).to.equal('d') expect(requests.post(url).text).to.equal('d') expect(requests.post(url).text).to.equal('d') + + +@httprettified +def test_httpretty_should_normalize_url_patching(): + u"HTTPretty should normalize all url patching" + + HTTPretty.register_uri( + HTTPretty.GET, + "http://yipit.com/foo(bar)", + body="Find the best daily deals") + + response = requests.get('http://yipit.com/foo%28bar%29') + expect(response.text).to.equal('Find the best daily deals') |
