summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Falcão <gabriel@nacaolivre.org>2021-05-14 01:49:11 +0200
committerGabriel Falcão <gabriel@nacaolivre.org>2021-05-14 01:49:26 +0200
commitd5545104c8aad2f2272d13c11f13a030e5df61b7 (patch)
tree0e5f089e8c73f88dd103492bb7931c947fbd2962
parent6c37ff9db14caeb4099513a00f2adc5b0f2da1af (diff)
downloadhttpretty-fix/387/trailing-slash.tar.gz
-rw-r--r--httpretty/core.py2
-rw-r--r--tests/functional/bugfixes/test_387_regex_port.py26
2 files changed, 27 insertions, 1 deletions
diff --git a/httpretty/core.py b/httpretty/core.py
index f76aebe..1459e00 100644
--- a/httpretty/core.py
+++ b/httpretty/core.py
@@ -1557,7 +1557,7 @@ class httpretty(HttpBaseClass):
"""
uri_is_string = isinstance(uri, str)
- if uri_is_string and re.search(r'^\w+://[^/]+[.]\w{2,}$', uri):
+ if uri_is_string and re.search(r'^\w+://[^/]+[.]\w{2,}(:[0-9]+)?$', uri):
uri += '/'
if isinstance(responses, list) and len(responses) > 0:
diff --git a/tests/functional/bugfixes/test_387_regex_port.py b/tests/functional/bugfixes/test_387_regex_port.py
new file mode 100644
index 0000000..c3f90cd
--- /dev/null
+++ b/tests/functional/bugfixes/test_387_regex_port.py
@@ -0,0 +1,26 @@
+# based on the snippet from https://github.com/gabrielfalcao/HTTPretty/issues/387
+
+import httpretty
+import requests
+from sure import expect
+
+@httpretty.activate(allow_net_connect=False, verbose=True)
+def test_match_with_port_no_slashes():
+ "Reproduce #387 registering host:port without trailing slash"
+ httpretty.register_uri(httpretty.GET, 'http://fakeuri.com:8080', body='{"hello":"world"}')
+ req = requests.get('http://fakeuri.com:8080', timeout=1)
+ expect(req.status_code).to.equal(200)
+ expect(req.json()).to.equal({"hello": "world"})
+
+
+@httpretty.activate(allow_net_connect=False, verbose=True)
+def test_match_with_port_trailing_slash():
+ "Reproduce #387 registering host:port with trailing slash"
+ httpretty.register_uri(httpretty.GET, 'https://fakeuri.com:443/', body='{"hello":"world"}')
+ req = requests.get('https://fakeuri.com:443', timeout=1)
+ expect(req.status_code).to.equal(200)
+ expect(req.json()).to.equal({"hello": "world"})
+
+ req = requests.get('https://fakeuri.com:443/', timeout=1)
+ expect(req.status_code).to.equal(200)
+ expect(req.json()).to.equal({"hello": "world"})