Add option to automatically check out all attendees at night (#1819)

This commit is contained in:
Raphael Michel
2020-10-21 18:26:57 +02:00
committed by GitHub
parent ffde521fcb
commit e3d9b3546d
11 changed files with 151 additions and 8 deletions

View File

@@ -143,6 +143,7 @@ TEST_LIST_RES = {
"allow_multiple_entries": False,
"allow_entry_after_exit": True,
"subevent": None,
"exit_all_at": None,
"rules": {}
}

View File

@@ -10,7 +10,7 @@ from freezegun import freeze_time
from pretix.base.models import Checkin, Event, Order, OrderPosition, Organizer
from pretix.base.services.checkin import (
CheckInError, RequiredQuestionsError, perform_checkin,
CheckInError, RequiredQuestionsError, perform_checkin, process_exit_all,
)
@@ -22,6 +22,7 @@ def event():
date_from=now(),
plugins='pretix.plugins.banktransfer'
)
event.settings.timezone = 'Europe/Berlin'
with scope(organizer=o):
yield event
@@ -600,3 +601,39 @@ def test_position_queries(django_assert_num_queries, position, clist):
perform_checkin(position, clist, {})
if 'sqlite' not in settings.DATABASES['default']['ENGINE']:
assert any('FOR UPDATE' in s['sql'] for s in captured)
@pytest.mark.django_db(transaction=True)
def test_auto_checkout_at_correct_time(event, position, clist):
clist.exit_all_at = event.timezone.localize(datetime(2020, 1, 2, 3, 0))
clist.save()
with freeze_time("2020-01-01 10:00:00+01:00"):
perform_checkin(position, clist, {})
with freeze_time("2020-01-02 02:55:00+01:00"):
process_exit_all(sender=None)
assert position.checkins.count() == 1
with freeze_time("2020-01-02 03:05:00+01:00"):
process_exit_all(sender=None)
assert clist.inside_count == 0
assert position.checkins.count() == 2
assert position.checkins.first().type == Checkin.TYPE_EXIT
clist.refresh_from_db()
assert clist.exit_all_at == event.timezone.localize(datetime(2020, 1, 3, 3, 0))
@pytest.mark.django_db(transaction=True)
def test_auto_check_out_only_if_checked_in(event, position, clist):
clist.exit_all_at = event.timezone.localize(datetime(2020, 1, 2, 3, 0))
clist.save()
with freeze_time("2020-01-02 03:05:00+01:00"):
process_exit_all(sender=None)
assert position.checkins.count() == 0
with freeze_time("2020-01-02 04:05:00+01:00"):
perform_checkin(position, clist, {})
with freeze_time("2020-01-02 04:10:00+01:00"):
perform_checkin(position, clist, {}, type=Checkin.TYPE_EXIT)
with freeze_time("2020-01-03 03:05:00+01:00"):
process_exit_all(sender=None)
assert position.checkins.count() == 2

View File

@@ -4,6 +4,7 @@ from decimal import Decimal
import pytest
from django.utils.timezone import now
from django_scopes import scopes_disabled
from freezegun import freeze_time
from pretix.base.models import (
Checkin, Event, Item, ItemAddOn, ItemCategory, LogEntry, Order,
@@ -398,6 +399,7 @@ class CheckinListFormTest(SoupTest):
organizer=self.orga1, name='30C3', slug='30c3',
date_from=datetime(2013, 12, 26, tzinfo=timezone.utc),
)
self.event1.settings.timezone = 'Europe/Berlin'
t = Team.objects.create(organizer=self.orga1, can_change_event_settings=True, can_view_orders=True)
t.members.add(self.user)
t.limit_events.add(self.event1)
@@ -432,6 +434,32 @@ class CheckinListFormTest(SoupTest):
with scopes_disabled():
assert list(cl.limit_products.all()) == [self.item_ticket]
@freeze_time("2020-01-02 02:55:00+01:00")
def test_update_exit_all_at_current_day(self):
with scopes_disabled():
cl = self.event1.checkin_lists.create(name='All', all_products=True)
doc = self.get_doc('/control/event/%s/%s/checkinlists/%s/change' % (self.orga1.slug, self.event1.slug, cl.id))
form_data = extract_form_fields(doc.select('.container-fluid form')[0])
form_data['exit_all_at'] = '03:00:00'
doc = self.post_doc('/control/event/%s/%s/checkinlists/%s/change' % (self.orga1.slug, self.event1.slug, cl.id),
form_data)
assert doc.select(".alert-success")
cl.refresh_from_db()
assert cl.exit_all_at == self.event1.timezone.localize(datetime(2020, 1, 2, 3, 0))
@freeze_time("2020-01-02 03:05:00+01:00")
def test_update_exit_all_at_next_day(self):
with scopes_disabled():
cl = self.event1.checkin_lists.create(name='All', all_products=True)
doc = self.get_doc('/control/event/%s/%s/checkinlists/%s/change' % (self.orga1.slug, self.event1.slug, cl.id))
form_data = extract_form_fields(doc.select('.container-fluid form')[0])
form_data['exit_all_at'] = '03:00:00'
doc = self.post_doc('/control/event/%s/%s/checkinlists/%s/change' % (self.orga1.slug, self.event1.slug, cl.id),
form_data)
assert doc.select(".alert-success")
cl.refresh_from_db()
assert cl.exit_all_at == self.event1.timezone.localize(datetime(2020, 1, 3, 3, 0))
def test_delete(self):
with scopes_disabled():
cl = self.event1.checkin_lists.create(name='All', all_products=True)