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
39 changes: 39 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: CI

on:
push:
branches:
- master

pull_request:
branches:
- master

jobs:
build:
runs-on: ubuntu-18.04

strategy:
matrix:
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, pypy2, pypy3]

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Test with tox
run: |
pip install "pytest" "tox>=1.9" "tox-gh-actions"
tox
2 changes: 2 additions & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
3.8.2
3.7.7
3.5.1
2.7.11
3.4.3
Expand Down
54 changes: 0 additions & 54 deletions .travis.yml

This file was deleted.

6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
1.2.2
-----
- Add API version setting
- Fix tests
- Move CI to Github Actions

1.2.1
-----
- Require pyOpenSSL>=0.15 to prevent random failures.
Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Python library for the PayPlug API
==================================

.. image:: https://travis-ci.org/payplug/payplug-python.svg?branch=master
:target: https://travis-ci.org/payplug/payplug-python
.. image:: https://github.com/payplug/payplug-python/workflows/CI/badge.svg
:target: https://github.com/payplug/payplug-python/actions
:alt: CI Status

.. image:: https://img.shields.io/pypi/v/payplug.svg?maxAge=2592000
Expand Down Expand Up @@ -61,7 +61,7 @@ To get started, add the following piece of code to the header of your Python pro

import payplug

If everything run without error, congratulations. You installed PayPlug python library! You're ready to create your
If everything runs without errors, congratulations. You installed PayPlug python library! You're ready to create your
first payment.

Usage
Expand Down
19 changes: 19 additions & 0 deletions payplug/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from datetime import datetime
from six import string_types
from payplug import config, exceptions, network, notifications, resources, routes
from payplug.network import HttpClient, UrllibRequest
Expand Down Expand Up @@ -28,6 +29,24 @@ def set_secret_key(token):

config.secret_key = token

def set_api_version(version):
"""
Specify the PayPlug API version to use.

:Example

>>> import payplug
>>> payplug.set_api_version("2019-08-06")

:param version: the desired version, as an ISO-8601 date
:type version: string
"""

if not isinstance(version, string_types) and version is not None:
raise exceptions.ConfigurationError('Expected string value for API version.')

config.api_version = version


class Payment(object):
"""
Expand Down
2 changes: 1 addition & 1 deletion payplug/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
__version__ = '1.2.1'
__version__ = '1.2.2'
1 change: 1 addition & 0 deletions payplug/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
CACERT_PATH = os.path.join(os.path.dirname(__file__), 'certs', 'cacert.pem')

secret_key = None
api_version = None
6 changes: 5 additions & 1 deletion payplug/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class HttpClient(object):
"""
HTTP Client that relies on HttpRequest to perform requests.
"""
def __init__(self, token=None, request_handler=None):
def __init__(self, token=None, request_handler=None, api_version=None):
"""
:param token: the secret key that will be used to authenticate API requests
:type token: string
Expand All @@ -173,6 +173,7 @@ def __init__(self, token=None, request_handler=None):
raise exceptions.SecretKeyNotSet('You must set your secret key using payplug.set_secret_key() function.')

self._secret_key = token or config.secret_key
self._api_version = api_version or config.api_version
self._request_handler = request_handler or available_clients[0]

def post(self, url, data=None):
Expand Down Expand Up @@ -280,6 +281,9 @@ def _request(self, http_verb, url, data=None, authenticated=True):
if authenticated:
headers['Authorization'] = 'Bearer ' + self._secret_key

if self._api_version:
headers['PayPlug-Version'] = self._api_version

requestor = self._request_handler()
response, status, _ = requestor.do_request(http_verb, url, headers, data)

Expand Down
1 change: 1 addition & 0 deletions payplug/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
class TestBase:
def setup_method(self, method):
payplug.secret_key = None
payplug.api_version = None
20 changes: 20 additions & 0 deletions payplug/test/test_init/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,23 @@ def test_secret_key_set(self):
assert config.secret_key is None
payplug.set_secret_key('a_secret_key')
assert config.secret_key == 'a_secret_key'

class TestApiVersionKey(TestBase):
def test_no_api_version(self):
import payplug
assert config.api_version is None
payplug.set_api_version(None)
assert config.api_version == None

def test_invalid_api_version(self):
import payplug
with py.test.raises(exceptions.ConfigurationError) as excinfo:
payplug.set_api_version(42)
assert 'Expected string value for API version.' == str(excinfo.value)
assert config.api_version is None

def test_secret_api_version(self):
import payplug
assert config.api_version is None
payplug.set_api_version('2019-08-06')
assert config.api_version == '2019-08-06'
1 change: 0 additions & 1 deletion payplug/test/test_init/test_dao_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def test_delete_with_card_object(self):
assert res is None


@pytest.fixture
def cards_list_fixture():
return {
"type": "list",
Expand Down
1 change: 0 additions & 1 deletion payplug/test/test_init/test_dao_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def test_delete_with_customer_object(self):
assert res is None


@pytest.fixture
def customers_list_fixture():
return {
"type": "list",
Expand Down
1 change: 0 additions & 1 deletion payplug/test/test_init/test_dao_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def test_create(self):
assert payment.id == 'pay_payment_id'


@pytest.fixture
def get_payments_fixture():
return {
"type": "list",
Expand Down
1 change: 0 additions & 1 deletion payplug/test/test_init/test_dao_refund.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def test_create_with_payment_object(self, url_mock):
assert isinstance(refund, resources.Refund)


@pytest.fixture
def get_refunds_fixture():
return {
"type": "list",
Expand Down
15 changes: 14 additions & 1 deletion payplug/test/test_network/test_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ def test_default_no_secret_key(self):
with pytest.raises(exceptions.SecretKeyNotSet):
HttpClient()

@patch('payplug.network.available_clients', [network.RequestsRequest])
@patch('payplug.config.api_version', 'an_api_version')
def test_default_api_version(self):
http_client = HttpClient()
assert http_client._api_version == 'an_api_version'

@patch('payplug.network.available_clients', [network.RequestsRequest])
@patch('payplug.config.api_version', 'an_api_version')
def test_api_version(self):
http_client = HttpClient(api_version='another_api_version')
assert http_client._api_version == 'another_api_version'

@patch('payplug.network.available_clients', [network.RequestsRequest, network.UrllibRequest])
@patch('payplug.config.secret_key', 'a_secret_key')
def test_default_request_handler(self):
Expand Down Expand Up @@ -71,14 +83,15 @@ def test_request_ok(self):
requestor.do_request.return_value = '"a valid json response"', 201, {}
request_handler = MagicMock(return_value=requestor)

http_client = HttpClient('a_secret_key', request_handler)
http_client = HttpClient('a_secret_key', request_handler, api_version='an_api_version')
response, status = http_client._request('POST', 'this_is_an_url', {'some': 'data'})

assert requestor.do_request.call_count == 1
do_request_args, _ = requestor.do_request.call_args
assert do_request_args[0] == 'POST'
assert do_request_args[1] == 'this_is_an_url'
assert do_request_args[2]['Authorization'] == 'Bearer a_secret_key'
assert do_request_args[2]['PayPlug-Version'] == 'an_api_version'
assert do_request_args[3] == {'some': 'data'}

assert response == 'a valid json response'
Expand Down
10 changes: 6 additions & 4 deletions payplug/test/test_real_http_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@


class TestRealHttpQuery(TestBase):
def test_http_query_requests(self):
http_client = HttpClient(token='a_secret_key', request_handler=RequestsRequest)
@pytest.mark.parametrize("api_version", [None, '2019-08-06'])
def test_http_query_requests(self, api_version):
http_client = HttpClient(token='a_secret_key', api_version=api_version, request_handler=RequestsRequest)
_, status = http_client._request('GET', routes.API_BASE_URL + '/test', authenticated=False)
assert status == 200

@pytest.mark.xfail(sys.version_info < (2, 7, 9), reason="Can't set ca_file easily with urllib.")
def test_http_query_urllib(self):
http_client = HttpClient(token='a_secret_key', request_handler=UrllibRequest)
@pytest.mark.parametrize("api_version", [None, '2019-08-06'])
def test_http_query_urllib(self, api_version):
http_client = HttpClient(token='a_secret_key', api_version=api_version, request_handler=UrllibRequest)
_, status = http_client._request('GET', routes.API_BASE_URL + '/test', authenticated=False)
assert status == 200
1 change: 0 additions & 1 deletion payplug/test/test_resources/test_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ def test_abort_payment(self, payment_abort_mock):
payment_abort_mock.assert_called_once_with(payment)


@pytest.fixture
def payment_fixture():
return {
"id": "pay_5iHMDxy4ABR4YBVW4UscIn",
Expand Down
1 change: 0 additions & 1 deletion payplug/test/test_resources/test_refund.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def test_initialize_refund(self):
assert refund_object.metadata['reason'] == "The delivery was delayed"


@pytest.fixture
def refund_fixture():
return {
"id": "re_5iHMDxy4ABR4YBVW4UscIn",
Expand Down
39 changes: 29 additions & 10 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
[tox]
; No support for Python 3.4+ in requests 1.x
envlist =
py{26,27,33,py,py3}-requests{10,11,12,20,21,22,23,24,25,26,27,28,29,210,211,dev},
py{34,35}-requests{20,21,22,23,24,25,26,27,28,29,210,211,dev}
py{27,py}-requests{10,11,12},
py{27,py,34,35,36,37,38,py3}-requests{20,21,22,23,24,25,26,27,28,29,210,211,212,213,214,215,216,217,218,219,220,221,222,223,dev}

[gh-actions]
python =
2.7: py27
3.4: py34
3.5: py35
3.6: py36
3.7: py37
3.8: py38
pypy2: pypy
pypy3: pypy3

[testenv]
deps =
Expand All @@ -28,12 +39,20 @@ deps =
requests29: requests>=2.9,<2.10
requests210: requests>=2.10,<2.11
requests211: requests>=2.11,<2.12
requests212: requests>=2.12,<2.13
requests213: requests>=2.13,<2.14
requests214: requests>=2.14,<2.15
requests215: requests>=2.15,<2.16
requests216: requests>=2.16,<2.17
requests217: requests>=2.17,<2.18
requests218: requests>=2.18,<2.19
requests219: requests>=2.19,<2.20
requests220: requests>=2.20,<2.21
requests221: requests>=2.21,<2.22
requests222: requests>=2.22,<2.23
requests223: requests>=2.23,<2.24
requestsdev: https://github.com/kennethreitz/requests/tarball/master
; Travis CI runs on Debian Jessie which provides outdated Pypy versions (<2.6) that are incompatible with
; cryptography >= 1.0.
; We have to force cryptography < 1.0 in this case.
; We also force pyOpenSSL < 16.0 because newer versions requires cryptography>=1.3.
; See https://github.com/travis-ci/travis-ci/issues/4756
py{py,py3}-travis: pyOpenSSL<16.0
py{py,py3}-travis: cryptography<1.0
commands=py.test {posargs}

requests213,requests214,requests215: idna>=1.0

commands=py.test {posargs}