diff options
| author | Steve Pulec <spulec@gmail.com> | 2013-04-30 09:15:30 -0400 |
|---|---|---|
| committer | Steve Pulec <spulec@gmail.com> | 2013-04-30 09:15:30 -0400 |
| commit | 0d25f93bebd9c71b9cb8fae3d4bb724e0168296f (patch) | |
| tree | a3b45afda8cc3c8c6532f235d5031a4a27fed1e5 | |
| parent | 424e788aaded8ffa409d0c66cdc11d430c122c24 (diff) | |
| download | httpretty-0d25f93bebd9c71b9cb8fae3d4bb724e0168296f.tar.gz | |
regex matching should ignore querystrings
| -rw-r--r-- | httpretty/core.py | 6 | ||||
| -rw-r--r-- | tests/functional/test_requests.py | 18 | ||||
| -rw-r--r-- | tests/unit/test_httpretty.py | 4 |
3 files changed, 25 insertions, 3 deletions
diff --git a/httpretty/core.py b/httpretty/core.py index 4e04409..16510d8 100644 --- a/httpretty/core.py +++ b/httpretty/core.py @@ -527,14 +527,14 @@ class URIInfo(BaseClass): ) return self_tuple == other_tuple - def full_url(self): + def full_url(self, use_querystring=True): credentials = "" if self.password: credentials = "{0}:{1}@".format( self.username, self.password) query = "" - if self.query: + if use_querystring and self.query: query = "?{0}".format(decode_utf8(self.query)) result = "{scheme}://{credentials}{host}{path}{query}".format( @@ -580,7 +580,7 @@ class URIMatcher(object): if self.info: return self.info == info else: - return self.regex.search(info.full_url()) + return self.regex.search(info.full_url(use_querystring=False)) def __str__(self): wrap = 'URLMatcher({0})' diff --git a/tests/functional/test_requests.py b/tests/functional/test_requests.py index dcdd97f..f127540 100644 --- a/tests/functional/test_requests.py +++ b/tests/functional/test_requests.py @@ -502,6 +502,24 @@ def test_httpretty_should_allow_registering_regexes(): @httprettified +def test_httpretty_provides_easy_access_to_querystrings_with_regexes(): + u"HTTPretty should match regexes even if they have a different querystring" + + HTTPretty.register_uri( + HTTPretty.GET, + re.compile("https://api.yipit.com/v1/(?P<endpoint>\w+)/$"), + body="Find the best daily deals" + ) + + response = requests.get('https://api.yipit.com/v1/deals/?foo=bar&foo=baz&chuck=norris') + expect(response.text).to.equal("Find the best daily deals") + expect(HTTPretty.last_request.querystring).to.equal({ + 'foo': ['bar', 'baz'], + 'chuck': ['norris'], + }) + + +@httprettified def test_httpretty_should_allow_multiple_methods_for_the_same_uri(): u"HTTPretty should allow registering multiple methods for the same uri" diff --git a/tests/unit/test_httpretty.py b/tests/unit/test_httpretty.py index fd8b884..89cb50c 100644 --- a/tests/unit/test_httpretty.py +++ b/tests/unit/test_httpretty.py @@ -155,6 +155,10 @@ def test_uri_info_full_url(): "http://johhny:password@google.com/?foo=bar&baz=test" ) + expect(uri_info.full_url(use_querystring=False)).to.equal( + "http://johhny:password@google.com/" + ) + def test_global_boolean_enabled(): expect(HTTPretty.is_enabled()).to.be.falsy |
