dummy: handle capture_date in request() (#46787)
This commit is contained in:
parent
cae250d132
commit
b99c62cfd5
|
@ -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]
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue