Projet

Général

Profil

0001-api-support-overlapping-events-44644.patch

Emmanuel Cazenave, 01 juillet 2020 12:47

Télécharger (2,75 ko)

Voir les différences:

Subject: [PATCH] api: support overlapping events (#44644)

 chrono/api/views.py |  2 +-
 tests/test_api.py   | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)
chrono/api/views.py
169 169
            )
170 170
            .exclude(booking__cancellation_datetime__isnull=False)
171 171
            # ordering is important for the later groupby, it works like sort | uniq
172
            .order_by('desk_id', 'start_datetime')
172
            .order_by('desk_id', 'start_datetime', 'meeting_type__duration')
173 173
            .values_list('desk_id', 'start_datetime', 'meeting_type__duration')
174 174
        )
175 175
        # compute exclusion set by desk from all bookings, using
tests/test_api.py
3074 3074
    assert len([x for x in resp.json['data'] if x['disabled']]) == 2
3075 3075

  
3076 3076

  
3077
def test_datetimes_api_concurrent_bookings(app, user, meetings_agenda):
3078
    meeting_type = MeetingType.objects.get(agenda=meetings_agenda)
3079
    api_url = '/api/agenda/%s/meetings/%s/datetimes/' % (meeting_type.agenda.slug, meeting_type.slug)
3080
    assert Booking.objects.count() == 0
3081
    resp = app.get(api_url)
3082
    assert resp.json['data'][0]['datetime'] == '2017-05-22 10:00:00'
3083

  
3084
    # make a booking
3085
    fillslot_url = resp.json['data'][0]['api']['fillslot_url']
3086
    app.authorization = ('Basic', ('john.doe', 'password'))
3087
    resp = app.post(fillslot_url)
3088
    assert Booking.objects.count() == 1
3089

  
3090
    # make a second one artificially on an overlapping slot
3091
    meeting_type = MeetingType.objects.create(agenda=meetings_agenda, label='Boo', duration=8)
3092
    booking = Booking.objects.first()
3093
    event = booking.event
3094
    new_event = Event.objects.create(
3095
        meeting_type=meeting_type,
3096
        start_datetime=event.start_datetime,
3097
        desk=event.desk,
3098
        places=event.places,
3099
        agenda=meetings_agenda,
3100
    )
3101
    Booking.objects.create(event=new_event)
3102

  
3103
    # should not crash and slot not showing up
3104
    resp = app.get(api_url)
3105
    assert resp.json['data'][0]['datetime'] == '2017-05-22 10:00:00'
3106
    assert resp.json['data'][0]['disabled'] is True
3107

  
3108

  
3077 3109
def test_agenda_detail_routing(app, meetings_agenda):
3078 3110
    api_url = '/api/agenda/%s/' % meetings_agenda.slug
3079 3111
    resp = app.get(api_url)
3080
-