1461 |
1461 |
assert len(ctx.captured_queries) == 3
|
1462 |
1462 |
|
1463 |
1463 |
|
|
1464 |
@pytest.mark.freeze_time('2021-09-06 12:00')
|
|
1465 |
def test_recurring_events_api_list_subscribed(app, user):
|
|
1466 |
category = Category.objects.create(label='Category A')
|
|
1467 |
first_agenda = Agenda.objects.create(label='First agenda', kind='events', category=category)
|
|
1468 |
# Desk.objects.create(agenda=first_agenda, slug='_exceptions_holder')
|
|
1469 |
category = Category.objects.create(label='Category B')
|
|
1470 |
second_agenda = Agenda.objects.create(label='Second agenda', kind='events', category=category)
|
|
1471 |
# Desk.objects.create(agenda=second_agenda, slug='_exceptions_holder')
|
|
1472 |
event = Event.objects.create(
|
|
1473 |
slug='event',
|
|
1474 |
start_datetime=now(),
|
|
1475 |
recurrence_days=[0, 1, 3, 4], # Monday, Tuesday, Thursday, Friday
|
|
1476 |
places=2,
|
|
1477 |
waiting_list_places=1,
|
|
1478 |
agenda=first_agenda,
|
|
1479 |
recurrence_end_date=now() + datetime.timedelta(days=364),
|
|
1480 |
)
|
|
1481 |
sunday_event = Event.objects.create(
|
|
1482 |
slug='sunday-event',
|
|
1483 |
start_datetime=now(),
|
|
1484 |
recurrence_days=[6],
|
|
1485 |
places=2,
|
|
1486 |
waiting_list_places=1,
|
|
1487 |
agenda=second_agenda,
|
|
1488 |
recurrence_end_date=now() + datetime.timedelta(days=364),
|
|
1489 |
)
|
|
1490 |
|
|
1491 |
Subscription.objects.create(
|
|
1492 |
agenda=first_agenda,
|
|
1493 |
user_external_id='xxx',
|
|
1494 |
date_start=now(),
|
|
1495 |
date_end=now() + datetime.timedelta(days=30),
|
|
1496 |
)
|
|
1497 |
resp = app.get('/api/agendas/recurring-events/?user_external_id=xxx&subscribed=all')
|
|
1498 |
assert len(resp.json['data']) == 4
|
|
1499 |
assert all(event['id'].startswith('first-agenda') for event in resp.json['data'])
|
|
1500 |
|
|
1501 |
resp = app.get('/api/agendas/recurring-events/?user_external_id=xxx&subscribed=category-a')
|
|
1502 |
assert len(resp.json['data']) == 4
|
|
1503 |
assert all(event['id'].startswith('first-agenda') for event in resp.json['data'])
|
|
1504 |
|
|
1505 |
resp = app.get('/api/agendas/recurring-events/?user_external_id=xxx&subscribed=category-b')
|
|
1506 |
assert len(resp.json['data']) == 0
|
|
1507 |
|
|
1508 |
Subscription.objects.create(
|
|
1509 |
agenda=second_agenda,
|
|
1510 |
user_external_id='xxx',
|
|
1511 |
date_start=now(),
|
|
1512 |
date_end=now() + datetime.timedelta(days=30),
|
|
1513 |
)
|
|
1514 |
resp = app.get('/api/agendas/recurring-events/?user_external_id=xxx&subscribed=all')
|
|
1515 |
assert len(resp.json['data']) == 5
|
|
1516 |
|
|
1517 |
resp = app.get('/api/agendas/recurring-events/?user_external_id=xxx&subscribed=category-b')
|
|
1518 |
assert len(resp.json['data']) == 1
|
|
1519 |
|
|
1520 |
# other user
|
|
1521 |
resp = app.get('/api/agendas/recurring-events/?user_external_id=yyy&subscribed=all')
|
|
1522 |
assert len(resp.json['data']) == 0
|
|
1523 |
|
|
1524 |
Subscription.objects.create(
|
|
1525 |
agenda=second_agenda,
|
|
1526 |
user_external_id='yyy',
|
|
1527 |
date_start=now(),
|
|
1528 |
date_end=now() + datetime.timedelta(days=30),
|
|
1529 |
)
|
|
1530 |
resp = app.get('/api/agendas/recurring-events/?user_external_id=yyy&subscribed=all')
|
|
1531 |
assert len(resp.json['data']) == 1
|
|
1532 |
|
|
1533 |
|
1464 |
1534 |
@pytest.mark.freeze_time('2021-05-06 14:00')
|
1465 |
1535 |
def test_datetimes_multiple_agendas(app):
|
1466 |
1536 |
first_agenda = Agenda.objects.create(
|
1467 |
|
-
|