1448 |
1448 |
|
1449 |
1449 |
@pytest.mark.freeze_time('2021-09-06 12:00')
|
1450 |
1450 |
def test_recurring_events_api_list_multiple_agendas_queries(app):
|
|
1451 |
category = Category.objects.create(label='Category A')
|
1451 |
1452 |
for i in range(20):
|
1452 |
|
agenda = Agenda.objects.create(slug=f'{i}', kind='events')
|
|
1453 |
agenda = Agenda.objects.create(slug=f'{i}', kind='events', category=category)
|
1453 |
1454 |
Desk.objects.create(agenda=agenda, slug='_exceptions_holder')
|
1454 |
1455 |
start, end = now(), now() + datetime.timedelta(days=30)
|
1455 |
1456 |
Event.objects.create(
|
1456 |
1457 |
start_datetime=start, places=2, recurrence_end_date=end, recurrence_days=[1, 2], agenda=agenda
|
1457 |
1458 |
)
|
|
1459 |
Subscription.objects.create(
|
|
1460 |
agenda=agenda,
|
|
1461 |
user_external_id='xxx',
|
|
1462 |
date_start=now(),
|
|
1463 |
date_end=now() + datetime.timedelta(days=60),
|
|
1464 |
)
|
1458 |
1465 |
with CaptureQueriesContext(connection) as ctx:
|
1459 |
1466 |
resp = app.get('/api/agendas/recurring-events/?agendas=%s' % ','.join(str(i) for i in range(20)))
|
1460 |
1467 |
assert len(resp.json['data']) == 40
|
1461 |
1468 |
assert len(ctx.captured_queries) == 3
|
1462 |
1469 |
|
|
1470 |
with CaptureQueriesContext(connection) as ctx:
|
|
1471 |
resp = app.get('/api/agendas/recurring-events/?subscribed=category-a&user_external_id=xxx')
|
|
1472 |
assert len(resp.json['data']) == 40
|
|
1473 |
assert len(ctx.captured_queries) == 3
|
|
1474 |
|
1463 |
1475 |
|
1464 |
1476 |
@pytest.mark.freeze_time('2021-09-06 12:00')
|
1465 |
1477 |
def test_recurring_events_api_list_subscribed(app, user):
|
... | ... | |
1470 |
1482 |
Event.objects.create(
|
1471 |
1483 |
slug='event',
|
1472 |
1484 |
start_datetime=now(),
|
1473 |
|
recurrence_days=[0, 1, 3, 4], # Monday, Tuesday, Thursday, Friday
|
|
1485 |
recurrence_days=[0, 1, 3, 6], # Monday, Tuesday, Thursday, Friday
|
1474 |
1486 |
places=2,
|
1475 |
|
waiting_list_places=1,
|
1476 |
1487 |
agenda=first_agenda,
|
1477 |
1488 |
recurrence_end_date=now() + datetime.timedelta(days=364),
|
1478 |
1489 |
)
|
1479 |
1490 |
Event.objects.create(
|
1480 |
1491 |
slug='sunday-event',
|
1481 |
1492 |
start_datetime=now(),
|
1482 |
|
recurrence_days=[6],
|
|
1493 |
recurrence_days=[5],
|
1483 |
1494 |
places=2,
|
1484 |
|
waiting_list_places=1,
|
1485 |
1495 |
agenda=second_agenda,
|
1486 |
1496 |
recurrence_end_date=now() + datetime.timedelta(days=364),
|
1487 |
1497 |
)
|
... | ... | |
1512 |
1522 |
resp = app.get('/api/agendas/recurring-events/?user_external_id=xxx&subscribed=all')
|
1513 |
1523 |
assert len(resp.json['data']) == 5
|
1514 |
1524 |
|
|
1525 |
# events are sorted by day
|
|
1526 |
assert [x['id'] for x in resp.json['data']] == [
|
|
1527 |
'first-agenda@event:0',
|
|
1528 |
'first-agenda@event:1',
|
|
1529 |
'first-agenda@event:3',
|
|
1530 |
'second-agenda@sunday-event:5',
|
|
1531 |
'first-agenda@event:6',
|
|
1532 |
]
|
|
1533 |
|
1515 |
1534 |
resp = app.get('/api/agendas/recurring-events/?user_external_id=xxx&subscribed=category-b')
|
1516 |
1535 |
assert len(resp.json['data']) == 1
|
1517 |
1536 |
|
... | ... | |
1528 |
1547 |
resp = app.get('/api/agendas/recurring-events/?user_external_id=yyy&subscribed=all')
|
1529 |
1548 |
assert len(resp.json['data']) == 1
|
1530 |
1549 |
|
|
1550 |
# sorting depends on querystring order
|
|
1551 |
Event.objects.create(
|
|
1552 |
slug='event',
|
|
1553 |
start_datetime=now(),
|
|
1554 |
recurrence_days=[0],
|
|
1555 |
places=2,
|
|
1556 |
agenda=second_agenda,
|
|
1557 |
recurrence_end_date=now() + datetime.timedelta(days=364),
|
|
1558 |
)
|
|
1559 |
resp = app.get('/api/agendas/recurring-events/?subscribed=category-a,category-b&user_external_id=xxx')
|
|
1560 |
event_ids = [x['id'] for x in resp.json['data']]
|
|
1561 |
assert event_ids.index('first-agenda@event:0') < event_ids.index('second-agenda@event:0')
|
|
1562 |
|
|
1563 |
resp = app.get('/api/agendas/recurring-events/?subscribed=category-b,category-a&user_external_id=xxx')
|
|
1564 |
event_ids = [x['id'] for x in resp.json['data']]
|
|
1565 |
assert event_ids.index('first-agenda@event:0') > event_ids.index('second-agenda@event:0')
|
|
1566 |
|
1531 |
1567 |
|
1532 |
1568 |
@pytest.mark.freeze_time('2021-05-06 14:00')
|
1533 |
1569 |
def test_datetimes_multiple_agendas(app):
|
1534 |
|
-
|