Allow selecting the same add-on multiple times (#1717)

This commit is contained in:
Raphael Michel
2020-07-20 10:21:12 +02:00
committed by GitHub
parent ed3542e219
commit 3c5948d2e0
19 changed files with 743 additions and 335 deletions

View File

@@ -352,7 +352,8 @@ def test_item_detail_addons(token_client, organizer, event, team, item, category
"min_count": 0,
"max_count": 1,
"position": 0,
"price_included": False
"multi_allowed": False,
"price_included": False,
}]
resp = token_client.get('/api/v1/organizers/{}/events/{}/items/{}/'.format(organizer.slug, event.slug,
item.pk))
@@ -575,6 +576,7 @@ def test_item_create_with_addon(token_client, organizer, event, item, category,
"min_count": 0,
"max_count": 10,
"position": 0,
"multi_allowed": False,
"price_included": True
}
]
@@ -620,6 +622,7 @@ def test_item_create_with_addon(token_client, organizer, event, item, category,
"min_count": 0,
"max_count": 10,
"position": 0,
"multi_allowed": False,
"price_included": True
}
]
@@ -663,6 +666,7 @@ def test_item_create_with_addon(token_client, organizer, event, item, category,
"min_count": 110,
"max_count": 10,
"position": 0,
"multi_allowed": False,
"price_included": True
}
]
@@ -706,6 +710,7 @@ def test_item_create_with_addon(token_client, organizer, event, item, category,
"min_count": -1,
"max_count": 10,
"position": 0,
"multi_allowed": False,
"price_included": True
}
]
@@ -920,6 +925,7 @@ def test_item_update(token_client, organizer, event, item, category, item2, cate
"min_count": 0,
"max_count": 10,
"position": 0,
"multi_allowed": False,
"price_included": True
}
]
@@ -1011,6 +1017,7 @@ def test_item_update_with_addon(token_client, organizer, event, item, category):
"min_count": 0,
"max_count": 10,
"position": 0,
"multi_allowed": False,
"price_included": True
}
]
@@ -1372,6 +1379,7 @@ TEST_ADDONS_RES = {
"min_count": 0,
"max_count": 10,
"position": 1,
"multi_allowed": False,
"price_included": False
}
@@ -1410,6 +1418,7 @@ def test_addons_create(token_client, organizer, event, item, category, category2
"min_count": 0,
"max_count": 10,
"position": 1,
"multi_allowed": False,
"price_included": False
},
format='json'
@@ -1427,6 +1436,7 @@ def test_addons_create(token_client, organizer, event, item, category, category2
"min_count": 10,
"max_count": 20,
"position": 2,
"multi_allowed": False,
"price_included": False
},
format='json'
@@ -1441,6 +1451,7 @@ def test_addons_create(token_client, organizer, event, item, category, category2
"min_count": 10,
"max_count": 20,
"position": 2,
"multi_allowed": False,
"price_included": False
},
format='json'

View File

@@ -2222,6 +2222,158 @@ class CartAddonTest(CartTestMixin, TestCase):
])
self.cm.commit()
@classscope(attr='orga')
def test_multi_allowed(self):
cp1 = CartPosition.objects.create(
expires=now() + timedelta(minutes=10), item=self.ticket, price=Decimal('23.00'),
event=self.event, cart_id=self.session_key
)
self.addon1.max_count = 2
self.addon1.multi_allowed = True
self.addon1.save()
self.cm.set_addons([
{
'addon_to': cp1.pk,
'item': self.workshop3.pk,
'variation': self.workshop3a.pk
},
{
'addon_to': cp1.pk,
'item': self.workshop3.pk,
'variation': self.workshop3b.pk
}
])
self.cm.commit()
assert cp1.addons.count() == 2
@classscope(attr='orga')
def test_number_exceeds_max(self):
cp1 = CartPosition.objects.create(
expires=now() + timedelta(minutes=10), item=self.ticket, price=Decimal('23.00'),
event=self.event, cart_id=self.session_key
)
self.addon1.max_count = 2
self.addon1.multi_allowed = True
self.addon1.save()
with self.assertRaises(CartError):
self.cm.set_addons([
{
'addon_to': cp1.pk,
'item': self.workshop3.pk,
'variation': self.workshop3a.pk,
'count': 3,
},
])
self.cm.commit()
assert cp1.addons.count() == 0
@classscope(attr='orga')
def test_number_exceeds_quota(self):
self.workshopquota.size = 1
self.workshopquota.save()
cp1 = CartPosition.objects.create(
expires=now() + timedelta(minutes=10), item=self.ticket, price=Decimal('23.00'),
event=self.event, cart_id=self.session_key
)
self.addon1.max_count = 2
self.addon1.multi_allowed = True
self.addon1.save()
with self.assertRaises(CartError):
self.cm.set_addons([
{
'addon_to': cp1.pk,
'item': self.workshop3.pk,
'variation': self.workshop3a.pk,
'count': 2,
},
])
self.cm.commit()
assert cp1.addons.count() == 1
@classscope(attr='orga')
def test_free_price(self):
self.workshop3.free_price = True
self.workshop3.save()
cp1 = CartPosition.objects.create(
expires=now() + timedelta(minutes=10), item=self.ticket, price=Decimal('23.00'),
event=self.event, cart_id=self.session_key
)
self.addon1.max_count = 5
self.addon1.multi_allowed = True
self.addon1.save()
self.cm = CartManager(event=self.event, cart_id=self.session_key)
self.cm.set_addons([
{
'addon_to': cp1.pk,
'item': self.workshop3.pk,
'variation': self.workshop3a.pk,
'count': 3,
'price': '24.00'
},
])
self.cm.commit()
assert cp1.addons.count() == 3
assert all(a.price == Decimal('24.00') for a in cp1.addons.all())
self.cm = CartManager(event=self.event, cart_id=self.session_key)
self.cm.set_addons([
{
'addon_to': cp1.pk,
'item': self.workshop3.pk,
'variation': self.workshop3a.pk,
'count': 3,
'price': '5.00'
},
])
self.cm.commit()
assert cp1.addons.count() == 3
assert all(a.price == Decimal('12.00') for a in cp1.addons.all())
@classscope(attr='orga')
def test_change_number(self):
cp1 = CartPosition.objects.create(
expires=now() + timedelta(minutes=10), item=self.ticket, price=Decimal('23.00'),
event=self.event, cart_id=self.session_key
)
self.addon1.max_count = 5
self.addon1.multi_allowed = True
self.addon1.save()
self.cm.set_addons([
{
'addon_to': cp1.pk,
'item': self.workshop3.pk,
'variation': self.workshop3a.pk,
'count': 3,
},
])
self.cm.commit()
assert cp1.addons.count() == 3
self.cm = CartManager(event=self.event, cart_id=self.session_key)
self.cm.set_addons([
{
'addon_to': cp1.pk,
'item': self.workshop3.pk,
'variation': self.workshop3a.pk,
'count': 4,
},
])
self.cm.commit()
assert cp1.addons.count() == 4
self.cm = CartManager(event=self.event, cart_id=self.session_key)
self.cm.set_addons([
{
'addon_to': cp1.pk,
'item': self.workshop3.pk,
'variation': self.workshop3a.pk,
'count': 2,
},
])
self.cm.commit()
assert cp1.addons.count() == 2
@classscope(attr='orga')
def test_no_duplicate_items_for_same_cp(self):
cp1 = CartPosition.objects.create(

View File

@@ -2226,8 +2226,8 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
)
response = self.client.post('/%s/%s/checkout/addons/' % (self.orga.slug, self.event.slug), {
'{}_{}-item_{}'.format(cp1.pk, self.workshopcat.pk, self.workshop1.pk): 'on',
'{}_{}-item_{}'.format(cp2.pk, self.workshopcat.pk, self.workshop2.pk): self.workshop2a.pk,
'cp_{}_item_{}'.format(cp1.pk, self.workshop1.pk): '1',
'cp_{}_variation_{}_{}'.format(cp2.pk, self.workshop2.pk, self.workshop2a.pk): '1',
}, follow=True)
self.assertRedirects(response, '/%s/%s/checkout/questions/' % (self.orga.slug, self.event.slug),
target_status_code=200)
@@ -2236,6 +2236,45 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
assert cp2.addons.first().item == self.workshop2
assert cp2.addons.first().variation == self.workshop2a
def test_set_addon_multi(self):
with scopes_disabled():
ItemAddOn.objects.create(base_item=self.ticket, addon_category=self.workshopcat, multi_allowed=True, max_count=2)
cp1 = CartPosition.objects.create(
event=self.event, cart_id=self.session_key, item=self.ticket,
price=23, expires=now() - timedelta(minutes=10)
)
response = self.client.post('/%s/%s/checkout/addons/' % (self.orga.slug, self.event.slug), {
'cp_{}_item_{}'.format(cp1.pk, self.workshop1.pk): '2',
}, follow=True)
self.assertRedirects(response, '/%s/%s/checkout/questions/' % (self.orga.slug, self.event.slug),
target_status_code=200)
with scopes_disabled():
assert cp1.addons.count() == 2
assert cp1.addons.first().item == self.workshop1
assert cp1.addons.last().item == self.workshop1
def test_set_addon_free_price(self):
with scopes_disabled():
self.workshop1.free_price = True
self.workshop1.save()
ItemAddOn.objects.create(base_item=self.ticket, addon_category=self.workshopcat)
cp1 = CartPosition.objects.create(
event=self.event, cart_id=self.session_key, item=self.ticket,
price=23, expires=now() - timedelta(minutes=10)
)
response = self.client.post('/%s/%s/checkout/addons/' % (self.orga.slug, self.event.slug), {
'cp_{}_item_{}'.format(cp1.pk, self.workshop1.pk): '1',
'cp_{}_item_{}_price'.format(cp1.pk, self.workshop1.pk): '999,99',
}, follow=True)
self.assertRedirects(response, '/%s/%s/checkout/questions/' % (self.orga.slug, self.event.slug),
target_status_code=200)
with scopes_disabled():
assert cp1.addons.count() == 1
assert cp1.addons.first().item == self.workshop1
assert cp1.addons.first().price == Decimal('999.99')
def test_set_addons_required(self):
with scopes_disabled():
ItemAddOn.objects.create(base_item=self.ticket, addon_category=self.workshopcat, min_count=1)
@@ -2332,7 +2371,7 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
response = self.client.get('/%s/%s/checkout/questions/' % (self.orga.slug, self.event.slug), follow=True)
self.assertRedirects(response, '/%s/%s/checkout/addons/' % (self.orga.slug, self.event.slug),
target_status_code=200)
assert 'Workshop 1 (+ €42.00)' in response.rendered_content
assert '42.00' in response.rendered_content
def test_set_addons_subevent_net_prices(self):
with scopes_disabled():
@@ -2358,8 +2397,8 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
response = self.client.get('/%s/%s/checkout/questions/' % (self.orga.slug, self.event.slug), follow=True)
self.assertRedirects(response, '/%s/%s/checkout/addons/' % (self.orga.slug, self.event.slug),
target_status_code=200)
assert 'Workshop 1 (+ €35.29 plus 19.00% VAT)' in response.rendered_content
assert 'A (+ €10.08 plus 19.00% VAT)' in response.rendered_content
assert '35.29' in response.rendered_content
assert '10.08' in response.rendered_content
def test_confirm_subevent_presale_not_yet(self):
with scopes_disabled():