mirror of
https://github.com/pretix/pretix.git
synced 2026-05-26 18:43:59 +00:00
add test where in the same transaction:
- one product in the cart is expired and sold out, and therefore can't be renewed - another product is expired but still available, so it can be renewed - a new product is successfully added
This commit is contained in:
@@ -1258,15 +1258,23 @@ class CartTest(CartTestMixin, TestCase):
|
|||||||
'item_%d' % (self.ticket.id,): '1'
|
'item_%d' % (self.ticket.id,): '1'
|
||||||
}, follow=True)
|
}, follow=True)
|
||||||
cp.refresh_from_db()
|
cp.refresh_from_db()
|
||||||
self.assertEqual(cp.expires, start_time + timedelta(minutes=20) + self.cart_reservation_time)
|
with scopes_disabled():
|
||||||
self.assertEqual(cp.max_extend, max_extend)
|
positions = list(CartPosition.objects.filter(cart_id=cp.cart_id))
|
||||||
|
self.assertEqual(len(positions), 2)
|
||||||
|
for pos in positions:
|
||||||
|
self.assertEqual(pos.expires, start_time + timedelta(minutes=20) + self.cart_reservation_time)
|
||||||
|
self.assertEqual(pos.max_extend, max_extend)
|
||||||
with freezegun.freeze_time(start_time + timedelta(minutes=45)):
|
with freezegun.freeze_time(start_time + timedelta(minutes=45)):
|
||||||
self.client.post('/%s/%s/cart/add' % (self.orga.slug, self.event.slug), {
|
self.client.post('/%s/%s/cart/add' % (self.orga.slug, self.event.slug), {
|
||||||
'item_%d' % (self.ticket.id,): '1'
|
'item_%d' % (self.ticket.id,): '1'
|
||||||
}, follow=True)
|
}, follow=True)
|
||||||
cp.refresh_from_db()
|
cp.refresh_from_db()
|
||||||
self.assertEqual(cp.expires, max_extend)
|
with scopes_disabled():
|
||||||
self.assertEqual(cp.max_extend, max_extend)
|
positions = list(CartPosition.objects.filter(cart_id=cp.cart_id))
|
||||||
|
self.assertEqual(len(positions), 3)
|
||||||
|
for pos in positions:
|
||||||
|
self.assertEqual(pos.expires, max_extend)
|
||||||
|
self.assertEqual(pos.max_extend, max_extend)
|
||||||
with freezegun.freeze_time(start_time + timedelta(days=1)):
|
with freezegun.freeze_time(start_time + timedelta(days=1)):
|
||||||
self.client.post('/%s/%s/cart/add' % (self.orga.slug, self.event.slug), {
|
self.client.post('/%s/%s/cart/add' % (self.orga.slug, self.event.slug), {
|
||||||
'item_%d' % (self.ticket.id,): '1'
|
'item_%d' % (self.ticket.id,): '1'
|
||||||
@@ -1365,6 +1373,28 @@ class CartTest(CartTestMixin, TestCase):
|
|||||||
with scopes_disabled():
|
with scopes_disabled():
|
||||||
self.assertFalse(CartPosition.objects.filter(id=cp1.id).exists())
|
self.assertFalse(CartPosition.objects.filter(id=cp1.id).exists())
|
||||||
|
|
||||||
|
def test_expired_renew_fails_partially_and_add_succeeds(self):
|
||||||
|
self.quota_tickets.size = 0
|
||||||
|
self.quota_tickets.save()
|
||||||
|
with scopes_disabled():
|
||||||
|
cp1 = CartPosition.objects.create(
|
||||||
|
event=self.event, cart_id=self.session_key, item=self.ticket,
|
||||||
|
price=23, expires=now() - timedelta(minutes=10), max_extend=now() + 10 * self.cart_reservation_time
|
||||||
|
)
|
||||||
|
cp2 = CartPosition.objects.create(
|
||||||
|
event=self.event, cart_id=self.session_key, item=self.shirt, variation=self.shirt_blue,
|
||||||
|
price=23, expires=now() - timedelta(minutes=10), max_extend=now() + 10 * self.cart_reservation_time
|
||||||
|
)
|
||||||
|
response = self.client.post('/%s/%s/cart/add' % (self.orga.slug, self.event.slug), {
|
||||||
|
'variation_%d_%d' % (self.shirt.id, self.shirt_red.id): '1',
|
||||||
|
}, follow=True)
|
||||||
|
doc = BeautifulSoup(response.rendered_content, "lxml")
|
||||||
|
self.assertIn('no longer available', doc.select('.alert-danger')[0].text)
|
||||||
|
with scopes_disabled():
|
||||||
|
self.assertFalse(CartPosition.objects.filter(id=cp1.id).exists())
|
||||||
|
self.assertTrue(CartPosition.objects.filter(id=cp2.id).exists())
|
||||||
|
self.assertTrue(CartPosition.objects.filter(variation_id=self.shirt_red.id).exists())
|
||||||
|
|
||||||
def test_subevent_renew_expired_successfully(self):
|
def test_subevent_renew_expired_successfully(self):
|
||||||
self.event.has_subevents = True
|
self.event.has_subevents = True
|
||||||
self.event.save()
|
self.event.save()
|
||||||
|
|||||||
Reference in New Issue
Block a user