forked from pool/python-respx
Accepting request 1230776 from devel:languages:python
Forwarded request #1230633 from bnavigator - Add patches for httpx 0.28 * respx-pr267-httpx0.28.patch gh#lundberg/respx#267 * respx-pr278-httpx0.28.patch gh#lundberg/respx#278 OBS-URL: https://build.opensuse.org/request/show/1230776 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-respx?expand=0&rev=10
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
-------------------------------------------------------------------
|
||||
Thu Dec 12 15:14:25 UTC 2024 - Ben Greiner <code@bnavigator.de>
|
||||
|
||||
- Add patches for httpx 0.28
|
||||
* respx-pr267-httpx0.28.patch gh#lundberg/respx#267
|
||||
* respx-pr278-httpx0.28.patch gh#lundberg/respx#278
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Wed May 22 17:02:32 UTC 2024 - Johannes Kastl <opensuse_buildservice@ojkastl.de>
|
||||
|
||||
|
@@ -24,17 +24,24 @@ Summary: Mock HTTPX with request patterns and response side effects
|
||||
License: BSD-3-Clause
|
||||
URL: https://github.com/lundberg/respx
|
||||
Source0: https://github.com/lundberg/respx/archive/refs/tags/%{version}.tar.gz#/respx-%{version}.tar.gz
|
||||
# PATCH-FIX-UPSTREAM respx-pr267-httpx0.28.patch gh#lundberg/respx#267
|
||||
Patch0: respx-pr267-httpx0.28.patch
|
||||
# PATCH-FIX-UPSTREAM respx-pr278-httpx0.28.patch gh#lundberg/respx#278
|
||||
Patch1: respx-pr278-httpx0.28.patch
|
||||
BuildRequires: %{python_module Flask}
|
||||
BuildRequires: %{python_module httpx}
|
||||
# >= 0.28 for tests because of the Patches
|
||||
BuildRequires: %{python_module httpx >= 0.28}
|
||||
BuildRequires: %{python_module pip}
|
||||
BuildRequires: %{python_module pytest-asyncio}
|
||||
BuildRequires: %{python_module pytest-cov}
|
||||
BuildRequires: %{python_module pytest}
|
||||
BuildRequires: %{python_module setuptools}
|
||||
BuildRequires: %{python_module starlette}
|
||||
BuildRequires: %{python_module trio}
|
||||
BuildRequires: %{python_module typing_extensions}
|
||||
BuildRequires: %{python_module wheel}
|
||||
BuildRequires: fdupes
|
||||
BuildRequires: python-rpm-macros
|
||||
Requires: python-httpx >= 0.21
|
||||
BuildArch: noarch
|
||||
%python_subpackages
|
||||
|
||||
@@ -43,21 +50,22 @@ Python library to mock httpx with request patterns and responses
|
||||
|
||||
%prep
|
||||
%autosetup -p1 -n respx-%{version}
|
||||
sed -i '/--cov/d' setup.cfg
|
||||
|
||||
%build
|
||||
%python_build
|
||||
%pyproject_wheel
|
||||
|
||||
%install
|
||||
%python_install
|
||||
%pyproject_install
|
||||
%python_expand %fdupes %{buildroot}%{$python_sitelib}
|
||||
|
||||
%check
|
||||
%pytest --asyncio-mode=auto
|
||||
%pytest -rfE
|
||||
|
||||
%files %{python_files}
|
||||
%license LICENSE.md
|
||||
%doc README.md
|
||||
%{python_sitelib}/respx-%{version}-py*.egg-info
|
||||
%{python_sitelib}/respx-%{version}.dist-info
|
||||
%{python_sitelib}/respx
|
||||
|
||||
%changelog
|
||||
|
67
respx-pr267-httpx0.28.patch
Normal file
67
respx-pr267-httpx0.28.patch
Normal file
@@ -0,0 +1,67 @@
|
||||
From 4abc14b995d5d7e3b1a593927ff9a95f9da4d097 Mon Sep 17 00:00:00 2001
|
||||
From: Jonas Lundberg <jonas@5monkeys.se>
|
||||
Date: Tue, 2 Apr 2024 20:14:16 +0200
|
||||
Subject: [PATCH] Fix test warnings
|
||||
|
||||
---
|
||||
tests/conftest.py | 6 +++---
|
||||
tests/test_mock.py | 8 +++-----
|
||||
2 files changed, 6 insertions(+), 8 deletions(-)
|
||||
|
||||
diff --git a/tests/conftest.py b/tests/conftest.py
|
||||
index 47b3fcb..02b7edf 100644
|
||||
--- a/tests/conftest.py
|
||||
+++ b/tests/conftest.py
|
||||
@@ -2,7 +2,7 @@
|
||||
import pytest
|
||||
|
||||
import respx
|
||||
-from respx.fixtures import session_event_loop as event_loop # noqa: F401
|
||||
+from respx.fixtures import session_event_loop # noqa: F401
|
||||
|
||||
pytest_plugins = ["pytester"]
|
||||
|
||||
@@ -23,7 +23,7 @@ async def my_mock():
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
-async def mocked_foo(event_loop): # noqa: F811
|
||||
+async def mocked_foo(session_event_loop): # noqa: F811
|
||||
async with respx.mock(
|
||||
base_url="https://foo.api/api/", using="httpcore"
|
||||
) as respx_mock:
|
||||
@@ -33,7 +33,7 @@ async def mocked_foo(event_loop): # noqa: F811
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
-async def mocked_ham(event_loop): # noqa: F811
|
||||
+async def mocked_ham(session_event_loop): # noqa: F811
|
||||
async with respx.mock(base_url="https://ham.api", using="httpcore") as respx_mock:
|
||||
respx_mock.get("/", name="index").respond(200)
|
||||
yield respx_mock
|
||||
diff --git a/tests/test_mock.py b/tests/test_mock.py
|
||||
index 76631b5..12b2d23 100644
|
||||
--- a/tests/test_mock.py
|
||||
+++ b/tests/test_mock.py
|
||||
@@ -473,18 +473,16 @@ def test_add_remove_targets():
|
||||
assert len(HTTPCoreMocker.targets) == pre_add_count
|
||||
|
||||
|
||||
-async def test_proxies():
|
||||
+async def test_proxy():
|
||||
with respx.mock:
|
||||
respx.get("https://foo.bar/") % dict(json={"foo": "bar"})
|
||||
- with httpx.Client(proxies={"https://": "https://1.1.1.1:1"}) as client:
|
||||
+ with httpx.Client(proxy="https://1.1.1.1:1") as client:
|
||||
response = client.get("https://foo.bar/")
|
||||
assert response.json() == {"foo": "bar"}
|
||||
|
||||
async with respx.mock:
|
||||
respx.get("https://foo.bar/") % dict(json={"foo": "bar"})
|
||||
- async with httpx.AsyncClient(
|
||||
- proxies={"https://": "https://1.1.1.1:1"}
|
||||
- ) as client:
|
||||
+ async with httpx.AsyncClient(proxy="https://1.1.1.1:1") as client:
|
||||
response = await client.get("https://foo.bar/")
|
||||
assert response.json() == {"foo": "bar"}
|
||||
|
79
respx-pr278-httpx0.28.patch
Normal file
79
respx-pr278-httpx0.28.patch
Normal file
@@ -0,0 +1,79 @@
|
||||
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"},
|
Reference in New Issue
Block a user