From 7fd0e5ecf7df6121c8c628d68229b3ba593e4693 Mon Sep 17 00:00:00 2001 From: Matias Bordese Date: Wed, 31 Aug 2022 14:14:21 -0300 Subject: [PATCH] Skip empty events in final schedule --- engine/apps/api/tests/test_oncall_shift.py | 18 +++++++++--------- .../apps/schedules/models/on_call_schedule.py | 4 ++++ .../schedules/tests/test_on_call_schedule.py | 9 +-------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/engine/apps/api/tests/test_oncall_shift.py b/engine/apps/api/tests/test_oncall_shift.py index 25e48a53..44660571 100644 --- a/engine/apps/api/tests/test_oncall_shift.py +++ b/engine/apps/api/tests/test_oncall_shift.py @@ -79,7 +79,14 @@ def test_create_on_call_shift_override(on_call_shift_internal_api_setup, make_us } response = client.post(url, data, format="json", **make_user_auth_headers(user1, token)) - expected_payload = data | {"id": response.data["id"], "updated_shift": None} + returned_rolling_users = response.data["rolling_users"] + assert len(returned_rolling_users) == 1 + assert sorted(returned_rolling_users[0]) == sorted(data["rolling_users"][0]) + expected_payload = data | { + "id": response.data["id"], + "updated_shift": None, + "rolling_users": returned_rolling_users, + } assert response.status_code == status.HTTP_201_CREATED assert response.json() == expected_payload @@ -1376,14 +1383,7 @@ def test_on_call_shift_preview_without_users( # check final schedule events final_events = response.json()["final"] - expected_events = [ - { - "end": shift_end, - "start": shift_start, - "user": None, - "is_empty": True, - } - ] + expected_events = [] returned_events = [ { "end": e["end"], diff --git a/engine/apps/schedules/models/on_call_schedule.py b/engine/apps/schedules/models/on_call_schedule.py index 11b37d7f..ad26893f 100644 --- a/engine/apps/schedules/models/on_call_schedule.py +++ b/engine/apps/schedules/models/on_call_schedule.py @@ -297,6 +297,10 @@ class OnCallSchedule(PolymorphicModel): while pending: ev = pending.pop(0) + if ev["is_empty"]: + # exclude events without active users + continue + if ev["calendar_type"] == OnCallSchedule.TYPE_ICAL_OVERRIDES: # include overrides from start resolved.append(ev) diff --git a/engine/apps/schedules/tests/test_on_call_schedule.py b/engine/apps/schedules/tests/test_on_call_schedule.py index 7e6d52d8..766b44bb 100644 --- a/engine/apps/schedules/tests/test_on_call_schedule.py +++ b/engine/apps/schedules/tests/test_on_call_schedule.py @@ -600,14 +600,7 @@ def test_preview_shift_no_user(make_organization, make_user_for_organization, ma ] assert rotation_events == expected_rotation_events - expected_events = [ - { - "end": new_shift.start + new_shift.duration, - "start": new_shift.start, - "user": None, - "is_empty": True, - } - ] + expected_events = [] returned_events = [ { "end": e["end"],