diff --git a/engine/apps/api/tests/test_schedules.py b/engine/apps/api/tests/test_schedules.py index 4c562307..9c73027d 100644 --- a/engine/apps/api/tests/test_schedules.py +++ b/engine/apps/api/tests/test_schedules.py @@ -205,11 +205,11 @@ def test_get_list_schedules_by_type( }, ] - for expected, schedule_type in enumerate(("api", "ical", "web")): + for schedule_type in range(3): url = reverse("api-internal:schedule-list") + "?type={}".format(schedule_type) response = client.get(url, format="json", **make_user_auth_headers(user, token)) assert response.status_code == status.HTTP_200_OK - assert response.json() == [expected_payload[expected]] + assert response.json() == [expected_payload[schedule_type]] @pytest.mark.django_db diff --git a/engine/apps/api/views/schedule.py b/engine/apps/api/views/schedule.py index 5a2d96aa..04de4393 100644 --- a/engine/apps/api/views/schedule.py +++ b/engine/apps/api/views/schedule.py @@ -24,7 +24,7 @@ from apps.api.serializers.schedule_polymorphic import ( from apps.auth_token.auth import PluginAuthentication from apps.auth_token.constants import SCHEDULE_EXPORT_TOKEN_NAME from apps.auth_token.models import ScheduleExportAuthToken -from apps.schedules.models import OnCallSchedule, OnCallScheduleCalendar, OnCallScheduleICal, OnCallScheduleWeb +from apps.schedules.models import OnCallSchedule from apps.slack.models import SlackChannel from apps.slack.tasks import update_slack_user_group_for_schedules from common.api_helpers.exceptions import BadRequest, Conflict @@ -42,7 +42,9 @@ EVENTS_FILTER_BY_ROTATION = "rotation" EVENTS_FILTER_BY_OVERRIDE = "override" EVENTS_FILTER_BY_FINAL = "final" -SCHEDULE_TYPE_TO_CLASS = {"api": OnCallScheduleCalendar, "ical": OnCallScheduleICal, "web": OnCallScheduleWeb} +SCHEDULE_TYPE_TO_CLASS = { + str(num_type): cls for cls, num_type in PolymorphicScheduleSerializer.SCHEDULE_CLASS_TO_TYPE.items() +} class ScheduleView(