Allow quotas to "close" when once full (#1344)

* Model

* Some UI

* API and logging

* Permission check

* Add tests

* Move option around
This commit is contained in:
Raphael Michel
2019-07-16 14:02:27 +02:00
committed by GitHub
parent c1e2fb36ba
commit a02ea45dba
16 changed files with 219 additions and 12 deletions

View File

@@ -1386,7 +1386,9 @@ TEST_QUOTA_RES = {
"size": 200,
"items": [],
"variations": [],
"subevent": None
"subevent": None,
"close_when_sold_out": False,
"closed": False
}
@@ -1593,6 +1595,30 @@ def test_quota_update(token_client, organizer, event, quota, item):
assert quota.all_logentries().count() == 1
@pytest.mark.django_db
def test_quota_update_closed(token_client, organizer, event, quota, item):
resp = token_client.patch(
'/api/v1/organizers/{}/events/{}/quotas/{}/'.format(organizer.slug, event.slug, quota.pk),
{
"closed": True,
},
format='json'
)
assert resp.status_code == 200
with scopes_disabled():
quota = Quota.objects.get(pk=resp.data['id'])
assert quota.all_logentries().filter(action_type="pretix.event.quota.closed").count() == 1
resp = token_client.patch(
'/api/v1/organizers/{}/events/{}/quotas/{}/'.format(organizer.slug, event.slug, quota.pk),
{
"closed": False,
},
format='json'
)
assert resp.status_code == 200
assert quota.all_logentries().filter(action_type="pretix.event.quota.opened").count() == 1
@pytest.mark.django_db
def test_quota_update_unchanged(token_client, organizer, event, quota, item):
resp = token_client.patch(

View File

@@ -483,6 +483,24 @@ class QuotaTestCase(BaseQuotaTestCase):
self.event.has_subevents = False
self.event.save()
@classscope(attr='o')
def test_close_when_full_on_calculation(self):
self.quota.close_when_sold_out = True
self.quota.size = 0
self.quota.save()
assert not self.quota.closed
self.quota.availability()
self.quota.refresh_from_db()
assert self.quota.closed
assert self.quota.all_logentries().filter(action_type="pretix.event.quota.closed").exists()
@classscope(attr='o')
def test_closed_reports_as_sold_out(self):
self.quota.closed = True
self.quota.size = 100
self.quota.save()
assert self.quota.availability() == (Quota.AVAILABILITY_ORDERED, 0)
class BundleQuotaTestCase(BaseQuotaTestCase):
def setUp(self):

View File

@@ -338,6 +338,28 @@ class QuotaTest(ItemFormTest):
with scopes_disabled():
assert not Quota.objects.filter(id=c.id).exists()
def test_reopen(self):
with scopes_disabled():
c = Quota.objects.create(event=self.event1, name="Full house", size=500,
close_when_sold_out=True, closed=True)
self.post_doc('/control/event/%s/%s/quotas/%s/' % (self.orga1.slug, self.event1.slug, c.id),
{'reopen': 'true'})
with scopes_disabled():
c.refresh_from_db()
assert not c.closed
assert c.close_when_sold_out
def test_reopen_and_disable(self):
with scopes_disabled():
c = Quota.objects.create(event=self.event1, name="Full house", size=500,
close_when_sold_out=True, closed=True)
self.post_doc('/control/event/%s/%s/quotas/%s/' % (self.orga1.slug, self.event1.slug, c.id),
{'disable': 'true'})
with scopes_disabled():
c.refresh_from_db()
assert not c.closed
assert not c.close_when_sold_out
class ItemsTest(ItemFormTest):