summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLauréline Guérin <zebuline@entrouvert.com>2019-10-23 09:41:06 (GMT)
committerLauréline Guérin <zebuline@entrouvert.com>2019-11-03 16:27:10 (GMT)
commitfbfeb64a8322f99413f87c73982002abd872f4e3 (patch)
tree1991ac200c9d9c7314bb7eb91889e1dfdb23e171
parent818ae481c7bed9b2d466bc4844d9bfeedc567dbf (diff)
downloadcombo-wip/27854-addbasketitem-remote.zip
combo-wip/27854-addbasketitem-remote.tar.gz
combo-wip/27854-addbasketitem-remote.tar.bz2
lingo: do not add a basket item to a remote regie (#27854)wip/27854-addbasketitem-remote
-rw-r--r--combo/apps/lingo/views.py3
-rw-r--r--tests/test_lingo_payment.py30
2 files changed, 33 insertions, 0 deletions
diff --git a/combo/apps/lingo/views.py b/combo/apps/lingo/views.py
index b68b906..9b20c02 100644
--- a/combo/apps/lingo/views.py
+++ b/combo/apps/lingo/views.py
@@ -171,6 +171,9 @@ class AddBasketItemApiView(View):
# the database...
item.regie = Regie.objects.all()[0]
+ if item.regie.is_remote():
+ return HttpResponseBadRequest('Can not add a basket item to a remote regie.')
+
if request.GET.get('cancellable') == 'no':
item.user_cancellable = False
diff --git a/tests/test_lingo_payment.py b/tests/test_lingo_payment.py
index a5a43a5..0a0e152 100644
--- a/tests/test_lingo_payment.py
+++ b/tests/test_lingo_payment.py
@@ -64,6 +64,28 @@ def regie():
regie.save()
return regie
+
+@pytest.fixture
+def remote_regie():
+ try:
+ payment_backend = PaymentBackend.objects.get(slug='test1')
+ except PaymentBackend.DoesNotExist:
+ payment_backend = PaymentBackend.objects.create(
+ label='test1', slug='test1', service='dummy', service_options={'siret': '1234'})
+ try:
+ regie = Regie.objects.get(slug='remote')
+ except Regie.DoesNotExist:
+ regie = Regie()
+ regie.label = 'Remote'
+ regie.slug = 'remote'
+ regie.description = 'remote'
+ regie.payment_min_amount = Decimal(2.0)
+ regie.payment_backend = payment_backend
+ regie.webservice_url = 'http://example.org/regie' # is_remote
+ regie.save()
+ return regie
+
+
@pytest.fixture
def basket_page():
page = Page(title='xxx', slug='test_basket_cell', template_name='standard')
@@ -344,6 +366,14 @@ def test_add_basket_capture_date_format(app, user, regie, invalid_capture_date):
assert 'Bad format for capture date, it should be yyyy-mm-dd.' in resp.text
+def test_add_basket_item_with_remote_regie(app, user, remote_regie):
+ data = {'amount': 10, 'display_name': 'test item'}
+ url = '%s?email=%s' % (reverse('api-add-basket-item'), user.email)
+ url = sign_url(url, settings.LINGO_API_SIGN_KEY)
+ resp = app.post_json(url, params=data, status=400)
+ assert 'Can not add a basket item to a remote regie.' in resp.text
+
+
def test_cant_pay_if_different_capture_date(app, basket_page, regie, user):
capture1 = (timezone.now() + timedelta(days=1)).date()
capture2 = (timezone.now() + timedelta(days=2)).date()