Ejemplo n.º 1
0
def test_rules_scan_days(event, position, clist):
    # Ticket is valid unlimited times, but only on two arbitrary days
    event.settings.timezone = 'Europe/Berlin'
    clist.allow_multiple_entries = True
    clist.rules = {"or": [{">": [{"var": "entries_today"}, 0]}, {"<": [{"var": "entries_days"}, 2]}]}
    clist.save()
    with freeze_time("2020-01-01 10:00:00"):
        perform_checkin(position, clist, {})
        perform_checkin(position, clist, {})
        assert OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules), pk=position.pk).exists()
        perform_checkin(position, clist, {})

    with freeze_time("2020-01-03 10:00:00"):
        perform_checkin(position, clist, {})
        perform_checkin(position, clist, {})
        perform_checkin(position, clist, {})
        assert OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules), pk=position.pk).exists()
        perform_checkin(position, clist, {})

    with freeze_time("2020-01-03 22:50:00"):
        assert OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules), pk=position.pk).exists()
        perform_checkin(position, clist, {})

    with freeze_time("2020-01-03 23:50: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 number of days with an entry exceeded.' in str(excinfo.value)
Ejemplo n.º 2
0
def test_rules_variation(item, position, clist):
    v1 = item.variations.create(value="A")
    v2 = item.variations.create(value="B")
    position.variation = v2
    position.save()
    clist.rules = {
        "inList": [
            {"var": "variation"}, {
                "objectList": [
                    {"lookup": ["variation", str(v1.pk), "Ticket – A"]},
                ]
            }
        ]
    }
    clist.save()
    with pytest.raises(CheckInError) as excinfo:
        perform_checkin(position, clist, {})
    assert not OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules), pk=position.pk).exists()
    assert excinfo.value.code == 'rules'
    assert 'Ticket type not allowed' in str(excinfo.value)

    clist.rules = {
        "inList": [
            {"var": "variation"}, {
                "objectList": [
                    {"lookup": ["variation", str(v1.pk), "Ticket – A"]},
                    {"lookup": ["variation", str(v2.pk), "Ticket – B"]},
                ]
            }
        ]
    }
    clist.save()
    assert OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules), pk=position.pk).exists()
    perform_checkin(position, clist, {})
Ejemplo n.º 3
0
def test_rules_scan_today(event, position, clist):
    # Ticket is valid three times per day
    event.settings.timezone = 'Europe/Berlin'
    clist.allow_multiple_entries = True
    clist.rules = {"<": [{"var": "entries_today"}, 3]}
    clist.save()
    with freeze_time("2020-01-01 10:00:00"):
        perform_checkin(position, clist, {})
        perform_checkin(position, clist, {})
        perform_checkin(position, clist, {}, type=Checkin.TYPE_EXIT)
        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 today' in str(excinfo.value)

    with freeze_time("2020-01-01 22:50: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 number of entries today' in str(excinfo.value)

    with freeze_time("2020-01-01 23:10:00"):
        assert OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules), pk=position.pk).exists()
        perform_checkin(position, clist, {})
        perform_checkin(position, clist, {})
        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 today' in str(excinfo.value)
Ejemplo n.º 4
0
def test_rules_isafter_subevent(position, clist, event):
    event.has_subevents = True
    event.save()
    event.settings.timezone = 'Europe/Berlin'
    se1 = event.subevents.create(name="Foo",
                                 date_from=event.timezone.localize(
                                     datetime(2020, 2, 1, 12, 0, 0)))
    position.subevent = se1
    position.save()
    clist.rules = {
        "isAfter": [{
            "var": "now"
        }, {
            "buildTime": ["date_admission"]
        }]
    }
    clist.save()
    with freeze_time("2020-02-01 10:51: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'

    with freeze_time("2020-02-01 11:01:00"):
        assert OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules),
                                            pk=position.pk).exists()
        perform_checkin(position, clist, {})
Ejemplo n.º 5
0
def test_rules_product(event, position, clist):
    i2 = event.items.create(name="Ticket", default_price=3, admission=True)
    clist.rules = {
        "inList": [
            {"var": "product"}, {
                "objectList": [
                    {"lookup": ["product", str(i2.pk), "Ticket"]},
                ]
            }
        ]
    }
    clist.save()
    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 'Ticket type not allowed' in str(excinfo.value)

    clist.rules = {
        "inList": [
            {"var": "product"}, {
                "objectList": [
                    {"lookup": ["product", str(i2.pk), "Ticket"]},
                    {"lookup": ["product", str(position.item.pk), "Ticket"]},
                ]
            }
        ]
    }
    clist.save()
    assert OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules), pk=position.pk).exists()
    perform_checkin(position, clist, {})
Ejemplo n.º 6
0
def test_rules_time_isafter_no_tolerance(event, position, clist):
    # Ticket is valid only after admission time
    event.settings.timezone = 'Europe/Berlin'
    event.date_from = event.timezone.localize(datetime(2020, 1, 1, 12, 0, 0))
    # also tests that date_admission falls back to date_from
    event.save()
    clist.rules = {
        "isAfter": [{
            "var": "now"
        }, {
            "buildTime": ["date_admission"]
        }]
    }
    clist.save()
    with freeze_time("2020-01-01 10:51: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'

    with freeze_time("2020-01-01 11:01:00"):
        assert OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules),
                                            pk=position.pk).exists()
        perform_checkin(position, clist, {})
Ejemplo n.º 7
0
def test_rules_time_isbefore_with_tolerance(event, position, clist):
    # Ticket is valid until 10 minutes after end time
    event.settings.timezone = 'Europe/Berlin'
    event.date_to = event.timezone.localize(datetime(2020, 1, 1, 12, 0, 0))
    event.save()
    clist.rules = {
        "isBefore": [{
            "var": "now"
        }, {
            "buildTime": ["date_to"]
        }, 10]
    }
    clist.save()
    with freeze_time("2020-01-01 11:11: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 'Only allowed before 12:10' in str(excinfo.value)

    with freeze_time("2020-01-01 11:09:00"):
        assert OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules),
                                            pk=position.pk).exists()
        perform_checkin(position, clist, {})
Ejemplo n.º 8
0
def test_rules_time_isafter_custom_datetime(event, position, clist):
    # Ticket is valid starting at a custom time
    event.settings.timezone = 'Europe/Berlin'
    clist.rules = {"isAfter": [{"var": "now"}, {"buildTime": ["custom", "2020-01-01T23:00:00.000+01:00"]}, None]}
    clist.save()
    with freeze_time("2020-01-01 21:55:00+00: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'

    with freeze_time("2020-01-01 22:05:00+00:00"):
        assert OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules), pk=position.pk).exists()
        perform_checkin(position, clist, {})
Ejemplo n.º 9
0
def test_rules_scan_number(position, clist):
    # Ticket is valid three times
    clist.allow_multiple_entries = True
    clist.rules = {"<": [{"var": "entries_number"}, 3]}
    clist.save()
    assert OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules), pk=position.pk).exists()
    perform_checkin(position, clist, {})
    perform_checkin(position, clist, {})
    perform_checkin(position, clist, {}, type=Checkin.TYPE_EXIT)
    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'
Ejemplo n.º 10
0
def test_rules_simple(position, clist):
    clist.rules = {'and': [False, True]}
    clist.save()
    with pytest.raises(CheckInError) as excinfo:
        perform_checkin(position, clist, {})
    perform_checkin(position, clist, {}, type='exit')
    assert excinfo.value.code == 'rules'

    clist.rules = {'and': [True, True]}
    clist.save()

    assert OrderPosition.objects.filter(SQLLogic(clist).apply(clist.rules), pk=position.pk).exists()
    perform_checkin(position, clist, {})
Ejemplo n.º 11
0
 def check_rules_qs(self, queryset, name, value):
     if not self.checkinlist.rules:
         return queryset
     return queryset.filter(SQLLogic(self.checkinlist).apply(self.checkinlist.rules))