Skip to content

Commit

Permalink
Merge 6486875 into 6cca216
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem committed Nov 2, 2021
2 parents 6cca216 + 6486875 commit c15d1b2
Show file tree
Hide file tree
Showing 20 changed files with 158 additions and 73 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
on:
push:
branches:
- master
pull_request:

name: Lint
jobs:
chore:
name: Lint and check format
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- uses: actions/setup-python@v2
with:
python-version: "3.x"

- name: Install virtualenv
run: |
pip install virtualenv
virtualenv --python=python3 .venv
- name: Print environment
run: |
source .venv/bin/activate
python --version
pip --version
- name: make lint
run: |
source .venv/bin/activate
make lint
66 changes: 66 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
on:
push:
branches:
- master
pull_request:

name: Unit Testing
jobs:
chore:
name: Unit Tests
runs-on: ubuntu-latest
strategy:
matrix:
toxenv: [py37, py38, py39, py39-master]
include:
- toxenv: py37
python-version: "3.7"
- toxenv: py38
python-version: "3.8"
- toxenv: py39
python-version: "3.9"
- toxenv: py39-master
python-version: "3.9"

steps:
- uses: actions/checkout@v2

- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install virtualenv
run: |
pip install virtualenv
virtualenv --python=python3 .venv
- name: Print environment
run: |
source .venv/bin/activate
python --version
pip --version
- name: Install dependencies
run: |
source .venv/bin/activate
pip install tox
make install-dev
- name: Use kinto @ master
if: matrix.toxenv == 'py38-master'
run: pip install --pre -U https://github.com/Kinto/kinto/tarball/master

- name: Run server
run: |
make runkinto &
sleep 5 # to give kinto migrate a chance to finish
- name: Tox
run: |
source .venv/bin/activate
tox -e ${{ matrix.toxenv }}
- name: Coveralls
uses: AndreMiras/coveralls-python-action@develop
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
34 changes: 0 additions & 34 deletions .travis.yml

This file was deleted.

7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ functional: install-dev need-kinto-running
tests: install-dev need-kinto-running
$(VENV)/bin/py.test -f kinto_http/tests/ kinto_http/tests/functional.py

flake8: install-dev
$(VENV)/bin/flake8 kinto_http

black: install-dev
format: install-dev
$(VENV)/bin/isort --profile=black --lines-after-imports=2 kinto_http
$(VENV)/bin/black kinto_http
$(VENV)/bin/flake8 kinto_http

lint: install-dev
$(VENV)/bin/therapist run --use-tracked-files kinto_http
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Kinto python client
###################

.. image:: https://img.shields.io/travis/Kinto/kinto-http.py.svg
:target: https://travis-ci.org/Kinto/kinto-http.py
.. image:: https://github.com/Kinto/kinto-http.py/actions/workflows/test.yml/badge.svg
:target: https://github.com/Kinto/kinto-http.py/actions

.. image:: https://img.shields.io/pypi/v/kinto-http.svg
:target: https://pypi.python.org/pypi/kinto-http
Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
black
flake8
isort
pytest
pytest-cache
pytest-cov
Expand Down
8 changes: 5 additions & 3 deletions kinto_http/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
from contextlib import contextmanager

import requests

from kinto_http import utils
from kinto_http.session import create_session, Session
from kinto_http.batch import BatchSession
from kinto_http.exceptions import (
BucketNotFound,
CollectionNotFound,
KintoException,
KintoBatchException,
KintoException,
)
from kinto_http.patch_type import PatchType, BasicPatch
from kinto_http.patch_type import BasicPatch, PatchType
from kinto_http.session import Session, create_session


logger = logging.getLogger("kinto_http")

Expand Down
3 changes: 2 additions & 1 deletion kinto_http/batch.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import logging
from collections import defaultdict

from kinto_http.exceptions import KintoException, KintoBatchException
from kinto_http.exceptions import KintoBatchException, KintoException

from . import utils


logger = logging.getLogger(__name__)


Expand Down
2 changes: 1 addition & 1 deletion kinto_http/cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import getpass
import logging

from . import Client, BearerTokenAuth
from . import BearerTokenAuth, Client


def get_auth(auth):
Expand Down
1 change: 1 addition & 0 deletions kinto_http/replication.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from kinto_http import Client, cli_utils


logger = logging.getLogger(__name__)


Expand Down
5 changes: 3 additions & 2 deletions kinto_http/session.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import json
import pkg_resources
import sys
import time
import warnings
from urllib.parse import urlparse

import pkg_resources
import requests

from kinto_http import utils
from kinto_http.exceptions import KintoException, BackoffException
from kinto_http.exceptions import BackoffException, KintoException


kinto_http_version = pkg_resources.get_distribution("kinto_http").version
requests_version = pkg_resources.get_distribution("requests").version
Expand Down
15 changes: 11 additions & 4 deletions kinto_http/tests/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@
import hashlib
import hmac
import os.path
import pytest
import requests
import unittest
from unittest import mock
from urllib.parse import urljoin

from kinto_http import Client, BucketNotFound, CollectionNotFound, KintoException
from kinto_http import replication
import pytest
import requests

from kinto_http import (
BucketNotFound,
Client,
CollectionNotFound,
KintoException,
replication,
)
from kinto_http.patch_type import JSONPatch


__HERE__ = os.path.abspath(os.path.dirname(__file__))

SERVER_URL = "http://localhost:8888/v1"
Expand Down
3 changes: 1 addition & 2 deletions kinto_http/tests/test_cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import unittest
from unittest import mock

from kinto_http import cli_utils
from kinto_http import BearerTokenAuth
from kinto_http import BearerTokenAuth, cli_utils


ALL_PARAMETERS = [
Expand Down
13 changes: 7 additions & 6 deletions kinto_http/tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import unittest
from unittest import mock

import pytest

from kinto_http import (
KintoException,
KintoBatchException,
BucketNotFound,
DO_NOT_OVERWRITE,
BearerTokenAuth,
BucketNotFound,
Client,
DO_NOT_OVERWRITE,
KintoBatchException,
KintoException,
)
from kinto_http.patch_type import JSONPatch, MergePatch
from kinto_http.session import create_session
from kinto_http.patch_type import MergePatch, JSONPatch

from .support import mock_response, build_response, get_http_error
from .support import build_response, get_http_error, mock_response


class ClientTest(unittest.TestCase):
Expand Down
4 changes: 3 additions & 1 deletion kinto_http/tests/test_logging.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import unittest
from unittest import mock
from .support import mock_response

from kinto_http import Client

from .support import mock_response


class BucketLoggingTest(unittest.TestCase):
def setUp(self):
Expand Down
3 changes: 1 addition & 2 deletions kinto_http/tests/test_replication.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import unittest
from unittest import mock

from kinto_http import Client, exceptions
from kinto_http.replication import replicate
from kinto_http import Client
from kinto_http import exceptions

from .support import mock_response

Expand Down
22 changes: 13 additions & 9 deletions kinto_http/tests/test_session.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import pkg_resources
import pytest
import sys
import time
import unittest
import warnings
from unittest import mock
from datetime import date, datetime
from unittest import mock

import pkg_resources
import pytest

from kinto_http.exceptions import BackoffException, KintoException
from kinto_http.session import USER_AGENT, Session, create_session

from .support import get_200, get_403, get_503, get_http_response

from kinto_http.session import Session, create_session
from kinto_http.exceptions import KintoException, BackoffException
from kinto_http.session import USER_AGENT
from .support import get_200, get_503, get_403, get_http_response

def fake_response(status_code):
response = mock.MagicMock()
Expand Down Expand Up @@ -247,7 +249,9 @@ def test_user_agent_contains_kinto_http_as_well_as_requests_and_python_versions(
def test_deprecation_warning_on_deprecated_endpoint(self):
response = fake_response(200)
response.headers = {}
response.headers['Alert'] = str({'code':'testcode', 'message':'You are deprecated','url':'http://updateme.com'})
response.headers["Alert"] = str(
{"code": "testcode", "message": "You are deprecated", "url": "http://updateme.com"}
)
self.requests_mock.request.return_value = response
session = Session("http://localhost:8888/v1")
with warnings.catch_warnings(record=True) as w:
Expand All @@ -257,6 +261,7 @@ def test_deprecation_warning_on_deprecated_endpoint(self):
assert len(w) == 1
assert issubclass(w[-1].category, DeprecationWarning)


class SessionJSONTest(unittest.TestCase):
def setUp(self):
p = mock.patch("kinto_http.session.requests")
Expand Down Expand Up @@ -442,4 +447,3 @@ def test_next_request_without_the_header_clear_the_backoff(self):
time.sleep(1) # Spend the backoff
session.request("get", "/test") # The second call reset the backoff
self.assertIsNone(session.backoff)

1 change: 1 addition & 0 deletions kinto_http/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
import unicodedata
from datetime import date, datetime

from unidecode import unidecode


Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
classifiers=[
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Internet :: WWW/HTTP",
"License :: OSI Approved :: Apache Software License",
Expand Down
Loading

0 comments on commit c15d1b2

Please sign in to comment.