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