From 49f116e98ca42423e13041947db03ba5d4ab2fb8 Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Sun, 13 Jul 2025 18:48:31 +0800 Subject: [PATCH] fix build with urllib3 >= 2.3.0 --- ...n-for-compatibility-with-urllib3-2.3.patch | 40 +++++++++++++++++ chunked_requests_handled_by_urllib3.patch | 30 +++++++++++++ python-httpretty.spec | 38 ++++++++++------ skip-test_passthrough.patch | 44 +++++++++++++++++++ 4 files changed, 139 insertions(+), 13 deletions(-) create mode 100644 Mock-socket.shutdown-for-compatibility-with-urllib3-2.3.patch create mode 100644 chunked_requests_handled_by_urllib3.patch create mode 100644 skip-test_passthrough.patch diff --git a/Mock-socket.shutdown-for-compatibility-with-urllib3-2.3.patch b/Mock-socket.shutdown-for-compatibility-with-urllib3-2.3.patch new file mode 100644 index 0000000..c559f84 --- /dev/null +++ b/Mock-socket.shutdown-for-compatibility-with-urllib3-2.3.patch @@ -0,0 +1,40 @@ +From 8e96b1e312d473429fbd08bc867376e9932ad42a Mon Sep 17 00:00:00 2001 +From: Carl Smedstad +Date: Mon, 30 Dec 2024 19:08:26 +0100 +Subject: [PATCH] Mock socket.shutdown for compatibility with urllib3 >= 2.3 + +Version 2.3.0 of urllib3 gets the attribute socket.shutdown which +HTTPretty does no mock. See the following call stack: + + /usr/lib/python3.13/site-packages/requests/sessions.py:602: in get + return self.request("GET", url, **kwargs) + /usr/lib/python3.13/site-packages/requests/sessions.py:589: in request + resp = self.send(prep, **send_kwargs) + /usr/lib/python3.13/site-packages/requests/sessions.py:703: in send + r = adapter.send(request, **kwargs) + /usr/lib/python3.13/site-packages/requests/adapters.py:667: in send + resp = conn.urlopen( + /usr/lib/python3.13/site-packages/urllib3/connectionpool.py:787: in urlopen + response = self._make_request( + /usr/lib/python3.13/site-packages/urllib3/connectionpool.py:534: in _make_request + response = conn.getresponse() + /usr/lib/python3.13/site-packages/urllib3/connection.py:513: in getresponse + _shutdown = getattr(self.sock, "shutdown", None) +--- + httpretty/core.py | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/httpretty/core.py b/httpretty/core.py +index 69686458..de7e091a 100644 +--- a/httpretty/core.py ++++ b/httpretty/core.py +@@ -861,6 +861,9 @@ def recv_into(self, *args, **kwargs): + def recvfrom(self, *args, **kwargs): + return self.forward_and_trace('recvfrom', *args, **kwargs) + ++ def shutdown(self, *args, **kwargs): ++ return self.forward_and_trace('shutdown', *args, **kwargs) ++ + def recv(self, buffersize=0, *args, **kwargs): + if not self._read_buf: + self._read_buf = io.BytesIO() diff --git a/chunked_requests_handled_by_urllib3.patch b/chunked_requests_handled_by_urllib3.patch new file mode 100644 index 0000000..2ba98de --- /dev/null +++ b/chunked_requests_handled_by_urllib3.patch @@ -0,0 +1,30 @@ +From 929cc89c2afced0c42bd08e3b9440ab1f4ec22a8 Mon Sep 17 00:00:00 2001 +From: Maja Massarini +Date: Wed, 31 Jan 2024 16:18:57 +0100 +Subject: [PATCH] Fix test failing with chunked requests handled by urllib3 + +This change (https://requests.readthedocs.io/en/latest/community/updates/#id3) +is making the test fail. +--- + tests/functional/test_requests.py | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/tests/functional/test_requests.py b/tests/functional/test_requests.py +index 55aa109..4045074 100644 +--- a/tests/functional/test_requests.py ++++ b/tests/functional/test_requests.py +@@ -678,7 +678,10 @@ def test_httpretty_should_allow_registering_regexes_with_streaming_responses(): + os.environ['DEBUG'] = 'true' + + def my_callback(request, url, headers): +- request.body.should.equal(b'hithere') ++ if requests.__version__ < "2.29": ++ request.body.should.equal(b'hithere') ++ else: ++ request.body.should.equal(b'2\r\nhi\r\n5\r\nthere\r\n') + return 200, headers, "Received" + + HTTPretty.register_uri( +-- +2.43.0 + diff --git a/python-httpretty.spec b/python-httpretty.spec index 4e35164..ac4e18c 100644 --- a/python-httpretty.spec +++ b/python-httpretty.spec @@ -1,24 +1,37 @@ Name: python-httpretty Version: 1.1.4 -Release: 7 +Release: 8 Summary: HTTP Client mocking tool for Python License: MIT URL: https://pypi.org/project/httpretty/ Source0: https://files.pythonhosted.org/packages/source/h/httpretty/httpretty-%{version}.tar.gz +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-boto3 +BuildRequires: python3-httplib2 +BuildRequires: python3-httpx +BuildRequires: python3-mock +BuildRequires: python3-pytest +BuildRequires: python3-requests +BuildRequires: python3-sure +BuildRequires: python3-urllib3 +BuildRequires: python3-tornado +BuildRequires: python3-freezegun BuildArch: noarch Patch0000: test_handle_slashes.patch Patch0001: Duplicate-requests-in-latest_requests-if-there-are-chunks.patch Patch0002: add-support-for-Misdirected-Request.patch +Patch0003: Mock-socket.shutdown-for-compatibility-with-urllib3-2.3.patch +Patch0004: skip-test_passthrough.patch +Patch0005: chunked_requests_handled_by_urllib3.patch %description HTTP Client mocking tool for Python.Provides a full fake TCP socket module. %package -n python3-httpretty Summary: HTTP Client mocking tool for Python3 -BuildRequires: python3-devel python3-setuptools python3-httplib2 python3-freezegun -BuildRequires: python3-nose2 python3-requests python3-sure python3-tornado Requires: python3-six %{?python_provide:%python_provide python3-httpretty} @@ -37,16 +50,12 @@ LANG=en_US.UTF-8 %py3_build LANG=en_US.UTF-8 %py3_install %check -# https://github.com/gabrielfalcao/HTTPretty/issues/405 -export EVENTLET_NO_GREENDNS=yes -sed -Ei 's/(test_https?_passthrough)/_\1/' tests/functional/test_passthrough.py -sed -Ei 's/(test_streaming_responses)/_\1/' tests/functional/test_requests.py -sed -Ei 's/(test_fakesock_socket_sendall_with_body_data_with_chunked_entry)/_\1/' tests/unit/test_core.py -sed -Ei 's/(test_httpretty_should_allow_registering_regexes_with_streaming_responses)/_\1/' tests/functional/test_requests.py -%if "%_arch" == "riscv64" -sed -Ei 's/two=miliseconds/ten=miliseconds/g' tests/functional/test_{urllib2,httplib2}.py -%endif -LANG=en_US.UTF-8 %{__python3} -m nose2 -v +%pytest \ + --ignore tests/bugfixes/pytest/test_426_mypy_segfault.py \ + --ignore tests/functional/test_bypass.py \ + --ignore tests/functional/test_debug.py \ + --ignore tests/bugfixes/nosetests \ + -k "not test_httpretty_should_handle_paths_starting_with_two_slashes and not test_recording_calls" %files -n python3-httpretty %doc README.rst @@ -55,6 +64,9 @@ LANG=en_US.UTF-8 %{__python3} -m nose2 -v %{python3_sitelib}/httpretty-%{version}-py%{python3_version}.egg-info %changelog +* Sun Jul 13 2025 Funda Wang - 1.1.4-8 +- fix build with urllib3 >= 2.3.0 + * Mon Nov 4 2024 laokz - 1.1.4-7 - riscv64: increase tests timeout diff --git a/skip-test_passthrough.patch b/skip-test_passthrough.patch new file mode 100644 index 0000000..35ed783 --- /dev/null +++ b/skip-test_passthrough.patch @@ -0,0 +1,44 @@ +From 683a5216502be770ad21a7dc616acdec70d77f68 Mon Sep 17 00:00:00 2001 +From: Jiri Popelka +Date: Tue, 22 Jun 2021 18:09:22 +0200 +Subject: [PATCH 2/2] Apply patch skip-test_passthrough.patch + +patch_name: skip-test_passthrough.patch +patch_id: 2 +description: |- + Remote access (these tests were skipped upstream in <= 0.9.7) +--- + tests/functional/test_passthrough.py | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/tests/functional/test_passthrough.py b/tests/functional/test_passthrough.py +index 47c9e79..7a77d23 100644 +--- a/tests/functional/test_passthrough.py ++++ b/tests/functional/test_passthrough.py +@@ -24,6 +24,7 @@ + import requests + import httpretty + ++from unittest import skip + from sure import expect + + +@@ -35,6 +36,7 @@ def http(): + return sess + + ++@skip + def test_http_passthrough(): + url = 'http://httpbin.org/status/200' + response1 = http().get(url) +@@ -57,6 +59,7 @@ def test_http_passthrough(): + (response4.content).should.equal(response1.content) + + ++@skip + def test_https_passthrough(): + url = 'https://httpbin.org/status/200' + +-- +2.31.1 + -- Gitee