2168 |
2168 |
assert resp.json['booking_count'] == 155
|
2169 |
2169 |
assert len(resp.json['full_events']) == 1
|
2170 |
2170 |
assert resp.json['full_events'][0]['slug'] == event.slug
|
|
2171 |
resp = app.post_json(fillslots_url, params=params)
|
2171 |
2172 |
|
|
2173 |
# events are full
|
2172 |
2174 |
params['user_external_id'] = 'user_id_4'
|
2173 |
2175 |
resp = app.post_json(fillslots_url, params=params)
|
2174 |
|
assert resp.json['err'] == 1
|
2175 |
|
assert resp.json['err_desc'] == 'all events are all full'
|
|
2176 |
assert resp.json['booking_count'] == 0
|
|
2177 |
|
|
2178 |
# no event in range
|
|
2179 |
resp = app.post_json(fillslots_url + '?date_start=2020-10-06&date_end=2020-11-06', params=params)
|
|
2180 |
assert resp.json['booking_count'] == 0
|
2176 |
2181 |
|
2177 |
2182 |
params['slots'] = 'event:1'
|
2178 |
2183 |
resp = app.post_json(fillslots_url + '?date_start=2021-10-06&date_end=2021-11-06', params=params)
|
2179 |
2184 |
assert resp.json['booking_count'] == 4
|
2180 |
2185 |
assert Booking.objects.filter(user_external_id='user_id_4').count() == 4
|
2181 |
2186 |
|
2182 |
|
resp = app.post_json(fillslots_url + '?date_start=2020-10-06&date_end=2020-11-06', params=params)
|
2183 |
|
assert resp.json['err'] == 1
|
2184 |
|
assert resp.json['err_desc'] == 'no event recurrences to book'
|
2185 |
|
|
2186 |
2187 |
del params['user_external_id']
|
2187 |
2188 |
resp = app.post_json(fillslots_url, params=params, status=400)
|
2188 |
2189 |
assert resp.json['err'] == 1
|
... | ... | |
2226 |
2227 |
assert events.filter(waiting_list_count=2).count() == 5
|
2227 |
2228 |
|
2228 |
2229 |
|
|
2230 |
def test_recurring_events_api_fillslots_change_bookings(app, user, freezer):
|
|
2231 |
freezer.move_to('2021-09-06 12:00')
|
|
2232 |
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
|
2233 |
event = Event.objects.create(
|
|
2234 |
label='Event',
|
|
2235 |
start_datetime=now(),
|
|
2236 |
recurrence_days=[0, 1, 3, 4], # Monday, Tuesday, Thursday, Friday
|
|
2237 |
places=1,
|
|
2238 |
waiting_list_places=1,
|
|
2239 |
agenda=agenda,
|
|
2240 |
recurrence_end_date=now() + datetime.timedelta(days=364),
|
|
2241 |
)
|
|
2242 |
event.create_all_recurrences()
|
|
2243 |
|
|
2244 |
app.authorization = ('Basic', ('john.doe', 'password'))
|
|
2245 |
fillslots_url = '/api/agenda/%s/recurring-events/fillslots/' % agenda.slug
|
|
2246 |
params = {'user_external_id': 'user_id'}
|
|
2247 |
# Book Monday and Thursday
|
|
2248 |
params['slots'] = 'event:0,event:3'
|
|
2249 |
resp = app.post_json(fillslots_url, params=params)
|
|
2250 |
assert resp.json['booking_count'] == 104
|
|
2251 |
assert resp.json['cancelled_booking_count'] == 0
|
|
2252 |
assert Booking.objects.count() == 104
|
|
2253 |
assert Booking.objects.filter(event__start_datetime__week_day=2).count() == 52
|
|
2254 |
assert Booking.objects.filter(event__start_datetime__week_day=5).count() == 52
|
|
2255 |
|
|
2256 |
# Change booking to Monday and Tuesday
|
|
2257 |
params['slots'] = 'event:0,event:1'
|
|
2258 |
resp = app.post_json(fillslots_url, params=params)
|
|
2259 |
assert resp.json['booking_count'] == 52
|
|
2260 |
assert resp.json['cancelled_booking_count'] == 52
|
|
2261 |
assert Booking.objects.count() == 104
|
|
2262 |
assert Booking.objects.filter(event__start_datetime__week_day=2).count() == 52
|
|
2263 |
assert Booking.objects.filter(event__start_datetime__week_day=3).count() == 52
|
|
2264 |
|
|
2265 |
# Booking again does nothing
|
|
2266 |
resp = app.post_json(fillslots_url, params=params)
|
|
2267 |
assert resp.json['booking_count'] == 0
|
|
2268 |
assert resp.json['cancelled_booking_count'] == 0
|
|
2269 |
assert Booking.objects.count() == 104
|
|
2270 |
|
|
2271 |
params = {'user_external_id': 'user_id_2'}
|
|
2272 |
params['slots'] = 'event:0,event:3'
|
|
2273 |
resp = app.post_json(fillslots_url, params=params)
|
|
2274 |
assert resp.json['booking_count'] == 104
|
|
2275 |
assert resp.json['cancelled_booking_count'] == 0
|
|
2276 |
assert Booking.objects.count() == 208
|
|
2277 |
assert Booking.objects.filter(event__start_datetime__week_day=2).count() == 104
|
|
2278 |
assert Booking.objects.filter(event__start_datetime__week_day=5).count() == 52
|
|
2279 |
events = Event.annotate_queryset(Event.objects.filter(primary_event__isnull=False))
|
|
2280 |
assert events.filter(booked_places_count=1).count() == 156
|
|
2281 |
assert events.filter(waiting_list_count=1).count() == 52
|
|
2282 |
|
|
2283 |
params['slots'] = 'event:1,event:4'
|
|
2284 |
resp = app.post_json(fillslots_url, params=params)
|
|
2285 |
assert resp.json['booking_count'] == 104
|
|
2286 |
assert resp.json['cancelled_booking_count'] == 104
|
|
2287 |
assert Booking.objects.count() == 208
|
|
2288 |
assert Booking.objects.filter(event__start_datetime__week_day=3).count() == 104
|
|
2289 |
assert Booking.objects.filter(event__start_datetime__week_day=6).count() == 52
|
|
2290 |
events = Event.annotate_queryset(Event.objects.filter(primary_event__isnull=False))
|
|
2291 |
assert events.filter(booked_places_count=1).count() == 156
|
|
2292 |
assert events.filter(waiting_list_count=1).count() == 52
|
|
2293 |
|
|
2294 |
# only recurring events are impacted
|
|
2295 |
normal_event = Event.objects.create(
|
|
2296 |
start_datetime=now() + datetime.timedelta(days=1), places=2, agenda=agenda
|
|
2297 |
)
|
|
2298 |
Booking.objects.create(event=normal_event, user_external_id='user_id')
|
|
2299 |
resp = app.post_json(fillslots_url, params={'user_external_id': 'user_id', 'slots': 'event:0'})
|
|
2300 |
assert resp.json['cancelled_booking_count'] == 52
|
|
2301 |
assert Booking.objects.filter(user_external_id='user_id', event=normal_event).count() == 1
|
|
2302 |
|
|
2303 |
|
2229 |
2304 |
@pytest.mark.freeze_time('2021-09-06 12:00')
|
2230 |
2305 |
def test_api_events_fillslots(app, user):
|
2231 |
2306 |
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
2232 |
|
-
|