Check-in rules: Add now_isoweekday and minutes_since_last_entry (#2577)

This commit is contained in:
Raphael Michel
2022-04-21 17:17:59 +02:00
committed by GitHub
parent 0aff74afc6
commit 316081658a
5 changed files with 222 additions and 7 deletions

View File

@@ -495,6 +495,63 @@ def test_rules_scan_number(position, clist):
assert 'Maximum number of entries' in str(excinfo.value)
@pytest.mark.django_db
def test_rules_scan_minutes_since_last(position, clist):
# Ticket is valid unlimited times, but you always need to wait 3 hours
clist.allow_multiple_entries = True
clist.rules = {"or": [{"<=": [{"var": "minutes_since_last_entry"}, -1]}, {">": [{"var": "minutes_since_last_entry"}, 60 * 3]}]}
clist.save()
with freeze_time("2020-01-01 10:00:00"):
assert OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules), pk=position.pk).exists()
perform_checkin(position, clist, {})
with freeze_time("2020-01-01 12:55:00"):
assert not OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules), pk=position.pk).exists()
with pytest.raises(CheckInError) as excinfo:
perform_checkin(position, clist, {})
assert excinfo.value.code == 'rules'
assert 'Minimum time since last entry' in str(excinfo.value)
with freeze_time("2020-01-01 13:01:00"):
assert OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules), pk=position.pk).exists()
perform_checkin(position, clist, {})
with freeze_time("2020-01-01 15:55:00"):
assert not OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules), pk=position.pk).exists()
with pytest.raises(CheckInError) as excinfo:
perform_checkin(position, clist, {})
assert excinfo.value.code == 'rules'
assert 'Minimum time since last entry' in str(excinfo.value)
with freeze_time("2020-01-01 16:02:00"):
assert OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules), pk=position.pk).exists()
perform_checkin(position, clist, {})
@pytest.mark.django_db
def test_rules_scan_minutes_since_fist(position, clist):
# Ticket is valid unlimited times, but you always need to wait 3 hours
clist.allow_multiple_entries = True
clist.rules = {"or": [{"<=": [{"var": "minutes_since_first_entry"}, -1]}, {"<": [{"var": "minutes_since_first_entry"}, 60 * 3]}]}
clist.save()
with freeze_time("2020-01-01 10:00:00"):
assert OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules), pk=position.pk).exists()
perform_checkin(position, clist, {})
with freeze_time("2020-01-01 12:55:00"):
assert OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules), pk=position.pk).exists()
perform_checkin(position, clist, {})
with freeze_time("2020-01-01 13:01:00"):
assert not OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules), pk=position.pk).exists()
with pytest.raises(CheckInError) as excinfo:
perform_checkin(position, clist, {})
assert excinfo.value.code == 'rules'
assert 'Maximum time since first entry' in str(excinfo.value)
@pytest.mark.django_db
def test_rules_scan_today(event, position, clist):
# Ticket is valid three times per day
@@ -683,6 +740,24 @@ def test_rules_isafter_subevent(position, clist, event):
perform_checkin(position, clist, {})
@pytest.mark.django_db
def test_rules_time_isoweekday(event, position, clist):
# Ticket is valid starting at a custom time
event.settings.timezone = 'Europe/Berlin'
clist.rules = {"==": [{"var": "now_isoweekday"}, 6]}
clist.save()
with freeze_time("2022-04-06 21:55:00+01:00"):
assert not OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules), pk=position.pk).exists()
with pytest.raises(CheckInError) as excinfo:
perform_checkin(position, clist, {})
assert excinfo.value.code == 'rules'
assert 'week day is not Saturday' in str(excinfo.value)
with freeze_time("2022-04-09 22:05:00+01:00"):
assert OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules), pk=position.pk).exists()
perform_checkin(position, clist, {})
@pytest.mark.django_db
def test_rules_reasoning_prefer_close_date(event, position, clist):
# Ticket is valid starting at a custom time