From 0e8fa202ed0f4329642f2c220cf5af939f59ec1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Falc=C3=A3o?= Date: Fri, 14 May 2021 01:26:50 +0200 Subject: reproduce bug report by @akkana #413 --- tests/functional/bugfixes/test_413_regex.py | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/functional/bugfixes/test_413_regex.py diff --git a/tests/functional/bugfixes/test_413_regex.py b/tests/functional/bugfixes/test_413_regex.py new file mode 100644 index 0000000..2131f7f --- /dev/null +++ b/tests/functional/bugfixes/test_413_regex.py @@ -0,0 +1,39 @@ +# File based on the snippet provided in https://github.com/gabrielfalcao/HTTPretty/issues/413#issue-787264551 +import requests +import httpretty +import re + + +def mock_body(request, url, response_headers): + return [200, response_headers, "Mocked " + url] + + +@httpretty.activate(verbose=True, allow_net_connect=False) +def test_works_with_regex_path(): + "Issue #413 regex with path" + patmatchpat = re.compile("/file-one") + + httpretty.register_uri(httpretty.GET, patmatchpat, body=mock_body) + + response = requests.get("https://example.com/file-one.html") + response.status_code.should.equal(200) + response.text.should.equal("Mocked https://example.com/file-one.html") + + response = requests.get("https://github.com/file-one.json") + response.status_code.should.equal(200) + response.text.should.equal("Mocked https://github.com/file-one.json") + +@httpretty.activate(verbose=True, allow_net_connect=False) +def test_works_with_regex_dotall(): + "Issue #413 regex with .*" + patmatchpat = re.compile(".*/file-two.*") + + httpretty.register_uri(httpretty.GET, patmatchpat, body=mock_body) + + response = requests.get("https://example.com/file-two.html") + response.status_code.should.equal(200) + response.text.should.equal("Mocked https://example.com/file-two.html") + + response = requests.get("https://github.com/file-two.json") + response.status_code.should.equal(200) + response.text.should.equal("Mocked https://github.com/file-two.json") -- cgit v1.2.1