forked from CGM_Public/pretix_original
add empty cart button #161
add failing test for variation item with voucher
This commit is contained in:
committed by
Raphael Michel
parent
a0ce81a538
commit
bf7db945b0
@@ -26,7 +26,7 @@
|
||||
</em>
|
||||
<div class="row checkout-button-row">
|
||||
<div class="col-md-4 col-xs-12">
|
||||
<form method="post" data-asynctask action="{% eventurl request.event "presale:event.cart.remove.all" %}" >
|
||||
<form method="post" data-asynctask action="{% eventurl request.event "presale:event.cart.remove" %}" >
|
||||
{% csrf_token %}
|
||||
{% for line in cart.positions %}
|
||||
{% if line.variation %}
|
||||
|
||||
@@ -14,7 +14,6 @@ import pretix.presale.views.user
|
||||
event_patterns = [
|
||||
url(r'^cart/add$', pretix.presale.views.cart.CartAdd.as_view(), name='event.cart.add'),
|
||||
url(r'^cart/remove$', pretix.presale.views.cart.CartRemove.as_view(), name='event.cart.remove'),
|
||||
url(r'^cart/removeall$', pretix.presale.views.cart.CartRemoveAll.as_view(), name='event.cart.remove.all'),
|
||||
url(r'^checkout/start$', pretix.presale.views.checkout.CheckoutView.as_view(), name='event.checkout.start'),
|
||||
url(r'^redeem$', pretix.presale.views.cart.RedeemView.as_view(),
|
||||
name='event.redeem'),
|
||||
|
||||
@@ -6,7 +6,7 @@ from django.utils.timezone import now
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.views.generic import TemplateView, View
|
||||
|
||||
from pretix.base.models import Quota, Voucher
|
||||
from pretix.base.models import CartPosition, Quota, Voucher
|
||||
from pretix.base.services.cart import (
|
||||
CartError, add_items_to_cart, remove_items_from_cart,
|
||||
)
|
||||
@@ -104,33 +104,10 @@ class CartRemove(EventViewMixin, CartActionMixin, AsyncAction, View):
|
||||
task = remove_items_from_cart
|
||||
|
||||
def get_success_message(self, value):
|
||||
return _('Your cart has been updated.')
|
||||
|
||||
def get_error_message(self, exception):
|
||||
if isinstance(exception, dict) and exception['exc_type'] == 'CartError':
|
||||
return exception['exc_message']
|
||||
elif isinstance(exception, CartError):
|
||||
return str(exception)
|
||||
return super().get_error_message(exception)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
items = self._items_from_post_data()
|
||||
if items:
|
||||
return self.do(self.request.event.id, items, self.request.session.session_key)
|
||||
if CartPosition.objects.filter(cart_id=self.request.session.session_key).exists():
|
||||
return _('Your cart has been updated.')
|
||||
else:
|
||||
if 'ajax' in self.request.GET or 'ajax' in self.request.POST:
|
||||
return JsonResponse({
|
||||
'redirect': self.get_error_url()
|
||||
})
|
||||
else:
|
||||
return redirect(self.get_error_url())
|
||||
|
||||
|
||||
class CartRemoveAll(EventViewMixin, CartActionMixin, AsyncAction, View):
|
||||
task = remove_items_from_cart
|
||||
|
||||
def get_success_message(self, value):
|
||||
return _('Your cart is empty.')
|
||||
return _('Your cart is empty.')
|
||||
|
||||
def get_error_message(self, exception):
|
||||
if isinstance(exception, dict) and exception['exc_type'] == 'CartError':
|
||||
|
||||
@@ -2,6 +2,8 @@ import datetime
|
||||
from datetime import timedelta
|
||||
from decimal import Decimal
|
||||
|
||||
import pytest
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
from django.conf import settings
|
||||
from django.test import TestCase
|
||||
@@ -409,7 +411,7 @@ class CartTest(CartTestMixin, TestCase):
|
||||
'item_%d' % self.ticket.id: '1',
|
||||
}, follow=True)
|
||||
doc = BeautifulSoup(response.rendered_content, "lxml")
|
||||
self.assertIn('updated', doc.select('.alert-success')[0].text)
|
||||
self.assertIn('empty', doc.select('.alert-success')[0].text)
|
||||
self.assertFalse(CartPosition.objects.filter(cart_id=self.session_key, event=self.event).exists())
|
||||
|
||||
def test_remove_variation(self):
|
||||
@@ -421,7 +423,7 @@ class CartTest(CartTestMixin, TestCase):
|
||||
'variation_%d_%d' % (self.shirt.id, self.shirt_red.id): '1',
|
||||
}, follow=True)
|
||||
doc = BeautifulSoup(response.rendered_content, "lxml")
|
||||
self.assertIn('updated', doc.select('.alert-success')[0].text)
|
||||
self.assertIn('empty', doc.select('.alert-success')[0].text)
|
||||
self.assertFalse(CartPosition.objects.filter(cart_id=self.session_key, event=self.event).exists())
|
||||
|
||||
def test_remove_one_of_multiple(self):
|
||||
@@ -453,7 +455,7 @@ class CartTest(CartTestMixin, TestCase):
|
||||
'item_%d' % self.ticket.id: '2',
|
||||
}, follow=True)
|
||||
doc = BeautifulSoup(response.rendered_content, "lxml")
|
||||
self.assertIn('updated', doc.select('.alert-success')[0].text)
|
||||
self.assertIn('empty', doc.select('.alert-success')[0].text)
|
||||
self.assertFalse(CartPosition.objects.filter(cart_id=self.session_key, event=self.event).exists())
|
||||
|
||||
def test_remove_all(self):
|
||||
@@ -469,7 +471,7 @@ class CartTest(CartTestMixin, TestCase):
|
||||
event=self.event, cart_id=self.session_key, item=self.shirt, variation=self.shirt_red,
|
||||
price=14, expires=now() + timedelta(minutes=10)
|
||||
)
|
||||
response = self.client.post('/%s/%s/cart/removeall' % (self.orga.slug, self.event.slug), {
|
||||
response = self.client.post('/%s/%s/cart/remove' % (self.orga.slug, self.event.slug), {
|
||||
'item_%d' % self.ticket.id: '2',
|
||||
'variation_%d_%d' % (self.shirt.id, self.shirt_red.id): '1',
|
||||
}, follow=True)
|
||||
@@ -477,6 +479,23 @@ class CartTest(CartTestMixin, TestCase):
|
||||
self.assertIn('empty', doc.select('.alert-success')[0].text)
|
||||
self.assertFalse(CartPosition.objects.filter(cart_id=self.session_key, event=self.event).exists())
|
||||
|
||||
@pytest.mark.xfail
|
||||
def test_remove_all_same_variation_different_price(self):
|
||||
CartPosition.objects.create(
|
||||
event=self.event, cart_id=self.session_key, item=self.shirt, variation=self.shirt_red,
|
||||
price=14, expires=now() + timedelta(minutes=10)
|
||||
)
|
||||
v = Voucher.objects.create(item=self.shirt, variation=self.shirt_red, price=Decimal('10.00'), event=self.event)
|
||||
self.client.post('/%s/%s/cart/add' % (self.orga.slug, self.event.slug), {
|
||||
'variation_%d_%d_voucher' % (self.shirt.id, self.shirt_red.id): v.code,
|
||||
}, follow=True)
|
||||
response = self.client.post('/%s/%s/cart/remove' % (self.orga.slug, self.event.slug), {
|
||||
'variation_%d_%d' % (self.shirt.id, self.shirt_red.id): ('1', '1'),
|
||||
}, follow=True)
|
||||
doc = BeautifulSoup(response.rendered_content, "lxml")
|
||||
self.assertIn('empty', doc.select('.alert-success')[0].text)
|
||||
self.assertFalse(CartPosition.objects.filter(cart_id=self.session_key, event=self.event).exists())
|
||||
|
||||
def test_remove_most_expensive(self):
|
||||
CartPosition.objects.create(
|
||||
event=self.event, cart_id=self.session_key, item=self.ticket,
|
||||
|
||||
Reference in New Issue
Block a user