Skip to content
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
35 changes: 16 additions & 19 deletions .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,24 @@ on: [push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: ['3.7', '3.8', '3.9', '3.10']

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- name: Lint
run: |
make lint
- name: Test with pytest
run: |
pytest --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- name: pre-commit lint
run: make lint
- name: pytest
run: pytest --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ ENV/
.ropeproject

.DS_Store
.vscode/
.vscode/
46 changes: 26 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
repos:
- repo: local
hooks:
- id: black
name: black
entry: black
language: system
types: [python]
args: ['--diff']
- id: isort
name: isort
entry: isort
language: system
types: [python]
args: ['--check-only']
- id: flake8
name: flake8
entry: flake8
language: system
types: [python]
args: ['--ignore=E501,W503']
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://gitlab.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
args: ["--ignore=E501"]
- repo: https://github.com/pycqa/isort
rev: 5.9.3
hooks:
- id: isort
name: isort (python)
- id: isort
name: isort (cython)
types: [cython]
- id: isort
name: isort (pyi)
types: [pyi]
- repo: https://github.com/psf/black
rev: 21.9b0
hooks:
- id: black
9 changes: 9 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Changelog
---------

1.1.0
~~~~~

* Drop support for python 3.6.x.
* Fix json_encode_body cannot be overridden bug (thanks @denravonska).
* Replace asynctest with asyncmock.
* Update httpx and python-slugify to latest versions.
* Update pre-commit rules.

1.0.8
~~~~~

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Simple Rest Client

----

Simple REST client for python 3.6+.
Simple REST client for python 3.7+.


How to install
Expand Down
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ help:
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Welcome to python-simple-rest-client's documentation!
=====================================================

Simple REST client for python 3.6+, supports sync (with requests) and asyncio (with aiohttp) requests
Simple REST client for python 3.7+, supports sync and asyncio (with httpx) requests


Contents
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Install the latest stable release via pip::

pip install simple-rest-client

python-simple-rest-client runs with `Python 3.6+ <https://travis-ci.org/allisson/python-simple-rest-client>`_ .
python-simple-rest-client runs with `Python 3.7+ <https://travis-ci.org/allisson/python-simple-rest-client>`_ .
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[tool.black]
line-length = 110
target-version = ['py38']
target-version = ['py39']

[tool.isort]
profile = 'black'
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[pytest]
addopts = -vvv --cov=simple_rest_client --cov-report=term-missing
addopts = -vvv --cov=simple_rest_client --cov-report=term-missing
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-r requirements.txt
Sphinx
asynctest
asyncmock
black
codecov
flake8
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
httpx>=0.16.1
python-slugify>=4.0.0
httpx>=0.19.0
python-slugify>=5.0.2
python-status>=1.0.1
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ multi_line_output=3
include_trailing_comma=True
known_localfolder=simple_rest_client,tests
sections=FUTURE,STDLIB,THIRDPARTY,LOCALFOLDER
default_section=THIRDPARTY
default_section=THIRDPARTY
7 changes: 4 additions & 3 deletions 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.16.1", "python-slugify>=4.0.0"]
install_requirements = ["python-status>=1.0.1", "httpx>=0.19.0", "python-slugify>=5.0.2"]
tests_requirements = ["pytest", "pytest-asyncio", "pytest-cov", "pytest-httpserver", "coveralls"]


Expand Down Expand Up @@ -54,12 +54,13 @@ def run(self):
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Software Development :: Libraries",
],
keywords="rest client http asyncio",
keywords="rest client http httpx asyncio",
packages=find_packages(exclude=["docs", "tests*"]),
setup_requires=["pytest-runner"],
install_requires=install_requirements,
Expand Down
19 changes: 10 additions & 9 deletions simple_rest_client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,21 @@ def add_resource(
params=None,
headers=None,
timeout=None,
append_slash=False,
json_encode_body=False,
append_slash=None,
json_encode_body=None,
ssl_verify=None,
):
resource_valid_name = self.correct_attribute_name(resource_name)
resource_class = resource_class or Resource
resource = resource_class(
api_root_url=api_root_url or self.api_root_url,
api_root_url=api_root_url if api_root_url is not None else self.api_root_url,
resource_name=resource_valid_name,
params=params or self.params,
headers=headers or self.headers,
timeout=timeout or self.timeout,
append_slash=append_slash or self.append_slash,
json_encode_body=json_encode_body or self.json_encode_body,
ssl_verify=self.ssl_verify,
params=params if params is not None else self.params,
headers=headers if headers is not None else self.headers,
timeout=timeout if timeout is not None else self.timeout,
append_slash=append_slash if append_slash is not None else self.append_slash,
json_encode_body=json_encode_body if json_encode_body is not None else self.json_encode_body,
ssl_verify=ssl_verify if ssl_verify is not None else self.ssl_verify,
)
self._resources[resource_valid_name] = resource
setattr(self, resource_valid_name, resource)
Expand Down
8 changes: 7 additions & 1 deletion simple_rest_client/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
import httpx
import status

from .exceptions import AuthError, ClientConnectionError, ClientError, NotFoundError, ServerError
from .exceptions import (
AuthError,
ClientConnectionError,
ClientError,
NotFoundError,
ServerError,
)

logger = logging.getLogger(__name__)
client_connection_exceptions = (httpx.RequestError,)
Expand Down
10 changes: 7 additions & 3 deletions tests/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import httpx
import pytest
import status
from asynctest.mock import CoroutineMock
from asyncmock import AsyncMock

from simple_rest_client.decorators import handle_async_request_error, handle_request_error, validate_response
from simple_rest_client.decorators import (
handle_async_request_error,
handle_request_error,
validate_response,
)
from simple_rest_client.exceptions import (
AuthError,
ClientConnectionError,
Expand Down Expand Up @@ -83,6 +87,6 @@ def test_handle_request_error_exceptions(side_effect):
),
)
def test_handle_async_request_error_exceptions(event_loop, side_effect):
wrapped = CoroutineMock(side_effect=side_effect(message="message", request="Request"))
wrapped = AsyncMock(side_effect=side_effect(message="message", request="Request"))
with pytest.raises(ClientConnectionError):
event_loop.run_until_complete(handle_async_request_error(wrapped)())