summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Dauvergne <bdauvergne@entrouvert.com>2020-09-18 13:40:30 (GMT)
committerBenjamin Dauvergne <bdauvergne@entrouvert.com>2020-09-18 13:40:30 (GMT)
commitb99c62cfd5b27494e0cc659b4bb851b48fee06d4 (patch)
tree9a43433839d83c7e509fd5b85be773386134afaa
parentcae250d132c3c9b35916d7eceebef538d56e98ec (diff)
downloadeopayment-b99c62cfd5b27494e0cc659b4bb851b48fee06d4.zip
eopayment-b99c62cfd5b27494e0cc659b4bb851b48fee06d4.tar.gz
eopayment-b99c62cfd5b27494e0cc659b4bb851b48fee06d4.tar.bz2
dummy: handle capture_date in request() (#46787)
-rw-r--r--eopayment/dummy.py8
-rw-r--r--tests/test_dummy.py34
2 files changed, 36 insertions, 6 deletions
diff --git a/eopayment/dummy.py b/eopayment/dummy.py
index cf36690..8d63936 100644
--- a/eopayment/dummy.py
+++ b/eopayment/dummy.py
@@ -135,12 +135,16 @@ class Payment(PaymentCommon):
'type': str,
'deprecated': True,
},
+ {
+ 'name': 'capture_day',
+ 'type': str,
+ },
],
}
def request(self, amount, name=None, address=None, email=None, phone=None,
orderid=None, info1=None, info2=None, info3=None,
- next_url=None, **kwargs):
+ next_url=None, capture_day=None, **kwargs):
self.logger.debug(
'%s amount %s name %s address %s email %s phone %s'
' next_url %s info1 %s info2 %s info3 %s kwargs: %s',
@@ -168,6 +172,8 @@ class Payment(PaymentCommon):
query.update(
dict(name=name, address=address, email=email, phone=phone,
orderid=orderid, info1=info1, info2=info2, info3=info3))
+ if capture_day is not None:
+ query['capture_day'] = str(capture_day)
for key in list(query.keys()):
if query[key] is None:
del query[key]
diff --git a/tests/test_dummy.py b/tests/test_dummy.py
index b46b1d8..df0bb49 100644
--- a/tests/test_dummy.py
+++ b/tests/test_dummy.py
@@ -14,18 +14,42 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+from six.moves.urllib.parse import urlparse, parse_qs
+import datetime
import eopayment
import pytest
-def test_dummy():
+@pytest.fixture
+def backend():
options = {
'direct_notification_url': 'http://example.com/direct_notification_url',
'siret': '1234',
'origin': 'Mairie de Perpette-les-oies'
}
- p = eopayment.Payment('dummy', options)
+ return eopayment.Payment('dummy', options)
+
+
+def test_request(backend, freezer):
+ freezer.move_to('2020-01-01 00:00:00+01:00')
+ transaction_id, method, raw_url = backend.request('10.10', capture_date=datetime.date(2020, 1, 7))
+ assert transaction_id
+ assert method == 1
+ url = urlparse(raw_url)
+ assert url.scheme == 'http'
+ assert url.netloc == 'dummy-payment.demo.entrouvert.com'
+ assert url.path == '/'
+ assert url.fragment == ''
+ qs = {k: v[0] for k, v in parse_qs(url.query).items()}
+ assert qs['transaction_id'] == transaction_id
+ assert qs['siret'] == '1234'
+ assert qs['amount'] == '10.10'
+ assert qs['origin'] == 'Mairie de Perpette-les-oies'
+ assert qs['capture_day'] == '6'
+
+
+def test_response(backend):
retour = (
'http://example.com/retour?amount=10.0'
'&direct_notification_url=http%3A%2F%2Fexample.com%2Fdirect_notification_url'
@@ -34,7 +58,7 @@ def test_dummy():
'&return_url=http%3A%2F%2Fexample.com%2Fretour'
'&nok=1'
)
- r = p.response(retour.split('?', 1)[1])
+ r = backend.response(retour.split('?', 1)[1])
assert not r.signed
assert r.transaction_id == '6Tfw2e1bPyYnz7CedZqvdHt7T9XX6T'
assert r.return_content is None
@@ -47,10 +71,10 @@ def test_dummy():
'&return_url=http%3A%2F%2Fexample.com%2Fretour'
'&ok=1&signed=1'
)
- r = p.response(retour.split('?', 1)[1])
+ r = backend.response(retour.split('?', 1)[1])
assert r.signed
assert r.transaction_id == '6Tfw2e1bPyYnz7CedZqvdHt7T9XX6T'
assert r.return_content == 'signature ok'
with pytest.raises(eopayment.ResponseError, match='missing transaction_id'):
- p.response('foo=bar')
+ backend.response('foo=bar')