From 66957806b4c18e5278f7390ed961bf5f59fb983e Mon Sep 17 00:00:00 2001 From: Colin-b Date: Thu, 21 Dec 2023 10:11:14 +0100 Subject: [PATCH] Handle httpx 0.26.0 --- .pre-commit-config.yaml | 2 +- CHANGELOG.md | 7 ++++++- README.md | 4 ++-- pytest_httpx/version.py | 2 +- setup.py | 4 ++-- tests/test_httpx_async.py | 30 ++++++++++++------------------ tests/test_httpx_sync.py | 26 ++++++++------------------ 7 files changed, 32 insertions(+), 43 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3ec3b4f..53f937b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ repos: - repo: https://github.com/psf/black - rev: 23.11.0 + rev: 23.12.0 hooks: - id: black \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 84c4b2c..612b795 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.28.0] - 2023-12-21 +### Changed +- Requires [`httpx`](https://www.python-httpx.org)==0.26.\* + ## [0.27.0] - 2023-11-13 ### Added - Explicit support for python `3.12`. @@ -297,7 +301,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - First release, should be considered as unstable for now as design might change. -[Unreleased]: https://github.com/Colin-b/pytest_httpx/compare/v0.27.0...HEAD +[Unreleased]: https://github.com/Colin-b/pytest_httpx/compare/v0.28.0...HEAD +[0.28.0]: https://github.com/Colin-b/pytest_httpx/compare/v0.27.0...v0.28.0 [0.27.0]: https://github.com/Colin-b/pytest_httpx/compare/v0.26.0...v0.27.0 [0.26.0]: https://github.com/Colin-b/pytest_httpx/compare/v0.25.0...v0.26.0 [0.25.0]: https://github.com/Colin-b/pytest_httpx/compare/v0.24.0...v0.25.0 diff --git a/README.md b/README.md index 8fc751c..f463cf2 100644 --- a/README.md +++ b/README.md @@ -160,9 +160,9 @@ from pytest_httpx import HTTPXMock def test_proxy_url(httpx_mock: HTTPXMock): - httpx_mock.add_response(proxy_url="http://test_proxy_url?a=1&b=2") + httpx_mock.add_response(proxy_url="http://test_proxy_url?b=1&a=2") - with httpx.Client(proxies={"https://": "http://test_proxy_url?a=2&b=1"}) as client: + with httpx.Client(proxy="http://test_proxy_url?a=2&b=1") as client: response = client.get("https://test_url") ``` diff --git a/pytest_httpx/version.py b/pytest_httpx/version.py index 5921900..2640171 100644 --- a/pytest_httpx/version.py +++ b/pytest_httpx/version.py @@ -3,4 +3,4 @@ # Major should be incremented in case there is a breaking change. (eg: 2.5.8 -> 3.0.0) # Minor should be incremented in case there is an enhancement. (eg: 2.5.8 -> 2.6.0) # Patch should be incremented in case there is a bug fix. (eg: 2.5.8 -> 2.5.9) -__version__ = "0.27.0" +__version__ = "0.28.0" diff --git a/setup.py b/setup.py index 5e17eea..18f0295 100644 --- a/setup.py +++ b/setup.py @@ -40,11 +40,11 @@ packages=find_packages(exclude=["tests*"]), package_data={"pytest_httpx": ["py.typed"]}, entry_points={"pytest11": ["pytest_httpx = pytest_httpx"]}, - install_requires=["httpx==0.25.*", "pytest==7.*"], + install_requires=["httpx==0.26.*", "pytest==7.*"], extras_require={ "testing": [ # Used to run async test functions - "pytest-asyncio==0.21.*", + "pytest-asyncio==0.23.*", # Used to check coverage "pytest-cov==4.*", ] diff --git a/tests/test_httpx_async.py b/tests/test_httpx_async.py index 54eb82a..89607ff 100644 --- a/tests/test_httpx_async.py +++ b/tests/test_httpx_async.py @@ -1233,12 +1233,7 @@ async def test_content_matching(httpx_mock: HTTPXMock) -> None: async def test_proxy_matching(httpx_mock: HTTPXMock) -> None: httpx_mock.add_response(proxy_url="http://user:pwd@my_other_proxy/") - async with httpx.AsyncClient( - proxies={ - "http://": "http://my_test_proxy", - "https://": "http://user:pwd@my_other_proxy", - } - ) as client: + async with httpx.AsyncClient(proxy="http://user:pwd@my_other_proxy") as client: response = await client.get("https://test_url") assert response.read() == b"" @@ -1247,12 +1242,7 @@ async def test_proxy_matching(httpx_mock: HTTPXMock) -> None: async def test_proxy_not_matching(httpx_mock: HTTPXMock) -> None: httpx_mock.add_response(proxy_url="http://my_test_proxy") - async with httpx.AsyncClient( - proxies={ - "http://": "http://my_test_proxy", - "https://": "http://user:pwd@my_other_proxy", - } - ) as client: + async with httpx.AsyncClient(proxy="http://my_test_proxy") as client: with pytest.raises(httpx.TimeoutException) as exception_info: await client.get("http://test_url") assert ( @@ -1311,9 +1301,11 @@ async def test_requests_retrieval_proxy_matching(httpx_mock: HTTPXMock) -> None: httpx_mock.add_response() async with httpx.AsyncClient( - proxies={ - "http://": "http://my_test_proxy", - "https://": "http://user:pwd@my_other_proxy", + mounts={ + "http://": httpx.AsyncHTTPTransport(proxy="http://my_test_proxy"), + "https://": httpx.AsyncHTTPTransport( + proxy="http://user:pwd@my_other_proxy" + ), } ) as client: await client.get("https://test_url") @@ -1330,9 +1322,11 @@ async def test_request_retrieval_proxy_matching(httpx_mock: HTTPXMock) -> None: httpx_mock.add_response() async with httpx.AsyncClient( - proxies={ - "http://": "http://my_test_proxy", - "https://": "http://user:pwd@my_other_proxy", + mounts={ + "http://": httpx.AsyncHTTPTransport(proxy="http://my_test_proxy"), + "https://": httpx.AsyncHTTPTransport( + proxy="http://user:pwd@my_other_proxy" + ), } ) as client: await client.get("https://test_url") diff --git a/tests/test_httpx_sync.py b/tests/test_httpx_sync.py index e1e4938..e92e2be 100644 --- a/tests/test_httpx_sync.py +++ b/tests/test_httpx_sync.py @@ -979,12 +979,7 @@ def test_content_matching(httpx_mock: HTTPXMock) -> None: def test_proxy_matching(httpx_mock: HTTPXMock) -> None: httpx_mock.add_response(proxy_url="http://user:pwd@my_other_proxy/") - with httpx.Client( - proxies={ - "http://": "http://my_test_proxy", - "https://": "http://user:pwd@my_other_proxy", - } - ) as client: + with httpx.Client(proxy="http://user:pwd@my_other_proxy") as client: response = client.get("https://test_url") assert response.read() == b"" @@ -992,12 +987,7 @@ def test_proxy_matching(httpx_mock: HTTPXMock) -> None: def test_proxy_not_matching(httpx_mock: HTTPXMock) -> None: httpx_mock.add_response(proxy_url="http://my_test_proxy") - with httpx.Client( - proxies={ - "http://": "http://my_test_proxy", - "https://": "http://user:pwd@my_other_proxy", - } - ) as client: + with httpx.Client(proxy="http://my_test_proxy") as client: with pytest.raises(httpx.TimeoutException) as exception_info: client.get("http://test_url") assert ( @@ -1052,9 +1042,9 @@ def test_requests_retrieval_proxy_matching(httpx_mock: HTTPXMock) -> None: httpx_mock.add_response() with httpx.Client( - proxies={ - "http://": "http://my_test_proxy", - "https://": "http://user:pwd@my_other_proxy", + mounts={ + "http://": httpx.HTTPTransport(proxy="http://my_test_proxy"), + "https://": httpx.HTTPTransport(proxy="http://user:pwd@my_other_proxy"), } ) as client: client.get("https://test_url") @@ -1070,9 +1060,9 @@ def test_request_retrieval_proxy_matching(httpx_mock: HTTPXMock) -> None: httpx_mock.add_response() with httpx.Client( - proxies={ - "http://": "http://my_test_proxy", - "https://": "http://user:pwd@my_other_proxy", + mounts={ + "http://": httpx.HTTPTransport(proxy="http://my_test_proxy"), + "https://": httpx.HTTPTransport(proxy="http://user:pwd@my_other_proxy"), } ) as client: client.get("https://test_url")