Allow to create blocking vouchers for items with unspecified variation (#3932)

This commit is contained in:
Raphael Michel
2024-02-29 16:45:41 +01:00
committed by GitHub
parent 5deb1a8c69
commit 6bf23b0fdd
4 changed files with 56 additions and 17 deletions

View File

@@ -283,6 +283,29 @@ class QuotaTestCase(BaseQuotaTestCase):
v.save()
self.assertEqual(self.var1.check_quotas(), (Quota.AVAILABILITY_ORDERED, 0))
@classscope(attr='o')
def test_voucher_all_variations(self):
self.quota.variations.add(self.var1)
self.quota.size = 1
self.quota.save()
self.quota2 = Quota.objects.create(name="Test", size=2, event=self.event)
self.quota2.variations.add(self.var2)
self.quota3 = Quota.objects.create(name="Test", size=2, event=self.event)
self.quota3.variations.add(self.var3)
v = Voucher.objects.create(item=self.item2, event=self.event)
self.assertEqual(self.var1.check_quotas(), (Quota.AVAILABILITY_OK, 1))
self.assertEqual(self.var2.check_quotas(), (Quota.AVAILABILITY_OK, 2))
self.assertEqual(self.var3.check_quotas(), (Quota.AVAILABILITY_OK, 2))
v.block_quota = True
v.save()
self.assertEqual(self.var1.check_quotas(), (Quota.AVAILABILITY_ORDERED, 0))
self.assertEqual(self.var2.check_quotas(), (Quota.AVAILABILITY_OK, 1))
self.assertEqual(self.var3.check_quotas(), (Quota.AVAILABILITY_OK, 2))
@classscope(attr='o')
def test_voucher_quota(self):
self.quota.variations.add(self.var1)
@@ -979,9 +1002,8 @@ class VoucherTestCase(BaseQuotaTestCase):
@classscope(attr='o')
def test_voucher_specify_variation_for_block_quota(self):
with self.assertRaises(ValidationError):
v = Voucher(item=self.item2, block_quota=True, event=self.event)
v.clean()
v = Voucher(item=self.item2, block_quota=True, event=self.event)
v.clean()
@classscope(attr='o')
def test_voucher_no_item_but_variation(self):

View File

@@ -254,7 +254,7 @@ class VoucherFormTest(SoupTestMixin, TransactionTestCase):
self._create_voucher({
'itemvar': '%d' % self.shirt.pk,
'block_quota': 'on'
}, expected_failure=True)
})
def test_create_blocking_item_voucher_quota_full_invalid(self):
self.quota_shirts.size = 0