lingo: change "remove basket item" API to notify on "notify=true" arg (#15798)
This commit is contained in:
parent
2920c0d87a
commit
693e6155cc
|
@ -201,8 +201,8 @@ class BasketItem(models.Model):
|
|||
self.notification_date = timezone.now()
|
||||
self.save()
|
||||
|
||||
def notify_cancellation(self, skip_notification=False):
|
||||
if not skip_notification:
|
||||
def notify_cancellation(self, notify_origin=False):
|
||||
if notify_origin:
|
||||
self.notify('cancelled')
|
||||
self.cancellation_date = timezone.now()
|
||||
self.save()
|
||||
|
|
|
@ -192,7 +192,8 @@ class RemoveBasketItemApiView(View):
|
|||
|
||||
item = BasketItem.objects.get(id=request_body.get('basket_item_id'),
|
||||
user=user, cancellation_date__isnull=True)
|
||||
item.notify_cancellation(skip_notification=bool(request_body.get('skip_notification')))
|
||||
notify_origin = bool(request_body.get('notify', 'false') == 'true')
|
||||
item.notify_cancellation(notify_origin=notify_origin)
|
||||
|
||||
response = HttpResponse(content_type='application/json')
|
||||
response.write(json.dumps({'result': 'success'}))
|
||||
|
@ -580,7 +581,7 @@ class CancelItemView(DetailView):
|
|||
messages.error(request, _('This item cannot be removed.'))
|
||||
return HttpResponseRedirect(get_basket_url())
|
||||
try:
|
||||
self.get_object().notify_cancellation()
|
||||
self.get_object().notify_cancellation(notify_origin=True)
|
||||
except requests.exceptions.HTTPError:
|
||||
messages.error(request, _('An error occured when removing the item.'))
|
||||
return HttpResponseRedirect(get_basket_url())
|
||||
|
|
|
@ -221,26 +221,40 @@ def test_cancel_basket_item(key, regie, user):
|
|||
User.objects.get_or_create(email=user_email)
|
||||
url = '%s?email=%s&orig=wcs' % (reverse('api-add-basket-item'), user_email)
|
||||
url = sign_url(url, key)
|
||||
data = {'amount': 42, 'display_name': 'test amount', 'url': 'http://example.com'}
|
||||
data = {'amount': 42, 'display_name': 'test amount', 'url':
|
||||
'http://example.com/', 'notify': 'true'}
|
||||
resp = client.post(url, json.dumps(data), content_type='application/json')
|
||||
assert resp.status_code == 200
|
||||
assert json.loads(resp.content)['result'] == 'success'
|
||||
assert BasketItem.objects.filter(amount=42, cancellation_date__isnull=True).exists()
|
||||
basket_item_id = json.loads(resp.content)['id']
|
||||
|
||||
data = {'amount': 21, 'display_name': 'test amount', 'url': 'http://example.com'}
|
||||
data = {'amount': 21, 'display_name': 'test amount', 'url': 'http://example.net/'}
|
||||
resp = client.post(url, json.dumps(data), content_type='application/json')
|
||||
assert resp.status_code == 200
|
||||
assert json.loads(resp.content)['result'] == 'success'
|
||||
assert BasketItem.objects.filter(amount=42, cancellation_date__isnull=True).exists()
|
||||
assert BasketItem.objects.filter(amount=21, cancellation_date__isnull=True).exists()
|
||||
basket_item_id_2 = json.loads(resp.content)['id']
|
||||
|
||||
with mock.patch('combo.utils.RequestsSession.request') as request:
|
||||
url = '%s?email=%s&orig=wcs' % (reverse('api-remove-basket-item'), user_email)
|
||||
url = sign_url(url, key)
|
||||
data = {'basket_item_id': basket_item_id, 'notify': 'true'}
|
||||
resp = client.post(url, json.dumps(data), content_type='application/json')
|
||||
assert request.call_args[0] == ('POST', u'http://example.com/jump/trigger/cancelled')
|
||||
assert not BasketItem.objects.filter(amount=42, cancellation_date__isnull=True).exists()
|
||||
assert BasketItem.objects.filter(amount=21, cancellation_date__isnull=True).exists()
|
||||
|
||||
with mock.patch('combo.utils.RequestsSession.request') as request:
|
||||
url = '%s?email=%s&orig=wcs' % (reverse('api-remove-basket-item'), user_email)
|
||||
url = sign_url(url, key)
|
||||
data = {'basket_item_id': basket_item_id_2}
|
||||
resp = client.post(url, json.dumps(data), content_type='application/json')
|
||||
assert request.call_count == 0
|
||||
assert not BasketItem.objects.filter(amount=42, cancellation_date__isnull=True).exists()
|
||||
assert not BasketItem.objects.filter(amount=21, cancellation_date__isnull=True).exists()
|
||||
|
||||
url = '%s?email=%s&orig=wcs' % (reverse('api-remove-basket-item'), user_email)
|
||||
url = sign_url(url, key)
|
||||
data = {'basket_item_id': basket_item_id, 'skip_notification': True}
|
||||
resp = client.post(url, json.dumps(data), content_type='application/json')
|
||||
assert not BasketItem.objects.filter(amount=42, cancellation_date__isnull=True).exists()
|
||||
assert BasketItem.objects.filter(amount=21, cancellation_date__isnull=True).exists()
|
||||
|
||||
def test_cancel_basket_item_from_cell(key, regie, user):
|
||||
page = Page(title='xxx', slug='test_basket_cell', template_name='standard')
|
||||
|
|
Loading…
Reference in New Issue