Skip to content

Commit

Permalink
LITE-30282: Support pytest-httpx >=0.27.0, drop Python 3.8 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
r-s11v committed Jun 3, 2024
1 parent f8423e3 commit f12b1eb
Show file tree
Hide file tree
Showing 6 changed files with 384 additions and 478 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.9', '3.10', '3.11']
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ play with the CloudBlue Connect API using a python REPL like [jupyter](https://j

## Install

`Connect Python OpenAPI Client` requires python 3.8 or later.
`Connect Python OpenAPI Client` requires python 3.9 or later.


`Connect Python OpenAPI Client` can be installed from [pypi.org](https://pypi.org/project/connect-openapi-client/) using pip:
Expand Down
21 changes: 11 additions & 10 deletions connect/client/testing/fluent.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import responses
from pytest import MonkeyPatch
from pytest_httpx import HTTPXMock
from pytest_httpx._httpx_mock import _PytestAsyncTransport
from responses import matchers

from connect.client.fluent import _ConnectClientBase
Expand Down Expand Up @@ -176,20 +175,22 @@ def __init__(self, base_url, exclude=None):

def start(self):
patterns = self.exclude if isinstance(self.exclude, (list, tuple, set)) else [self.exclude]
real_async_transport = httpx.AsyncClient._transport_for_url
real_handle_async_request = httpx.AsyncHTTPTransport.handle_async_request

def transport_for_url(self, url):
async def mocked_handle_async_request(
transport: httpx.AsyncHTTPTransport, request: httpx.Request
) -> httpx.Response:
for pattern in patterns:
if (isinstance(pattern, re.Pattern) and pattern.match(str(url))) or (
isinstance(pattern, str) and str(url).startswith(pattern)
if (isinstance(pattern, re.Pattern) and pattern.match(str(request.url))) or (
isinstance(pattern, str) and str(request.url).startswith(pattern)
):
return real_async_transport(self, url)
return _PytestAsyncTransport(_async_mocker)
return await real_handle_async_request(transport, request)
return await _async_mocker._handle_async_request(transport, request)

_monkeypatch.setattr(
httpx.AsyncClient,
'_transport_for_url',
transport_for_url,
httpx.AsyncHTTPTransport,
"handle_async_request",
mocked_handle_async_request,
)

def reset(self, success=True):
Expand Down
Loading

0 comments on commit f12b1eb

Please sign in to comment.