forked from CGM_Public/pretix_original
Cart: ensure free price input is decimal (PRETIXEU-80N)
Co-authored-by: Phin Wolkwitz <wolkwitz@rami.io>
This commit is contained in:
committed by
GitHub
parent
5ad0f92776
commit
e9b22b7d33
@@ -23,6 +23,7 @@ import json
|
||||
from decimal import Decimal
|
||||
|
||||
import pytest
|
||||
from django.utils import translation
|
||||
from django.utils.timezone import now
|
||||
from django_countries.fields import Country
|
||||
|
||||
@@ -196,7 +197,8 @@ def test_free_price_accepted(item):
|
||||
@pytest.mark.django_db
|
||||
def test_free_price_string(item):
|
||||
item.free_price = True
|
||||
assert get_price(item, custom_price='42,00').gross == Decimal('42.00')
|
||||
with translation.override('de'):
|
||||
assert get_price(item, custom_price='42,00').gross == Decimal('42.00')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@@ -209,7 +211,7 @@ def test_free_price_float(item):
|
||||
def test_free_price_limit(item):
|
||||
item.free_price = True
|
||||
with pytest.raises(ValueError):
|
||||
get_price(item, custom_price=Decimal('200000000'))
|
||||
get_price(item, custom_price=Decimal('200000000000'))
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
|
||||
@@ -635,6 +635,21 @@ class CartTest(CartTestMixin, TestCase):
|
||||
self.assertIsNone(objs[0].variation)
|
||||
self.assertEqual(objs[0].price, 24)
|
||||
|
||||
def test_free_price_numeric(self):
|
||||
self.ticket.free_price = True
|
||||
self.ticket.save()
|
||||
response = self.client.post('/%s/%s/cart/add' % (self.orga.slug, self.event.slug), {
|
||||
'item_%d' % self.ticket.id: '1',
|
||||
'price_%d' % self.ticket.id: 'abcde'
|
||||
}, follow=True)
|
||||
self.assertRedirects(response, '/%s/%s/?require_cookie=true' % (self.orga.slug, self.event.slug),
|
||||
target_status_code=200)
|
||||
doc = BeautifulSoup(response.rendered_content, "lxml")
|
||||
self.assertIn('not a number', doc.select('#error-message')[0].text)
|
||||
with scopes_disabled():
|
||||
objs = list(CartPosition.objects.filter(cart_id=self.session_key, event=self.event))
|
||||
self.assertEqual(len(objs), 0)
|
||||
|
||||
def test_free_price_only_if_allowed(self):
|
||||
self.ticket.free_price = False
|
||||
self.ticket.save()
|
||||
|
||||
@@ -3138,6 +3138,9 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
|
||||
assert cp1.addons.last().item == self.workshop1
|
||||
|
||||
def test_set_addon_free_price(self):
|
||||
self.event.settings.locales = ['de']
|
||||
self.event.settings.locale = 'de'
|
||||
|
||||
with scopes_disabled():
|
||||
self.workshop1.free_price = True
|
||||
self.workshop1.save()
|
||||
|
||||
Reference in New Issue
Block a user