Skip to content

fix: use httpx.RequestError as base exception for ClientConnectionError #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
python-version: [3.6, 3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
---------

1.0.8
~~~~~

* Use httpx.RequestError as base exception for ClientConnectionError.

1.0.7
~~~~~

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[tool.black]
line-length = 110
target-version = ['py37']
target-version = ['py38']
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
httpx>=0.13.3
httpx>=0.16.1
python-slugify>=4.0.0
python-status>=1.0.1
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
changelog = f.read()


install_requirements = ["python-status>=1.0.1", "httpx>=0.13.3", "python-slugify>=4.0.0"]
install_requirements = ["python-status>=1.0.1", "httpx>=0.16.1", "python-slugify>=4.0.0"]
tests_requirements = ["pytest", "pytest-asyncio", "pytest-cov", "pytest-httpserver", "coveralls"]


Expand Down
8 changes: 1 addition & 7 deletions simple_rest_client/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@
from .exceptions import AuthError, ClientConnectionError, ClientError, NotFoundError, ServerError

logger = logging.getLogger(__name__)
client_connection_exceptions = (
httpx.ConnectTimeout,
httpx.ReadTimeout,
httpx.WriteTimeout,
httpx.PoolTimeout,
httpx.NetworkError,
)
client_connection_exceptions = (httpx.RequestError,)


def validate_response(response):
Expand Down
24 changes: 20 additions & 4 deletions tests/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,35 @@ def test_validate_response_client_error(status_code, response_kwargs):

@pytest.mark.parametrize(
"side_effect",
(httpx.ConnectTimeout, httpx.ReadTimeout, httpx.WriteTimeout, httpx.PoolTimeout, httpx.NetworkError),
(
httpx.RequestError,
httpx.ConnectTimeout,
httpx.ReadTimeout,
httpx.WriteTimeout,
httpx.PoolTimeout,
httpx.NetworkError,
httpx.ProxyError,
),
)
def test_handle_request_error_exceptions(side_effect):
wrapped = mock.Mock(side_effect=side_effect)
wrapped = mock.Mock(side_effect=side_effect(message="message", request="Request"))
with pytest.raises(ClientConnectionError):
handle_request_error(wrapped)()


@pytest.mark.parametrize(
"side_effect",
(httpx.ConnectTimeout, httpx.ReadTimeout, httpx.WriteTimeout, httpx.PoolTimeout, httpx.NetworkError),
(
httpx.RequestError,
httpx.ConnectTimeout,
httpx.ReadTimeout,
httpx.WriteTimeout,
httpx.PoolTimeout,
httpx.NetworkError,
httpx.ProxyError,
),
)
def test_handle_async_request_error_exceptions(event_loop, side_effect):
wrapped = CoroutineMock(side_effect=side_effect)
wrapped = CoroutineMock(side_effect=side_effect(message="message", request="Request"))
with pytest.raises(ClientConnectionError):
event_loop.run_until_complete(handle_async_request_error(wrapped)())