summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Falcão <gabrielfalcao@users.noreply.github.com>2021-05-14 01:52:52 +0200
committerGitHub <noreply@github.com>2021-05-14 01:52:52 +0200
commitf5ca4d464e8baadad27512f3b91f702023096a54 (patch)
treebe4def49325f36ca7d16ce1d0974de9422a75593
parent85ca206cb026914258213780932674444c5c2ad6 (diff)
downloadhttpretty-f5ca4d464e8baadad27512f3b91f702023096a54.tar.gz
reproduce bug report by @akkana #413 (#423)
-rw-r--r--tests/functional/bugfixes/test_413_regex.py39
1 files changed, 39 insertions, 0 deletions
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")