diff --git a/httpretty/core.py b/httpretty/core.py index 64de381..71bdfe5 100644 --- a/httpretty/core.py +++ b/httpretty/core.py @@ -25,6 +25,7 @@ # OTHER DEALINGS IN THE SOFTWARE. from __future__ import unicode_literals +import re import inspect import socket import functools @@ -662,6 +663,11 @@ class httpretty(HttpBaseClass): status=200, responses=None, **headers): + uri_is_string = isinstance(uri, basestring) + + if uri_is_string and re.search(r'^\w+://[^/]+[.]\w{2,}$', uri): + uri += '/' + if isinstance(responses, list) and len(responses) > 0: for response in responses: response.uri = uri diff --git a/tests/functional/test_requests.py b/tests/functional/test_requests.py index 7d782d5..930ec28 100644 --- a/tests/functional/test_requests.py +++ b/tests/functional/test_requests.py @@ -617,3 +617,12 @@ def test_httpretty_should_normalize_url_patching(): response = requests.get('http://yipit.com/foo%28bar%29') expect(response.text).to.equal('Find the best daily deals') + + +@httprettified +def test_lack_of_trailing_slash(): + ("HTTPretty should automatically append a slash to given urls") + url = 'http://www.youtube.com' + HTTPretty.register_uri(HTTPretty.GET, url, body='') + response = requests.get(url) + response.status_code.should.equal(200)