lingo: do not add a basket item to a remote regie (#27854)

This commit is contained in:
Lauréline Guérin 2019-10-23 11:41:06 +02:00
parent 818ae481c7
commit fbfeb64a83
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 33 additions and 0 deletions

View File

@ -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

View File

@ -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()