|
18 | 18 | ICAL_STATUS_CANCELLED,
|
19 | 19 | ICAL_SUMMARY,
|
20 | 20 | )
|
| 21 | +from apps.schedules.ical_utils import MissingUser |
21 | 22 | from apps.schedules.models import (
|
22 | 23 | CustomOnCallShift,
|
23 | 24 | OnCallSchedule,
|
@@ -358,6 +359,57 @@ def test_filter_events_include_empty(make_organization, make_user_for_organizati
|
358 | 359 | assert events == expected
|
359 | 360 |
|
360 | 361 |
|
| 362 | +@pytest.mark.django_db |
| 363 | +def test_filter_events_include_empty_if_deleted( |
| 364 | + make_organization, make_user_for_organization, make_schedule, make_on_call_shift |
| 365 | +): |
| 366 | + organization = make_organization() |
| 367 | + schedule = make_schedule( |
| 368 | + organization, |
| 369 | + schedule_class=OnCallScheduleWeb, |
| 370 | + name="test_web_schedule", |
| 371 | + ) |
| 372 | + user = make_user_for_organization(organization) |
| 373 | + now = timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) |
| 374 | + start_date = now - timezone.timedelta(days=7) |
| 375 | + |
| 376 | + data = { |
| 377 | + "start": start_date + timezone.timedelta(hours=10), |
| 378 | + "rotation_start": start_date + timezone.timedelta(hours=10), |
| 379 | + "duration": timezone.timedelta(hours=8), |
| 380 | + "priority_level": 1, |
| 381 | + "frequency": CustomOnCallShift.FREQUENCY_DAILY, |
| 382 | + "schedule": schedule, |
| 383 | + } |
| 384 | + on_call_shift = make_on_call_shift( |
| 385 | + organization=organization, shift_type=CustomOnCallShift.TYPE_ROLLING_USERS_EVENT, **data |
| 386 | + ) |
| 387 | + on_call_shift.add_rolling_users([[user]]) |
| 388 | + |
| 389 | + # user is deleted, shift data still exists but the shift is empty |
| 390 | + user.delete() |
| 391 | + |
| 392 | + end_date = start_date + timezone.timedelta(days=1) |
| 393 | + events = schedule.filter_events(start_date, end_date, filter_by=OnCallSchedule.TYPE_ICAL_PRIMARY, with_empty=True) |
| 394 | + expected = [ |
| 395 | + { |
| 396 | + "calendar_type": OnCallSchedule.TYPE_ICAL_PRIMARY, |
| 397 | + "start": on_call_shift.start, |
| 398 | + "end": on_call_shift.start + on_call_shift.duration, |
| 399 | + "all_day": False, |
| 400 | + "is_override": False, |
| 401 | + "is_empty": True, |
| 402 | + "is_gap": False, |
| 403 | + "priority_level": on_call_shift.priority_level, |
| 404 | + "missing_users": [MissingUser.DISPLAY_NAME], |
| 405 | + "users": [], |
| 406 | + "shift": {"pk": on_call_shift.public_primary_key}, |
| 407 | + "source": "api", |
| 408 | + } |
| 409 | + ] |
| 410 | + assert events == expected |
| 411 | + |
| 412 | + |
361 | 413 | @pytest.mark.django_db
|
362 | 414 | def test_filter_events_ical_all_day(make_organization, make_user_for_organization, make_schedule, get_ical):
|
363 | 415 | calendar = get_ical("calendar_with_all_day_event.ics")
|
|
0 commit comments