File respx-pr278-httpx0.28.patch of Package python-respx
From a9f81cb8dcfe5cd97f51e1a375c8406d484f31c9 Mon Sep 17 00:00:00 2001
From: Nicholas Hansen <ndhansen@leskat.net>
Date: Fri, 29 Nov 2024 14:08:23 +0000
Subject: [PATCH] Fix compatibility with httpx 0.28.0
---
respx/mocks.py | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
Index: respx-0.21.1/respx/mocks.py
===================================================================
--- respx-0.21.1.orig/respx/mocks.py
+++ respx-0.21.1/respx/mocks.py
@@ -297,6 +297,11 @@ class HTTPCoreMocker(AbstractRequestMock
Create a `HTTPX` request from transport request arg.
"""
request = kwargs["request"]
+ method = (
+ request.method.decode("ascii").upper()
+ if isinstance(request.method, bytes)
+ else request.method.upper()
+ )
raw_url = (
request.url.scheme,
request.url.host,
@@ -304,7 +309,7 @@ class HTTPCoreMocker(AbstractRequestMock
request.url.target,
)
return httpx.Request(
- request.method,
+ method,
parse_url(raw_url),
headers=request.headers,
stream=request.stream,
Index: respx-0.21.1/tests/test_api.py
===================================================================
--- respx-0.21.1.orig/tests/test_api.py
+++ respx-0.21.1/tests/test_api.py
@@ -214,7 +214,7 @@ async def test_content_variants(client,
{"X-Foo": "bar"},
{
"Content-Type": "application/json",
- "Content-Length": "14",
+ "Content-Length": "13",
"X-Foo": "bar",
},
),
@@ -223,7 +223,7 @@ async def test_content_variants(client,
{"Content-Type": "application/json; charset=utf-8", "X-Foo": "bar"},
{
"Content-Type": "application/json; charset=utf-8",
- "Content-Length": "14",
+ "Content-Length": "13",
"X-Foo": "bar",
},
),
@@ -322,19 +322,19 @@ async def test_callable_content(client):
assert request.called is True
assert async_response.status_code == 200
assert async_response.text == "hello world."
- assert request.calls[-1][0].content == b'{"x": "."}'
+ assert request.calls[-1][0].content == b'{"x":"."}'
respx_mock.reset()
sync_response = httpx.post("https://foo.bar/jonas/", json={"x": "!"})
assert request.called is True
assert sync_response.status_code == 200
assert sync_response.text == "hello jonas!"
- assert request.calls[-1][0].content == b'{"x": "!"}'
+ assert request.calls[-1][0].content == b'{"x":"!"}'
async def test_request_callback(client):
def callback(request, name):
- if request.url.host == "foo.bar" and request.content == b'{"foo": "bar"}':
+ if request.url.host == "foo.bar" and request.content == b'{"foo":"bar"}':
return respx.MockResponse(
202,
headers={"X-Foo": "bar"},