summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEmmanuel Cazenave <ecazenave@entrouvert.com>2018-10-12 13:35:23 (GMT)
committerEmmanuel Cazenave <ecazenave@entrouvert.com>2018-11-12 14:18:10 (GMT)
commit980ab967ba9eb3ddbb67f10b0cc574c4a12bdb47 (patch)
treea71290ca48bb82c0c597df9034d4de0496ec059a /tests
parentd383315b34639421d6ef29dcdb603c41f07dde28 (diff)
downloadeopayment-980ab967ba9eb3ddbb67f10b0cc574c4a12bdb47.zip
eopayment-980ab967ba9eb3ddbb67f10b0cc574c4a12bdb47.tar.gz
eopayment-980ab967ba9eb3ddbb67f10b0cc574c4a12bdb47.tar.bz2
allow arbitrary date for deferred payment (#26992)
Diffstat (limited to 'tests')
-rw-r--r--tests/test_base_payment.py66
-rw-r--r--tests/test_paybox.py31
-rw-r--r--tests/test_sips2.py5
-rw-r--r--tests/test_systempayv2.py49
4 files changed, 151 insertions, 0 deletions
diff --git a/tests/test_base_payment.py b/tests/test_base_payment.py
new file mode 100644
index 0000000..7ea551e
--- /dev/null
+++ b/tests/test_base_payment.py
@@ -0,0 +1,66 @@
+from datetime import date, datetime, timedelta
+
+import mock
+import pytest
+
+
+def do_mock_backend(monkeypatch):
+
+ class MockBackend(object):
+
+ request = mock.Mock()
+
+ description = {
+ 'parameters': [
+ {
+ 'name': 'capture_day',
+ }
+ ]
+ }
+
+ def get_backend(*args, **kwargs):
+ def backend(*args, **kwargs):
+ return MockBackend
+ return backend
+
+ import eopayment
+ monkeypatch.setattr(eopayment, 'get_backend', get_backend)
+ return MockBackend, eopayment.Payment('kind', None)
+
+
+def test_deferred_payment(monkeypatch):
+ mock_backend, payment = do_mock_backend(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'})
+
+ # capture date can't be inferior to the transaction date
+ capture_date = (datetime.now().date() - timedelta(days=3))
+ with pytest.raises(
+ ValueError, match='capture_date needs to be superior to the transaction date.'):
+ payment.request(amount=12.2, capture_date=capture_date)
+
+ # capture date should be a date object
+ capture_date = 'not a date'
+ with pytest.raises(ValueError, match='capture_date should be a datetime.date object.'):
+ payment.request(amount=12.2, capture_date=capture_date)
+
+ # using capture date on a backend that does not support it raise an error
+ capture_date = (datetime.now().date() + timedelta(days=3))
+ mock_backend.description['parameters'] = []
+ with pytest.raises(ValueError, match='capture_date is not supported by the backend.'):
+ payment.request(amount=12.2, capture_date=capture_date)
+
+
+def test_paris_timezone(freezer, monkeypatch):
+ freezer.move_to('2018-10-02 23:50:00')
+ _, payment = do_mock_backend(monkeypatch)
+ capture_date = date(year=2018, month=10, day=3)
+
+ with pytest.raises(
+ ValueError, match='capture_date needs to be superior to the transaction date'):
+ # utcnow will return 2018-10-02 23:50:00,
+ # converted to Europe/Paris it is already 2018-10-03
+ # so 2018-10-03 for capture_date is invalid
+ payment.request(amount=12.2, capture_date=capture_date)
diff --git a/tests/test_paybox.py b/tests/test_paybox.py
index 7045026..9f38090 100644
--- a/tests/test_paybox.py
+++ b/tests/test_paybox.py
@@ -105,6 +105,37 @@ class PayboxTests(TestCase):
self.assertIn('PBX_DIFF', form_params)
self.assertEqual(form_params['PBX_DIFF'], '07')
+ # capture_day can be used as a request argument
+ params = BACKEND_PARAMS.copy()
+ backend = eopayment.Payment('paybox', params)
+ transaction_id, kind, what = backend.request(
+ Decimal(amount), email=email, orderid=order_id,
+ 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'))
+ self.assertIn('PBX_DIFF', form_params)
+ self.assertEqual(form_params['PBX_DIFF'], '02')
+
+ # capture_day passed as a request argument
+ # overrides capture_day from backend params
+ params = BACKEND_PARAMS.copy()
+ params['capture_day'] = '7'
+ backend = eopayment.Payment('paybox', params)
+ transaction_id, kind, what = backend.request(
+ Decimal(amount), email=email, orderid=order_id,
+ 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'))
+ self.assertIn('PBX_DIFF', form_params)
+ self.assertEqual(form_params['PBX_DIFF'], '02')
+
+
def test_request_with_authorization_only(self):
params = BACKEND_PARAMS.copy()
time = '2018-08-21T10:26:32+02:00'
diff --git a/tests/test_sips2.py b/tests/test_sips2.py
index 65e63f1..563c75b 100644
--- a/tests/test_sips2.py
+++ b/tests/test_sips2.py
@@ -19,6 +19,11 @@ def test_build_request():
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')
+ 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'})
assert payment.backend.get_data()['captureMode'] == 'VALIDATION'
diff --git a/tests/test_systempayv2.py b/tests/test_systempayv2.py
index bf00b6d..1df7282 100644
--- a/tests/test_systempayv2.py
+++ b/tests/test_systempayv2.py
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
+from datetime import datetime, timedelta
import pytest
from six.moves.urllib import parse as urlparse
+import eopayment
from eopayment.systempayv2 import Payment, VADS_CUST_FIRST_NAME, \
VADS_CUST_LAST_NAME, PAID
from eopayment import ResponseError
@@ -14,6 +16,13 @@ PARAMS = {
'vads_trans_date': u'20090501193530',
}
+
+def get_field(form, field_name):
+ for field in form.fields:
+ if field['name'] == field_name:
+ return field
+
+
def test_systempayv2():
p = Payment(PARAMS)
data = {'amount': 15.24, 'orderid': '654321',
@@ -49,3 +58,43 @@ def test_systempayv2():
# bad response
with pytest.raises(ResponseError, match='missing signature, vads_ctx_mode or vads_auth_result'):
p.response('foo=bar')
+
+
+def test_systempayv2_deferred_payment():
+ default_params = {
+ 'secret_test': u'1122334455667788',
+ 'vads_site_id': u'12345678',
+ 'vads_ctx_mode': u'TEST',
+ }
+ default_data = {
+ 'amount': 15.24, 'orderid': '654321', 'first_name': u'John',
+ 'last_name': u'Doe'
+ }
+
+ # default vads_capture_delay used
+ params = default_params.copy()
+ params['vads_capture_delay'] = 1
+
+ backend = eopayment.Payment('systempayv2', params)
+ data = default_data.copy()
+ transaction_id, f, form = backend.request(**data)
+ assert get_field(form, 'vads_capture_delay')['value'] == '1'
+
+ # vads_capture_delay can used in request and
+ # override default vads_capture_delay
+ params = default_params.copy()
+ params['vads_capture_delay'] = 1
+ p = eopayment.Payment('systempayv2', params)
+ data = default_data.copy()
+ data['vads_capture_delay'] = '3'
+ transaction_id, f, form = p.request(**data)
+ assert get_field(form, 'vads_capture_delay')['value'] == '3'
+
+ # capture_date can be used for deferred_payment
+ params = default_params.copy()
+ params['vads_capture_delay'] = 1
+ p = eopayment.Payment('systempayv2', params)
+ data = default_data.copy()
+ data['capture_date'] = (datetime.now().date() + timedelta(days=4))
+ transaction_id, f, form = p.request(**data)
+ assert get_field(form, 'vads_capture_delay')['value'] == '4'