diff --git a/eopayment/__init__.py b/eopayment/__init__.py index e7d0d38..4b964d9 100644 --- a/eopayment/__init__.py +++ b/eopayment/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # eopayment - online payment library # Copyright (C) 2011-2020 Entr'ouvert # @@ -64,10 +63,10 @@ def get_backends(): 'Dummy payment backend' ''' - return dict((backend, get_backend(backend)) for backend in __BACKENDS) + return {backend: get_backend(backend) for backend in __BACKENDS} -class Payment(object): +class Payment: ''' Interface to credit card online payment servers of French banks. The only use case supported for now is a unique automatic payment. @@ -132,7 +131,7 @@ class Payment(object): - the third is the URL or the HTML form to contact the payment server, which must be sent to the customer browser. ''' - logger.debug(u'%r' % kwargs) + logger.debug('%r' % kwargs) if 'capture_date' in kwargs: capture_date = kwargs.pop('capture_date') diff --git a/eopayment/__main__.py b/eopayment/__main__.py index 06e72ba..077fb61 100644 --- a/eopayment/__main__.py +++ b/eopayment/__main__.py @@ -14,7 +14,6 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from __future__ import print_function import configparser import decimal diff --git a/eopayment/cb.py b/eopayment/cb.py index 6ab828d..d409394 100644 --- a/eopayment/cb.py +++ b/eopayment/cb.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # eopayment - online payment library # Copyright (C) 2011-2020 Entr'ouvert # diff --git a/eopayment/common.py b/eopayment/common.py index 522dd91..400b66e 100644 --- a/eopayment/common.py +++ b/eopayment/common.py @@ -61,18 +61,18 @@ ORDERID_TRANSACTION_SEPARATOR = '!' def force_text(s, encoding='utf-8'): - if issubclass(type(s), six.text_type): + if issubclass(type(s), str): return s try: - if not issubclass(type(s), six.string_types): + if not issubclass(type(s), str): if isinstance(s, bytes): - s = six.text_type(s, encoding) + s = str(s, encoding) else: - s = six.text_type(s) + s = str(s) else: s = s.decode(encoding) except UnicodeDecodeError: - return six.text_type(s, encoding, 'ignore') + return str(s, encoding, 'ignore') return s @@ -93,7 +93,7 @@ class ResponseError(PaymentException): pass -class PaymentResponse(object): +class PaymentResponse: '''Holds a generic view on the result of payment transaction response. result -- holds the declarative result of the transaction, does not use @@ -143,7 +143,7 @@ class PaymentResponse(object): return self.result == ERROR -class PaymentCommon(object): +class PaymentCommon: has_free_transaction_id = False PATH = '/tmp' @@ -189,7 +189,7 @@ class PaymentCommon(object): return str(amount) -class Form(object): +class Form: def __init__(self, url, method, fields, encoding='utf-8', submit_name='Submit', submit_value='Submit'): self.url = url diff --git a/eopayment/ogone.py b/eopayment/ogone.py index 612906c..b25b8c6 100644 --- a/eopayment/ogone.py +++ b/eopayment/ogone.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # eopayment - online payment library # Copyright (C) 2011-2020 Entr'ouvert # @@ -456,7 +455,7 @@ class Payment(PaymentCommon): }, { 'name': 'language', - 'caption': _(u'Language'), + 'caption': _('Language'), 'default': 'fr_FR', 'choices': (('fr_FR', 'français'),), }, @@ -496,14 +495,14 @@ class Payment(PaymentCommon): def __init__(self, options, logger=None): # retro-compatibility with old default of latin1 options.setdefault('encoding', 'iso-8859-1') - super(Payment, self).__init__(options, logger=logger) + super().__init__(options, logger=logger) def sha_sign(self, algo, key, params, keep, encoding='iso-8859-1'): '''Ogone signature algorithm of query string''' values = params.items() values = [(a.upper(), b) for a, b in values] values = sorted(values) - values = [u'%s=%s' % (a, b) for a, b in values if a in keep and b] + values = ['%s=%s' % (a, b) for a, b in values if a in keep and b] tosign = key.join(values) tosign += key tosign = force_byte(tosign, encoding=encoding) @@ -578,8 +577,8 @@ class Payment(PaymentCommon): def response(self, query_string, **kwargs): params = urlparse.parse_qs(query_string, True, encoding=self.encoding) - params = dict((key.upper(), params[key][0]) for key in params) - if not set(params) >= set(['ORDERID', 'PAYID', 'STATUS', 'NCERROR']): + params = {key.upper(): params[key][0] for key in params} + if not set(params) >= {'ORDERID', 'PAYID', 'STATUS', 'NCERROR'}: raise ResponseError('missing ORDERID, PAYID, STATUS or NCERROR') # py2: decode binary strings in query-string diff --git a/eopayment/paybox.py b/eopayment/paybox.py index da19999..97aaed4 100644 --- a/eopayment/paybox.py +++ b/eopayment/paybox.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 # eopayment - online payment library # Copyright (C) 2011-2020 Entr'ouvert # @@ -224,7 +223,7 @@ class Payment(PaymentCommon): 'name': 'site', 'caption': 'Numéro de site', 'required': True, - 'validation': lambda x: isinstance(x, six.string_types) + 'validation': lambda x: isinstance(x, str) and x.isdigit() and len(x) == 7, }, { @@ -232,20 +231,20 @@ class Payment(PaymentCommon): 'caption': 'Clé', 'help_text': 'Uniquement nécessaire pour l\'annulation / remboursement / encaissement (PayBox Direct)', 'required': False, - 'validation': lambda x: isinstance(x, six.string_types), + 'validation': lambda x: isinstance(x, str), }, { 'name': 'rang', 'caption': 'Numéro de rang', 'required': True, - 'validation': lambda x: isinstance(x, six.string_types) + 'validation': lambda x: isinstance(x, str) and x.isdigit() and len(x) == 3, }, { 'name': 'identifiant', 'caption': 'Identifiant', 'required': True, - 'validation': lambda x: isinstance(x, six.string_types) + 'validation': lambda x: isinstance(x, str) and x.isdigit() and (0 < len(x) < 10), }, { @@ -273,7 +272,7 @@ class Payment(PaymentCommon): 'caption': 'Nombre de jours pour un paiement différé', 'default': '', 'required': False, - 'validation': lambda x: isinstance(x, six.string_types) + 'validation': lambda x: isinstance(x, str) and x.isdigit() and (1 <= len(x) <= 2) }, { @@ -358,17 +357,17 @@ class Payment(PaymentCommon): fields = [] for k, v in d: fields.append({ - 'type': u'hidden', + 'type': 'hidden', 'name': force_text(k), 'value': force_text(v), }) form = Form(url, 'POST', fields, submit_name=None, - submit_value=u'Envoyer', encoding='utf-8') + submit_value='Envoyer', encoding='utf-8') return transaction_id, FORM, form def response(self, query_string, callback=False, **kwargs): d = urlparse.parse_qs(query_string, True, False) - if not set(d) >= set(['erreur', 'reference']): + if not set(d) >= {'erreur', 'reference'}: raise ResponseError('missing erreur or reference') signed = False if 'signature' in d: diff --git a/eopayment/payfip_ws.py b/eopayment/payfip_ws.py index 08600d4..d7c90cf 100644 --- a/eopayment/payfip_ws.py +++ b/eopayment/payfip_ws.py @@ -14,7 +14,6 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from __future__ import print_function, unicode_literals import copy import decimal @@ -85,10 +84,10 @@ class PayFiPError(PaymentException): args = [code, message] if origin: args.append(origin) - super(PayFiPError, self).__init__(*args) + super().__init__(*args) -class PayFiP(object): +class PayFiP: '''Encapsulate SOAP web-services of PayFiP''' def __init__(self, wsdl_url=None, service_url=None, zeep_client_kwargs=None, use_local_wsdl=True): @@ -177,8 +176,8 @@ class Payment(PaymentCommon): 'parameters': [ { 'name': 'numcli', - 'caption': _(u'Client number'), - 'help_text': _(u'6 digits number provided by DGFIP'), + 'caption': _('Client number'), + 'help_text': _('6 digits number provided by DGFIP'), 'validation': lambda s: str.isdigit(s) and len(s) == 6, 'required': True, }, @@ -211,7 +210,7 @@ class Payment(PaymentCommon): maximal_amount = decimal.Decimal('100000.0') def __init__(self, *args, **kwargs): - super(Payment, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.payfip = PayFiP() def _generate_refdet(self): @@ -382,7 +381,7 @@ if __name__ == '__main__': ctx.obj = PayFiP(wsdl_url=wsdl_url, service_url=service_url) def numcli(ctx, param, value): - if not isinstance(value, six.string_types) or len(value) != 6 or not value.isdigit(): + if not isinstance(value, str) or len(value) != 6 or not value.isdigit(): raise click.BadParameter('numcli must a 6 digits number') return value diff --git a/eopayment/saga.py b/eopayment/saga.py index 4286cfc..6709f79 100644 --- a/eopayment/saga.py +++ b/eopayment/saga.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # eopayment - online payment library # Copyright (C) 2011-2020 Entr'ouvert # @@ -15,7 +14,6 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from __future__ import unicode_literals, print_function import functools @@ -35,7 +33,7 @@ class SagaError(PaymentException): pass -class Saga(object): +class Saga: def __init__(self, wsdl_url, service_url=None, zeep_client_kwargs=None): self.wsdl_url = wsdl_url kwargs = (zeep_client_kwargs or {}).copy() diff --git a/eopayment/sips2.py b/eopayment/sips2.py index f502116..c888634 100644 --- a/eopayment/sips2.py +++ b/eopayment/sips2.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # eopayment - online payment library # Copyright (C) 2011-2020 Entr'ouvert # @@ -165,7 +164,7 @@ class Payment(PaymentCommon): } def encode_data(self, data): - return u'|'.join(u'%s=%s' % (force_text(key), force_text(value)) + return '|'.join('%s=%s' % (force_text(key), force_text(value)) for key, value in data.items()) def seal_data(self, data): @@ -256,7 +255,7 @@ class Payment(PaymentCommon): def response(self, query_string, **kwargs): form = urlparse.parse_qs(query_string) - if not set(form) >= set(['Data', 'Seal', 'InterfaceVersion']): + if not set(form) >= {'Data', 'Seal', 'InterfaceVersion'}: raise ResponseError('missing Data, Seal or InterfaceVersion') self.logger.debug('received query string %r', form) data = self.decode_data(form['Data'][0]) @@ -283,7 +282,7 @@ class Payment(PaymentCommon): bank_data=data, order_id=transaction_id, transaction_id=data.get('authorisationId'), - bank_status=self.RESPONSE_CODES.get(response_code, u'unknown code - ' + response_code), + bank_status=self.RESPONSE_CODES.get(response_code, 'unknown code - ' + response_code), test=test, transaction_date=transaction_date) @@ -293,7 +292,7 @@ class Payment(PaymentCommon): if key in ('keyVersion', 'sealAlgorithm', 'seal'): continue data_to_send.append(force_text(data[key])) - data_to_send_str = u''.join(data_to_send).encode('utf-8') + data_to_send_str = ''.join(data_to_send).encode('utf-8') return hmac.new(force_text(self.secret_key).encode('utf-8'), data_to_send_str, hashlib.sha256).hexdigest() def perform_cash_management_operation(self, endpoint, data): diff --git a/eopayment/systempayv2.py b/eopayment/systempayv2.py index 695ab20..02b59b0 100644 --- a/eopayment/systempayv2.py +++ b/eopayment/systempayv2.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # eopayment - online payment library # Copyright (C) 2011-2020 Entr'ouvert # @@ -175,8 +174,8 @@ PARAMETERS = [ Parameter(VADS_CUST_FIRST_NAME, 'ans', 104, max_length=63), Parameter(VADS_CUST_LAST_NAME, 'ans', 104, max_length=63), ] -PARAMETER_MAP = dict(((parameter.name, - parameter) for parameter in PARAMETERS)) +PARAMETER_MAP = {parameter.name: + parameter for parameter in PARAMETERS} def add_vads(kwargs): @@ -290,7 +289,7 @@ class Payment(PaymentCommon): description['parameters'].append(x) def __init__(self, options, logger=None): - super(Payment, self).__init__(options, logger=logger) + super().__init__(options, logger=logger) options = add_vads(options) self.options = options @@ -396,7 +395,7 @@ class Payment(PaymentCommon): method='POST', fields=[ { - 'type': u'hidden', + 'type': 'hidden', 'name': force_text(field_name), 'value': force_text(field_value), } @@ -471,7 +470,7 @@ class Payment(PaymentCommon): def response(self, query_string, **kwargs): fields = urlparse.parse_qs(query_string, True) - if not set(fields) >= set([SIGNATURE, VADS_CTX_MODE, VADS_AUTH_RESULT]): + if not set(fields) >= {SIGNATURE, VADS_CTX_MODE, VADS_AUTH_RESULT}: raise ResponseError('missing %s, %s or %s' % (SIGNATURE, VADS_CTX_MODE, VADS_AUTH_RESULT)) for key, value in fields.items(): @@ -524,14 +523,14 @@ class Payment(PaymentCommon): def signature(self, fields): self.logger.debug('got fields %s to sign' % fields) ordered_keys = sorted( - [key for key in fields.keys() if key.startswith('vads_')]) + key for key in fields.keys() if key.startswith('vads_')) self.logger.debug('ordered keys %s' % ordered_keys) ordered_fields = [force_byte(fields[key]) for key in ordered_keys] secret = force_byte(getattr(self, 'secret_%s' % fields['vads_ctx_mode'].lower())) signed_data = b'+'.join(ordered_fields) signed_data = b'%s+%s' % (signed_data, secret) - self.logger.debug(u'generating signature on «%s»', signed_data) + self.logger.debug('generating signature on «%s»', signed_data) sign_method = getattr(self, '%s_sign' % self.signature_algo) sign = sign_method(secret, signed_data) - self.logger.debug(u'signature «%s»', sign) + self.logger.debug('signature «%s»', sign) return force_text(sign) diff --git a/eopayment/tipi.py b/eopayment/tipi.py index d6a9e2a..403cf2e 100644 --- a/eopayment/tipi.py +++ b/eopayment/tipi.py @@ -45,8 +45,8 @@ class Payment(PaymentCommon): 'parameters': [ { 'name': 'numcli', - 'caption': _(u'Client number'), - 'help_text': _(u'6 digits number provided by DGFIP'), + 'caption': _('Client number'), + 'help_text': _('6 digits number provided by DGFIP'), 'validation': lambda s: str.isdigit(s) and (0 < int(s) < 1000000), 'required': True, }, @@ -158,7 +158,7 @@ class Payment(PaymentCommon): def response(self, query_string, **kwargs): fields = parse_qs(query_string, True) - if not set(fields) >= set(['refdet', 'resultrans']): + if not set(fields) >= {'refdet', 'resultrans'}: raise ResponseError('missing refdet or resultrans') for key, value in fields.items(): fields[key] = value[0] diff --git a/setup.py b/setup.py index b8a002a..142c827 100755 --- a/setup.py +++ b/setup.py @@ -73,7 +73,7 @@ def get_version(): tag exists, take 0.0.0- and add the length of the commit log. ''' if os.path.exists('VERSION'): - with open('VERSION', 'r') as v: + with open('VERSION') as v: return v.read() if os.path.exists('.git'): p = subprocess.Popen(['git', 'describe', '--dirty', @@ -134,7 +134,7 @@ setuptools.setup( description='Common API to use all French online payment credit card ' 'processing services', include_package_data=True, - long_description=io.open( + long_description=open( os.path.join( os.path.dirname(__file__), 'README.txt'), encoding='utf-8').read(), diff --git a/tests/conftest.py b/tests/conftest.py index 5dbaa7c..5f79977 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -33,10 +33,10 @@ def pytest_addoption(parser): class LoggingAdapter(HTTPAdapter): def __init__(self, *args, **kwargs): self.history = [] - super(LoggingAdapter, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def send(self, request, *args, **kwargs): - response = super(LoggingAdapter, self).send(request, *args, **kwargs) + response = super().send(request, *args, **kwargs) self.history.append((request, response)) return response diff --git a/tests/test_base_payment.py b/tests/test_base_payment.py index b1f25fe..2f33af5 100644 --- a/tests/test_base_payment.py +++ b/tests/test_base_payment.py @@ -16,7 +16,7 @@ from datetime import date, datetime, timedelta -import mock +from unittest import mock import pytest import eopayment @@ -64,7 +64,7 @@ def test_deferred_payment(monkeypatch): capture_date = (datetime.now().date() + timedelta(days=3)) payment.request(amount=12.2, capture_date=capture_date) - mock_backend.request.assert_called_with(12.2, **{'capture_day': u'3'}) + mock_backend.request.assert_called_with(12.2, **{'capture_day': '3'}) # capture date can't be inferior to the transaction date capture_date = (datetime.now().date() - timedelta(days=3)) diff --git a/tests/test_ogone.py b/tests/test_ogone.py index 5cdb14c..18460c2 100644 --- a/tests/test_ogone.py +++ b/tests/test_ogone.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # eopayment - online payment library # Copyright (C) 2011-2020 Entr'ouvert # @@ -24,7 +23,7 @@ import eopayment import eopayment.ogone as ogone from eopayment import ResponseError -PSPID = u'2352566ö' +PSPID = '2352566ö' @pytest.fixture(params=[None, 'iso-8859-1', 'utf-8']) @@ -32,9 +31,9 @@ def params(request): params = { 'environment': ogone.ENVIRONMENT_TEST, 'pspid': PSPID, - 'sha_in': u'sécret', - 'sha_out': u'sécret', - 'automatic_return_url': u'http://example.com/autömatic_réturn_url' + 'sha_in': 'sécret', + 'sha_out': 'sécret', + 'automatic_return_url': 'http://example.com/autömatic_réturn_url' } encoding = request.param if encoding: @@ -45,7 +44,7 @@ def params(request): def test_request(params): ogone_backend = eopayment.Payment('ogone', params) amount = '42.42' - order_id = u'my ordér' + order_id = 'my ordér' reference, kind, what = ogone_backend.request( amount=amount, orderid=order_id, @@ -56,7 +55,7 @@ def test_request(params): assert root.attrib['method'] == 'POST' assert root.attrib['action'] == ogone.ENVIRONMENT_TEST_URL values = { - 'CURRENCY': u'EUR', + 'CURRENCY': 'EUR', 'ORDERID': order_id, 'PSPID': PSPID, 'EMAIL': 'foo@example.com', @@ -67,7 +66,7 @@ def test_request(params): values.update({'SHASIGN': ogone_backend.backend.sha_sign_in(values)}) for node in root: assert node.attrib['type'] in ('hidden', 'submit') - assert set(node.attrib.keys()), set(['type', 'name' == 'value']) + assert set(node.attrib.keys()), {'type', 'name' == 'value'} name = node.attrib['name'] if node.attrib['type'] == 'hidden': assert name in values @@ -77,10 +76,10 @@ def test_request(params): def test_response(params): ogone_backend = eopayment.Payment('ogone', params) order_id = 'myorder' - data = {'orderid': u'myorder', 'status': u'9', 'payid': u'3011229363', - 'cn': u'Usér', 'ncerror': u'0', - 'trxdate': u'10/24/16', 'acceptance': u'test123', - 'currency': u'eur', 'amount': u'7.5'} + data = {'orderid': 'myorder', 'status': '9', 'payid': '3011229363', + 'cn': 'Usér', 'ncerror': '0', + 'trxdate': '10/24/16', 'acceptance': 'test123', + 'currency': 'eur', 'amount': '7.5'} data['shasign'] = ogone_backend.backend.sha_sign_out( data, encoding=params.get('encoding', 'iso-8859-1')) # uniformize to utf-8 first @@ -95,9 +94,9 @@ def test_iso_8859_1_response(): params = { 'environment': ogone.ENVIRONMENT_TEST, 'pspid': PSPID, - 'sha_in': u'sécret', - 'sha_out': u'sécret', - 'automatic_return_url': u'http://example.com/autömatic_réturn_url' + 'sha_in': 'sécret', + 'sha_out': 'sécret', + 'automatic_return_url': 'http://example.com/autömatic_réturn_url' } ogone_backend = eopayment.Payment('ogone', params) order_id = 'lRXK4Rl1N2yIR3R5z7Kc' @@ -124,17 +123,17 @@ def test_bad_response(params): def test_bank_transfer_response(params): ogone_backend = eopayment.Payment('ogone', params) data = { - 'orderid': u'myorder', - 'status': u'41', - 'payid': u'3011229363', - 'cn': u'User', - 'ncerror': u'0', - 'trxdate': u'10/24/16', + 'orderid': 'myorder', + 'status': '41', + 'payid': '3011229363', + 'cn': 'User', + 'ncerror': '0', + 'trxdate': '10/24/16', 'brand': 'Bank transfer', 'pm': 'bank transfer', - 'currency': u'eur', - 'amount': u'7.5', - 'shasign': u'944CBD1E010BA4945415AE4B16CC40FD533F6CE2', + 'currency': 'eur', + 'amount': '7.5', + 'shasign': '944CBD1E010BA4945415AE4B16CC40FD533F6CE2', } # uniformize to expected encoding for k in data: diff --git a/tests/test_paybox.py b/tests/test_paybox.py index f7f393c..79bbf0b 100644 --- a/tests/test_paybox.py +++ b/tests/test_paybox.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # eopayment - online payment library # Copyright (C) 2011-2020 Entr'ouvert # @@ -20,7 +19,7 @@ import codecs from unittest import TestCase from decimal import Decimal import base64 -import mock +from unittest import mock from six.moves.urllib import parse as urllib from xml.etree import ElementTree as ET @@ -31,17 +30,17 @@ import eopayment BACKEND_PARAMS = { - 'platform': u'test', - 'site': u'12345678', - 'rang': u'001', - 'identifiant': u'12345678', + 'platform': 'test', + 'site': '12345678', + 'rang': '001', + 'identifiant': '12345678', 'shared_secret': ( - u'0123456789ABCDEF0123456789ABCDEF01234' - u'56789ABCDEF0123456789ABCDEF0123456789' - u'ABCDEF0123456789ABCDEF0123456789ABCDE' - u'F0123456789ABCDEF' + '0123456789ABCDEF0123456789ABCDEF01234' + '56789ABCDEF0123456789ABCDEF0123456789' + 'ABCDEF0123456789ABCDEF0123456789ABCDE' + 'F0123456789ABCDEF' ), - 'automatic_return_url': u'http://example.com/callback', + 'automatic_return_url': 'http://example.com/callback', } @@ -54,16 +53,16 @@ class PayboxTests(TestCase): b'EF') key = codecs.decode(key, 'hex') d = dict(paybox.sign([ - ['PBX_SITE', u'12345678'], - ['PBX_RANG', u'32'], - ['PBX_IDENTIFIANT', u'12345678'], - ['PBX_TOTAL', u'999'], - ['PBX_DEVISE', u'978'], - ['PBX_CMD', u'appel à Paybox'], - ['PBX_PORTEUR', u'test@paybox.com'], - ['PBX_RETOUR', u'Mt:M;Ref:R;Auto:A;Erreur:E'], - ['PBX_HASH', u'SHA512'], - ['PBX_TIME', u'2015-06-08T16:21:16+02:00'], + ['PBX_SITE', '12345678'], + ['PBX_RANG', '32'], + ['PBX_IDENTIFIANT', '12345678'], + ['PBX_TOTAL', '999'], + ['PBX_DEVISE', '978'], + ['PBX_CMD', 'appel à Paybox'], + ['PBX_PORTEUR', 'test@paybox.com'], + ['PBX_RETOUR', 'Mt:M;Ref:R;Auto:A;Erreur:E'], + ['PBX_HASH', 'SHA512'], + ['PBX_TIME', '2015-06-08T16:21:16+02:00'], ], key)) result = ( '7E74D8E9A0DBB65AAE51C5C50C2668FD98FC99AED' @@ -119,9 +118,9 @@ class PayboxTests(TestCase): for node in root: self.assertIn(node.attrib['type'], ('hidden', 'submit')) if node.attrib['type'] == 'submit': - self.assertEqual(set(node.attrib.keys()), set(['type', 'value'])) + self.assertEqual(set(node.attrib.keys()), {'type', 'value'}) if node.attrib['type'] == 'hidden': - self.assertEqual(set(node.attrib.keys()), set(['type', 'name', 'value'])) + self.assertEqual(set(node.attrib.keys()), {'type', 'name', 'value'}) name = node.attrib['name'] form_params[name] = node.attrib['value'] assert form_params == expected_form_values @@ -142,8 +141,8 @@ class PayboxTests(TestCase): transaction_id=transaction, time=time) root = ET.fromstring(str(what)) - form_params = dict( - ((node.attrib['name'], node.attrib['value']) for node in root if node.attrib['type'] == 'hidden')) + form_params = { + node.attrib['name']: node.attrib['value'] for node in root if node.attrib['type'] == 'hidden'} self.assertIn('PBX_DIFF', form_params) self.assertEqual(form_params['PBX_DIFF'], '07') @@ -155,9 +154,9 @@ class PayboxTests(TestCase): transaction_id=transaction, time=time, capture_day='2') root = ET.fromstring(str(what)) - form_params = dict((( - node.attrib['name'], node.attrib['value']) for node in root - if node.attrib['type'] == 'hidden')) + form_params = { + node.attrib['name']: node.attrib['value'] for node in root + if node.attrib['type'] == 'hidden'} self.assertIn('PBX_DIFF', form_params) self.assertEqual(form_params['PBX_DIFF'], '02') @@ -171,9 +170,9 @@ class PayboxTests(TestCase): transaction_id=transaction, time=time, capture_day='2') root = ET.fromstring(str(what)) - form_params = dict((( - node.attrib['name'], node.attrib['value']) for node in root - if node.attrib['type'] == 'hidden')) + form_params = { + node.attrib['name']: node.attrib['value'] for node in root + if node.attrib['type'] == 'hidden'} self.assertIn('PBX_DIFF', form_params) self.assertEqual(form_params['PBX_DIFF'], '02') @@ -192,8 +191,8 @@ class PayboxTests(TestCase): transaction_id=transaction, time=time) root = ET.fromstring(str(what)) - form_params = dict( - ((node.attrib['name'], node.attrib['value']) for node in root if node.attrib['type'] == 'hidden')) + form_params = { + node.attrib['name']: node.attrib['value'] for node in root if node.attrib['type'] == 'hidden'} self.assertEqual(form_params['PBX_AUTOSEULE'], 'O') def test_response(self): @@ -228,16 +227,16 @@ class PayboxTests(TestCase): 'reference': ['830657461681'], } backend_raw_response = ( - u'NUMTRANS=0013989865&NUMAPPEL=0030378572&NUMQUESTION=0013989862' - u'&SITE=1999888&RANG=32&AUTORISATION=XXXXXX&CODEREPONSE=00000' - u'&COMMENTAIRE=Demande traitée avec succès&REFABONNE=&PORTEUR=' + 'NUMTRANS=0013989865&NUMAPPEL=0030378572&NUMQUESTION=0013989862' + '&SITE=1999888&RANG=32&AUTORISATION=XXXXXX&CODEREPONSE=00000' + '&COMMENTAIRE=Demande traitée avec succès&REFABONNE=&PORTEUR=' ) backend_expected_response = {"CODEREPONSE": "00000", "RANG": "32", "AUTORISATION": "XXXXXX", "NUMTRANS": "0013989865", "PORTEUR": "", - "COMMENTAIRE": u"Demande traitée avec succès", + "COMMENTAIRE": "Demande traitée avec succès", "SITE": "1999888", "NUMAPPEL": "0030378572", "REFABONNE": "", @@ -278,7 +277,7 @@ class PayboxTests(TestCase): self.assertEqual(requests_post.call_args[0][0], 'https://ppps.paybox.com/PPPS.php') with mock.patch('eopayment.paybox.requests.post') as requests_post: - error_response = u"""CODEREPONSE=00015&COMMENTAIRE=PAYBOX : Transaction non trouvée""" + error_response = """CODEREPONSE=00015&COMMENTAIRE=PAYBOX : Transaction non trouvée""" response = mock.Mock(status_code=200, text=error_response) requests_post.return_value = response self.assertRaisesRegex( @@ -298,9 +297,9 @@ class PayboxTests(TestCase): 'reference': ['830657461681'] } backend_raw_response = ( - u'NUMTRANS=0013989865&NUMAPPEL=0030378572&NUMQUESTION=0013989862' - u'&SITE=1999888&RANG=32&AUTORISATION=XXXXXX&CODEREPONSE=00000' - u'&COMMENTAIRE=Demande traitée avec succès&REFABONNE=&PORTEUR=' + 'NUMTRANS=0013989865&NUMAPPEL=0030378572&NUMQUESTION=0013989862' + '&SITE=1999888&RANG=32&AUTORISATION=XXXXXX&CODEREPONSE=00000' + '&COMMENTAIRE=Demande traitée avec succès&REFABONNE=&PORTEUR=' ) with mock.patch('eopayment.paybox.requests.post') as requests_post: @@ -338,9 +337,9 @@ FBFKOZhgBJnkC+l6+XhT4aYWKaQ4ocmOMV92yjeXTE4=''' transaction_id=transaction, time=time) root = ET.fromstring(str(what)) - form_params = dict(( - (node.attrib['name'], node.attrib['value']) for node in root - if node.attrib['type'] == 'hidden')) + form_params = { + node.attrib['name']: node.attrib['value'] for node in root + if node.attrib['type'] == 'hidden'} self.assertIn('PBX_AUTOSEULE', form_params) self.assertEqual(form_params['PBX_AUTOSEULE'], 'N') @@ -352,9 +351,9 @@ FBFKOZhgBJnkC+l6+XhT4aYWKaQ4ocmOMV92yjeXTE4=''' time=time, manual_validation=True) root = ET.fromstring(str(what)) - form_params = dict(( - (node.attrib['name'], node.attrib['value']) for node in root - if node.attrib['type'] == 'hidden')) + form_params = { + node.attrib['name']: node.attrib['value'] for node in root + if node.attrib['type'] == 'hidden'} self.assertIn('PBX_AUTOSEULE', form_params) self.assertEqual(form_params['PBX_AUTOSEULE'], 'O') diff --git a/tests/test_payfip_ws.py b/tests/test_payfip_ws.py index e4a3959..e5d4952 100644 --- a/tests/test_payfip_ws.py +++ b/tests/test_payfip_ws.py @@ -1,4 +1,3 @@ -# coding: utf-8 # # eopayment - online payment library # Copyright (C) 2011-2020 Entr'ouvert @@ -16,12 +15,11 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from __future__ import print_function, unicode_literals import datetime import json import lxml.etree as ET -import mock +from unittest import mock import pytz @@ -56,7 +54,7 @@ def freezer(freezer): return freezer -class PayFiPHTTMock(object): +class PayFiPHTTMock: def __init__(self, history_name): history_path = 'tests/data/payfip-%s.json' % history_name with open(history_path) as fd: diff --git a/tests/test_saga.py b/tests/test_saga.py index 1671ec9..62b651c 100644 --- a/tests/test_saga.py +++ b/tests/test_saga.py @@ -1,4 +1,3 @@ -# coding: utf-8 # # eopayment - online payment library # Copyright (C) 2011-2020 Entr'ouvert @@ -16,7 +15,6 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from __future__ import print_function, unicode_literals import json diff --git a/tests/test_sips2.py b/tests/test_sips2.py index 2c70882..a982f79 100644 --- a/tests/test_sips2.py +++ b/tests/test_sips2.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # eopayment - online payment library # Copyright (C) 2011-2020 Entr'ouvert # @@ -22,26 +21,26 @@ import pytest def test_build_request(): backend = eopayment.Payment('sips2', {}) - transaction, f, form = backend.request(amount=u'12', last_name=u'Foo', - first_name=u'Félix000000') + transaction, f, form = backend.request(amount='12', last_name='Foo', + first_name='Félix000000') data = [f for f in form.fields if f['name'] == 'Data'] - assert u'lix000000' not in data[0]['value'] + assert 'lix000000' not in data[0]['value'] - transaction, f, form = backend.request(amount=u'12') + transaction, f, form = backend.request(amount='12') data = [f for f in form.fields if f['name'] == 'Data'] assert 'statementReference=%s' % transaction in data[0]['value'] - transaction, f, form = backend.request(amount=u'12', info1='foobar') + transaction, f, form = backend.request(amount='12', info1='foobar') data = [f for f in form.fields if f['name'] == 'Data'] assert 'statementReference=foobar' in data[0]['value'] - transaction, f, form = backend.request(amount=u'12', info1='foobar', capture_day=u'1') + transaction, f, form = backend.request(amount='12', info1='foobar', capture_day='1') data = [f for f in form.fields if f['name'] == 'Data'] assert 'captureDay=1' in data[0]['value'] def test_options(): - payment = eopayment.Payment('sips2', {'capture_mode': u'VALIDATION'}) + payment = eopayment.Payment('sips2', {'capture_mode': 'VALIDATION'}) assert payment.backend.get_data()['captureMode'] == 'VALIDATION' payment = eopayment.Payment('sips2', {}) diff --git a/tests/test_systempayv2.py b/tests/test_systempayv2.py index 353e190..dc91afd 100644 --- a/tests/test_systempayv2.py +++ b/tests/test_systempayv2.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # eopayment - online payment library # Copyright (C) 2011-2020 Entr'ouvert # @@ -27,10 +26,10 @@ from eopayment.systempayv2 import Payment, VADS_CUST_FIRST_NAME, \ from eopayment import ResponseError PARAMS = { - 'secret_test': u'1122334455667788', - 'vads_site_id': u'12345678', - 'vads_ctx_mode': u'TEST', - 'vads_trans_date': u'20090501193530', + 'secret_test': '1122334455667788', + 'vads_site_id': '12345678', + 'vads_ctx_mode': 'TEST', + 'vads_trans_date': '20090501193530', 'signature_algo': 'sha1' } @@ -52,8 +51,8 @@ def test_systempayv2(caplog): data = { 'amount': 15.24, 'orderid': '654321', - 'first_name': u'Jean Michél', - 'last_name': u'Mihaï' + 'first_name': 'Jean Michél', + 'last_name': 'Mihaï' } qs = ( 'vads_version=V2&vads_page_action=PAYMENT&vads_action_mode=INTERACTIV' @@ -70,7 +69,7 @@ def test_systempayv2(caplog): # check that user first and last names are unicode for field in form.fields: if field['name'] in (VADS_CUST_FIRST_NAME, VADS_CUST_LAST_NAME): - assert field['value'] in (u'Jean Michél', u'Mihaï') + assert field['value'] in ('Jean Michél', 'Mihaï') response_qs = 'vads_amount=1042&vads_auth_mode=FULL&vads_auth_number=3feadf' \ '&vads_auth_result=00&vads_capture_delay=0&vads_card_brand=CB' \ @@ -112,13 +111,13 @@ def test_systempayv2(caplog): def test_systempayv2_deferred_payment(): default_params = { - 'secret_test': u'1122334455667788', - 'vads_site_id': u'12345678', - 'vads_ctx_mode': u'TEST', + 'secret_test': '1122334455667788', + 'vads_site_id': '12345678', + 'vads_ctx_mode': 'TEST', } default_data = { - 'amount': 15.24, 'orderid': '654321', 'first_name': u'John', - 'last_name': u'Doe' + 'amount': 15.24, 'orderid': '654321', 'first_name': 'John', + 'last_name': 'Doe' } # default vads_capture_delay used @@ -152,13 +151,13 @@ def test_systempayv2_deferred_payment(): def test_manual_validation(): params = { - 'secret_test': u'1122334455667788', - 'vads_site_id': u'12345678', - 'vads_ctx_mode': u'TEST', + 'secret_test': '1122334455667788', + 'vads_site_id': '12345678', + 'vads_ctx_mode': 'TEST', } data = { - 'amount': 15.24, 'orderid': '654321', 'first_name': u'John', - 'last_name': u'Doe' + 'amount': 15.24, 'orderid': '654321', 'first_name': 'John', + 'last_name': 'Doe' } backend = eopayment.Payment('systempayv2', params)