Projet

Général

Profil

0001-api-fix-waiting-list-condition-in-RecurringFillslots.patch

Valentin Deniaud, 29 juillet 2021 17:50

Télécharger (2,62 ko)

Voir les différences:

Subject: [PATCH] api: fix waiting list condition in RecurringFillslots
 (#55905)

 chrono/api/views.py        |  3 ++-
 tests/api/test_fillslot.py | 28 ++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 1 deletion(-)
chrono/api/views.py
1607 1607
        events_to_book = Event.annotate_queryset(events_to_book)
1608 1608
        events_to_book = events_to_book.annotate(
1609 1609
            in_waiting_list=ExpressionWrapper(
1610
                Q(booked_places_count__gte=F('places')), output_field=BooleanField()
1610
                Q(booked_places_count__gte=F('places')) | Q(waiting_list_count__gt=0),
1611
                output_field=BooleanField(),
1611 1612
            )
1612 1613
        )
1613 1614

  
tests/api/test_fillslot.py
2191 2191
    resp = app.post_json(fillslots_url, params={'user_external_id': 'a', 'slots': 'a:1'}, status=400)
2192 2192
    assert resp.json['err'] == 1
2193 2193
    assert resp.json['err_desc'] == 'event a is not bookable'
2194

  
2195

  
2196
def test_recurring_events_api_fillslots_waiting_list(app, user, freezer):
2197
    freezer.move_to('2021-09-06 12:00')
2198
    agenda = Agenda.objects.create(label='Foo bar', kind='events')
2199
    event = Event.objects.create(
2200
        label='Event',
2201
        start_datetime=now(),
2202
        recurrence_days=[0],
2203
        places=2,
2204
        waiting_list_places=2,
2205
        agenda=agenda,
2206
        recurrence_end_date=now() + datetime.timedelta(days=30),
2207
    )
2208
    event.create_all_recurrences()
2209
    app.authorization = ('Basic', ('john.doe', 'password'))
2210

  
2211
    # create bookings in waiting list
2212
    for recurrence in event.recurrences.all():
2213
        Booking.objects.create(event=recurrence, in_waiting_list=True)
2214
    events = Event.annotate_queryset(Event.objects.filter(primary_event__isnull=False))
2215
    assert events.filter(waiting_list_count=1).count() == 5
2216

  
2217
    # check that new bookings are put in waiting list despite free slots on main list
2218
    params = {'user_external_id': 'user_id', 'slots': 'event:0'}
2219
    resp = app.post_json('/api/agenda/%s/recurring_fillslots/' % agenda.slug, params=params)
2220
    assert resp.json['booking_count'] == 5
2221
    assert events.filter(waiting_list_count=2).count() == 5
2194
-