mirror of
https://github.com/pretix/pretix.git
synced 2026-05-04 15:04:03 +00:00
Check-in rules: New variables (#3521)
This commit is contained in:
@@ -562,6 +562,44 @@ def test_rules_variation(item, position, clist):
|
||||
perform_checkin(position, clist, {})
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_rules_gate(event, item, position, clist):
|
||||
g1 = event.organizer.gates.create(name="Gate 1")
|
||||
g2 = event.organizer.gates.create(name="Gate 2")
|
||||
clist.rules = {
|
||||
"inList": [
|
||||
{"var": "gate"}, {
|
||||
"objectList": [
|
||||
{"lookup": ["gate", str(g1.pk), "Gate 1"]},
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
clist.save()
|
||||
with pytest.raises(CheckInError):
|
||||
perform_checkin(position, clist, {}, gate=None)
|
||||
with pytest.raises(CheckInError) as excinfo:
|
||||
perform_checkin(position, clist, {}, gate=g2)
|
||||
assert not OrderPosition.objects.filter(SQLLogic(clist, gate=g2).apply(clist.rules), pk=position.pk).exists()
|
||||
assert not OrderPosition.objects.filter(SQLLogic(clist, gate=None).apply(clist.rules), pk=position.pk).exists()
|
||||
assert excinfo.value.code == 'rules'
|
||||
assert 'Wrong entrance gate' in str(excinfo.value)
|
||||
|
||||
clist.rules = {
|
||||
"inList": [
|
||||
{"var": "gate"}, {
|
||||
"objectList": [
|
||||
{"lookup": ["gate", str(g1.pk), "Gate 1"]},
|
||||
{"lookup": ["gate", str(g2.pk), "Gate 2"]},
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
clist.save()
|
||||
assert OrderPosition.objects.filter(SQLLogic(clist, gate=g2).apply(clist.rules), pk=position.pk).exists()
|
||||
perform_checkin(position, clist, {}, gate=g2)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_rules_scan_number(position, clist):
|
||||
# Ticket is valid three times
|
||||
@@ -708,6 +746,106 @@ def test_rules_scan_days(event, position, clist):
|
||||
assert 'Maximum number of days with an entry exceeded.' in str(excinfo.value)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_rules_entries_since(event, position, clist):
|
||||
# Ticket is valid once before X and once after X
|
||||
event.settings.timezone = 'Europe/Berlin'
|
||||
clist.allow_multiple_entries = True
|
||||
clist.rules = {
|
||||
"or": [
|
||||
{"<=": [{"var": "entries_number"}, 0]},
|
||||
{"and": [
|
||||
{"isAfter": [{"var": "now"}, {"buildTime": ["custom", "2020-01-01T23:00:00.000+01:00"]}, 0]},
|
||||
{"<=": [{"entries_since": [{"buildTime": ["custom", "2020-01-01T23:00:00.000+01:00"]}]}, 0]},
|
||||
]},
|
||||
],
|
||||
}
|
||||
clist.save()
|
||||
with freeze_time("2020-01-01 22:00:00+01:00"):
|
||||
assert OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules), pk=position.pk).exists()
|
||||
perform_checkin(position, clist, {})
|
||||
|
||||
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 number of entries exceeded' in str(excinfo.value)
|
||||
|
||||
with freeze_time("2020-01-01 23:10:00+01:00"):
|
||||
assert OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules), pk=position.pk).exists()
|
||||
perform_checkin(position, clist, {})
|
||||
|
||||
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 number of entries since 23:00 exceeded' in str(excinfo.value)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_rules_entries_since_time_of_day(event, position, clist):
|
||||
# Ticket is valid daily once before X and once after X
|
||||
event.settings.timezone = 'Europe/Berlin'
|
||||
clist.allow_multiple_entries = True
|
||||
clist.rules = {
|
||||
"or": [
|
||||
{"<=": [{"var": "entries_today"}, 0]},
|
||||
{"and": [
|
||||
{"isAfter": [{"var": "now"}, {"buildTime": ["customtime", "23:00:00"]}, 0]},
|
||||
{"<=": [{"entries_since": [{"buildTime": ["customtime", "23:00:00"]}]}, 0]},
|
||||
]},
|
||||
],
|
||||
}
|
||||
clist.save()
|
||||
|
||||
for t in ["2020-01-01 22:00:00+01:00", "2020-01-01 23:01:00+01:00", "2020-01-02 22:00:00+01:00", "2020-01-02 23:01:00+01:00"]:
|
||||
with freeze_time(t):
|
||||
assert OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules), pk=position.pk).exists()
|
||||
perform_checkin(position, clist, {})
|
||||
|
||||
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'
|
||||
if now().astimezone(event.timezone).hour < 23:
|
||||
assert 'Maximum number of entries today exceeded' in str(excinfo.value)
|
||||
else:
|
||||
assert 'Maximum number of entries since 23:00 exceeded' in str(excinfo.value)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_rules_entries_before(event, position, clist):
|
||||
# Ticket is valid after 23:00 only if people already showed up before
|
||||
event.settings.timezone = 'Europe/Berlin'
|
||||
clist.allow_multiple_entries = True
|
||||
clist.rules = {
|
||||
"or": [
|
||||
{"isBefore": [{"var": "now"}, {"buildTime": ["custom", "2020-01-01T23:00:00.000+01:00"]}, 0]},
|
||||
{"and": [
|
||||
{"isAfter": [{"var": "now"}, {"buildTime": ["custom", "2020-01-01T23:00:00.000+01:00"]}, 0]},
|
||||
{">=": [{"entries_before": [{"buildTime": ["custom", "2020-01-01T23:00:00.000+01:00"]}]}, 1]},
|
||||
]},
|
||||
],
|
||||
}
|
||||
clist.save()
|
||||
|
||||
with freeze_time("2020-01-01 22:00:00+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 23:10:00+01:00"):
|
||||
assert OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules), pk=position.pk).exists()
|
||||
perform_checkin(position, clist, {})
|
||||
|
||||
position.all_checkins.all().delete()
|
||||
|
||||
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 number of entries before 23:00 exceeded' in str(excinfo.value)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_rules_time_isafter_tolerance(event, position, clist):
|
||||
# Ticket is valid starting 10 minutes before admission time
|
||||
|
||||
Reference in New Issue
Block a user