commit python-pytest-httpx for openSUSE:Factory
Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package python-pytest-httpx for openSUSE:Factory checked in at 2023-11-20 21:19:27 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-pytest-httpx (Old) and /work/SRC/openSUSE:Factory/.python-pytest-httpx.new.2521 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "python-pytest-httpx" Mon Nov 20 21:19:27 2023 rev:8 rq:1127546 version:0.27.0 Changes: -------- --- /work/SRC/openSUSE:Factory/python-pytest-httpx/python-pytest-httpx.changes 2023-11-08 22:18:18.116438470 +0100 +++ /work/SRC/openSUSE:Factory/.python-pytest-httpx.new.2521/python-pytest-httpx.changes 2023-11-20 21:20:04.683974438 +0100 @@ -1,0 +2,11 @@ +Sun Nov 19 10:48:03 UTC 2023 - Dirk Müller <dmueller@suse.com> + +- update to 0.27.0: + * Explicit support for python `3.12`. + * Custom HTTP transport are now handled (parent call to + `handle_async_request` or `handle_request`). + * Only HTTP transport are now mocked, this should not have any + impact, however if it does, please feel free to open an issue + describing your use case. + +------------------------------------------------------------------- Old: ---- pytest_httpx-0.26.0-gh.tar.gz New: ---- pytest_httpx-0.27.0-gh.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-pytest-httpx.spec ++++++ --- /var/tmp/diff_new_pack.xVURGk/_old 2023-11-20 21:20:06.052024928 +0100 +++ /var/tmp/diff_new_pack.xVURGk/_new 2023-11-20 21:20:06.052024928 +0100 @@ -18,7 +18,7 @@ %{?sle15_python_module_pythons} Name: python-pytest-httpx -Version: 0.26.0 +Version: 0.27.0 Release: 0 Summary: Send responses to httpx License: MIT ++++++ pytest_httpx-0.26.0-gh.tar.gz -> pytest_httpx-0.27.0-gh.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest_httpx-0.26.0/.github/workflows/release.yml new/pytest_httpx-0.27.0/.github/workflows/release.yml --- old/pytest_httpx-0.26.0/.github/workflows/release.yml 2023-09-18 19:23:33.000000000 +0200 +++ new/pytest_httpx-0.27.0/.github/workflows/release.yml 2023-11-13 20:26:49.000000000 +0100 @@ -11,7 +11,7 @@ runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.9', '3.10', '3.11'] + python-version: ['3.9', '3.10', '3.11', '3.12'] steps: - uses: actions/checkout@v4 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest_httpx-0.26.0/.github/workflows/test.yml new/pytest_httpx-0.27.0/.github/workflows/test.yml --- old/pytest_httpx-0.26.0/.github/workflows/test.yml 2023-09-18 19:23:33.000000000 +0200 +++ new/pytest_httpx-0.27.0/.github/workflows/test.yml 2023-11-13 20:26:49.000000000 +0100 @@ -8,7 +8,7 @@ runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.9', '3.10', '3.11'] + python-version: ['3.9', '3.10', '3.11', '3.12'] steps: - uses: actions/checkout@v4 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest_httpx-0.26.0/.pre-commit-config.yaml new/pytest_httpx-0.27.0/.pre-commit-config.yaml --- old/pytest_httpx-0.26.0/.pre-commit-config.yaml 2023-09-18 19:23:33.000000000 +0200 +++ new/pytest_httpx-0.27.0/.pre-commit-config.yaml 2023-11-13 20:26:49.000000000 +0100 @@ -1,5 +1,5 @@ repos: - repo: https://github.com/psf/black - rev: 23.7.0 + rev: 23.11.0 hooks: - id: black \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest_httpx-0.26.0/CHANGELOG.md new/pytest_httpx-0.27.0/CHANGELOG.md --- old/pytest_httpx-0.26.0/CHANGELOG.md 2023-09-18 19:23:33.000000000 +0200 +++ new/pytest_httpx-0.27.0/CHANGELOG.md 2023-11-13 20:26:49.000000000 +0100 @@ -6,6 +6,16 @@ ## [Unreleased] +## [0.27.0] - 2023-11-13 +### Added +- Explicit support for python `3.12`. + +### Fixed +- Custom HTTP transport are now handled (parent call to `handle_async_request` or `handle_request`). + +### Changed +- Only HTTP transport are now mocked, this should not have any impact, however if it does, please feel free to open an issue describing your use case. + ## [0.26.0] - 2023-09-18 ### Added - Added `proxy_url` parameter which allows matching on proxy URL. @@ -287,7 +297,8 @@ ### Added - First release, should be considered as unstable for now as design might change. -[Unreleased]: https://github.com/Colin-b/pytest_httpx/compare/v0.26.0...HEAD +[Unreleased]: https://github.com/Colin-b/pytest_httpx/compare/v0.27.0...HEAD +[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 [0.24.0]: https://github.com/Colin-b/pytest_httpx/compare/v0.23.1...v0.24.0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest_httpx-0.26.0/README.md new/pytest_httpx-0.27.0/README.md --- old/pytest_httpx-0.26.0/README.md 2023-09-18 19:23:33.000000000 +0200 +++ new/pytest_httpx-0.27.0/README.md 2023-11-13 20:26:49.000000000 +0100 @@ -5,7 +5,7 @@ <a href="https://github.com/Colin-b/pytest_httpx/actions"><img alt="Build status" src="https://github.com/Colin-b/pytest_httpx/workflows/Release/badge.svg"></a> <a href="https://github.com/Colin-b/pytest_httpx/actions"><img alt="Coverage" src="https://img.shields.io/badge/coverage-100%25-brightgreen"></a> <a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a> -<a href="https://github.com/Colin-b/pytest_httpx/actions"><img alt="Number of tests" src="https://img.shields.io/badge/tests-206 passed-blue"></a> +<a href="https://github.com/Colin-b/pytest_httpx/actions"><img alt="Number of tests" src="https://img.shields.io/badge/tests-208 passed-blue"></a> <a href="https://pypi.org/project/pytest-httpx/"><img alt="Number of downloads" src="https://img.shields.io/pypi/dm/pytest_httpx"></a> </p> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest_httpx-0.26.0/pytest_httpx/__init__.py new/pytest_httpx-0.27.0/pytest_httpx/__init__.py --- old/pytest_httpx-0.26.0/pytest_httpx/__init__.py 2023-09-18 19:23:33.000000000 +0200 +++ new/pytest_httpx-0.27.0/pytest_httpx/__init__.py 2023-11-13 20:26:49.000000000 +0100 @@ -5,11 +5,7 @@ import pytest from pytest import MonkeyPatch -from pytest_httpx._httpx_mock import ( - HTTPXMock, - _PytestSyncTransport, - _PytestAsyncTransport, -) +from pytest_httpx._httpx_mock import HTTPXMock from pytest_httpx._httpx_internals import IteratorStream from pytest_httpx.version import __version__ @@ -45,22 +41,36 @@ mock = HTTPXMock() # Mock synchronous requests - real_sync_transport = httpx.Client._transport_for_url + real_handle_request = httpx.HTTPTransport.handle_request + + def mocked_handle_request( + transport: httpx.HTTPTransport, request: httpx.Request + ) -> httpx.Response: + if request.url.host in non_mocked_hosts: + return real_handle_request(transport, request) + return mock._handle_request(transport, request) + monkeypatch.setattr( - httpx.Client, - "_transport_for_url", - lambda self, url: real_sync_transport(self, url) - if url.host in non_mocked_hosts - else _PytestSyncTransport(real_sync_transport(self, url), mock), + httpx.HTTPTransport, + "handle_request", + mocked_handle_request, ) + # Mock asynchronous requests - real_async_transport = httpx.AsyncClient._transport_for_url + real_handle_async_request = httpx.AsyncHTTPTransport.handle_async_request + + async def mocked_handle_async_request( + transport: httpx.AsyncHTTPTransport, request: httpx.Request + ) -> httpx.Response: + if request.url.host in non_mocked_hosts: + return await real_handle_async_request(transport, request) + return await mock._handle_async_request(transport, request) + monkeypatch.setattr( - httpx.AsyncClient, - "_transport_for_url", - lambda self, url: real_async_transport(self, url) - if url.host in non_mocked_hosts - else _PytestAsyncTransport(real_async_transport(self, url), mock), + httpx.AsyncHTTPTransport, + "handle_async_request", + mocked_handle_async_request, ) + yield mock mock.reset(assert_all_responses_were_requested) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest_httpx-0.26.0/pytest_httpx/_httpx_internals.py new/pytest_httpx-0.27.0/pytest_httpx/_httpx_internals.py --- old/pytest_httpx-0.26.0/pytest_httpx/_httpx_internals.py 2023-09-18 19:23:33.000000000 +0200 +++ new/pytest_httpx-0.27.0/pytest_httpx/_httpx_internals.py 2023-11-13 20:26:49.000000000 +0100 @@ -61,12 +61,9 @@ def _proxy_url( - real_transport: Union[httpx.BaseTransport, httpx.AsyncBaseTransport] + real_transport: Union[httpx.HTTPTransport, httpx.AsyncHTTPTransport] ) -> Optional[httpx.URL]: - if isinstance(real_transport, httpx.HTTPTransport): - if isinstance(real_pool := real_transport._pool, httpcore.HTTPProxy): - return _to_httpx_url(real_pool._proxy_url, real_pool._proxy_headers) - - if isinstance(real_transport, httpx.AsyncHTTPTransport): - if isinstance(real_pool := real_transport._pool, httpcore.AsyncHTTPProxy): - return _to_httpx_url(real_pool._proxy_url, real_pool._proxy_headers) + if isinstance( + real_pool := real_transport._pool, (httpcore.HTTPProxy, httpcore.AsyncHTTPProxy) + ): + return _to_httpx_url(real_pool._proxy_url, real_pool._proxy_headers) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest_httpx-0.26.0/pytest_httpx/_httpx_mock.py new/pytest_httpx-0.27.0/pytest_httpx/_httpx_mock.py --- old/pytest_httpx-0.26.0/pytest_httpx/_httpx_mock.py 2023-09-18 19:23:33.000000000 +0200 +++ new/pytest_httpx-0.27.0/pytest_httpx/_httpx_mock.py 2023-11-13 20:26:49.000000000 +0100 @@ -12,7 +12,7 @@ class HTTPXMock: def __init__(self) -> None: self._requests: list[ - tuple[Union[httpx.BaseTransport, httpx.AsyncBaseTransport], httpx.Request] + tuple[Union[httpx.HTTPTransport, httpx.AsyncHTTPTransport], httpx.Request] ] = [] self._callbacks: list[ tuple[ @@ -123,7 +123,7 @@ def _handle_request( self, - real_transport: httpx.BaseTransport, + real_transport: httpx.HTTPTransport, request: httpx.Request, ) -> httpx.Response: self._requests.append((real_transport, request)) @@ -142,7 +142,7 @@ async def _handle_async_request( self, - real_transport: httpx.AsyncBaseTransport, + real_transport: httpx.AsyncHTTPTransport, request: httpx.Request, ) -> httpx.Response: self._requests.append((real_transport, request)) @@ -178,7 +178,7 @@ def _get_callback( self, - real_transport: Union[httpx.BaseTransport, httpx.AsyncBaseTransport], + real_transport: Union[httpx.HTTPTransport, httpx.AsyncHTTPTransport], request: httpx.Request, ) -> Optional[ Callable[ @@ -266,24 +266,6 @@ return callbacks_not_executed -class _PytestSyncTransport(httpx.BaseTransport): - def __init__(self, real_transport: httpx.BaseTransport, mock: HTTPXMock): - self._real_transport = real_transport - self._mock = mock - - def handle_request(self, request: httpx.Request) -> httpx.Response: - return self._mock._handle_request(self._real_transport, request) - - -class _PytestAsyncTransport(httpx.AsyncBaseTransport): - def __init__(self, real_transport: httpx.AsyncBaseTransport, mock: HTTPXMock): - self._real_transport = real_transport - self._mock = mock - - async def handle_async_request(self, request: httpx.Request) -> httpx.Response: - return await self._mock._handle_async_request(self._real_transport, request) - - def _unread(response: httpx.Response) -> httpx.Response: # Allow to read the response on client side response.is_stream_consumed = False diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest_httpx-0.26.0/pytest_httpx/_request_matcher.py new/pytest_httpx-0.27.0/pytest_httpx/_request_matcher.py --- old/pytest_httpx-0.26.0/pytest_httpx/_request_matcher.py 2023-09-18 19:23:33.000000000 +0200 +++ new/pytest_httpx-0.27.0/pytest_httpx/_request_matcher.py 2023-11-13 20:26:49.000000000 +0100 @@ -52,7 +52,7 @@ def match( self, - real_transport: Union[httpx.BaseTransport, httpx.AsyncBaseTransport], + real_transport: Union[httpx.HTTPTransport, httpx.AsyncHTTPTransport], request: httpx.Request, ) -> bool: return ( @@ -106,7 +106,7 @@ return False def _proxy_match( - self, real_transport: Union[httpx.BaseTransport, httpx.AsyncBaseTransport] + self, real_transport: Union[httpx.HTTPTransport, httpx.AsyncHTTPTransport] ) -> bool: if not self.proxy_url: return True diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest_httpx-0.26.0/pytest_httpx/version.py new/pytest_httpx-0.27.0/pytest_httpx/version.py --- old/pytest_httpx-0.26.0/pytest_httpx/version.py 2023-09-18 19:23:33.000000000 +0200 +++ new/pytest_httpx-0.27.0/pytest_httpx/version.py 2023-11-13 20:26:49.000000000 +0100 @@ -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.26.0" +__version__ = "0.27.0" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest_httpx-0.26.0/setup.py new/pytest_httpx-0.27.0/setup.py --- old/pytest_httpx-0.26.0/setup.py 2023-09-18 19:23:33.000000000 +0200 +++ new/pytest_httpx-0.27.0/setup.py 2023-11-13 20:26:49.000000000 +0100 @@ -31,6 +31,7 @@ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Topic :: Software Development :: Build Tools", "Topic :: Internet :: WWW/HTTP", "Framework :: Pytest", diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest_httpx-0.26.0/tests/test_httpx_async.py new/pytest_httpx-0.27.0/tests/test_httpx_async.py --- old/pytest_httpx-0.26.0/tests/test_httpx_async.py 2023-09-18 19:23:33.000000000 +0200 +++ new/pytest_httpx-0.27.0/tests/test_httpx_async.py 2023-11-13 20:26:49.000000000 +0100 @@ -2015,3 +2015,26 @@ tasks = [client.get("https://example.com/") for _ in range(950)] await asyncio.gather(*tasks) # No need to assert anything, this test case ensure that no error was raised by the gather + + +@pytest.mark.asyncio +async def test_custom_transport(httpx_mock: HTTPXMock) -> None: + class CustomTransport(httpx.AsyncHTTPTransport): + def __init__(self, prefix: str, *args, **kwargs): + super().__init__(*args, **kwargs) + self.prefix = prefix + + async def handle_async_request( + self, + request: httpx.Request, + ) -> httpx.Response: + httpx_response = await super().handle_async_request(request) + httpx_response.headers["x-prefix"] = self.prefix + return httpx_response + + httpx_mock.add_response() + + async with httpx.AsyncClient(transport=CustomTransport(prefix="test")) as client: + response = await client.post("https://test_url", content=b"This is the body") + assert response.read() == b"" + assert response.headers["x-prefix"] == "test" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest_httpx-0.26.0/tests/test_httpx_sync.py new/pytest_httpx-0.27.0/tests/test_httpx_sync.py --- old/pytest_httpx-0.26.0/tests/test_httpx_sync.py 2023-09-18 19:23:33.000000000 +0200 +++ new/pytest_httpx-0.27.0/tests/test_httpx_sync.py 2023-11-13 20:26:49.000000000 +0100 @@ -1,5 +1,4 @@ import re -from typing import Any from unittest.mock import ANY import httpx @@ -1706,3 +1705,25 @@ response = client.get("https://test_url") assert response.json() == {"content": "request 2"} + + +def test_custom_transport(httpx_mock: HTTPXMock) -> None: + class CustomTransport(httpx.HTTPTransport): + def __init__(self, prefix: str, *args, **kwargs): + super().__init__(*args, **kwargs) + self.prefix = prefix + + def handle_request( + self, + request: httpx.Request, + ) -> httpx.Response: + httpx_response = super().handle_request(request) + httpx_response.headers["x-prefix"] = self.prefix + return httpx_response + + httpx_mock.add_response() + + with httpx.Client(transport=CustomTransport(prefix="test")) as client: + response = client.post("https://test_url", content=b"This is the body") + assert response.read() == b"" + assert response.headers["x-prefix"] == "test"
participants (1)
-
Source-Sync