-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix iCal imported schedules related users and next shifts per user (#…
…3178) Fixes grafana/oncall-private#2212
- Loading branch information
Showing
5 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import json | ||
import textwrap | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
@@ -1487,6 +1488,57 @@ def test_next_shifts_per_user( | |
assert returned_data == expected | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_next_shifts_per_user_ical_schedule_using_emails( | ||
make_organization_and_user_with_plugin_token, make_user_for_organization, make_user_auth_headers, make_schedule | ||
): | ||
organization, admin, token = make_organization_and_user_with_plugin_token() | ||
client = APIClient() | ||
|
||
user = make_user_for_organization(organization, username="testing", email="[email protected]") | ||
# ical file using emails as reference | ||
cached_ical_primary_schedule = textwrap.dedent( | ||
""" | ||
BEGIN:VCALENDAR | ||
VERSION:2.0 | ||
PRODID:testing | ||
CALSCALE:GREGORIAN | ||
BEGIN:VEVENT | ||
CREATED:20220316T121102Z | ||
LAST-MODIFIED:20230127T151619Z | ||
DTSTAMP:20230127T151619Z | ||
UID:something | ||
SUMMARY:[email protected] | ||
RRULE:FREQ=WEEKLY | ||
DTSTART;TZID=Europe/Madrid:20220309T130000 | ||
DTEND;TZID=Europe/Madrid:20220309T133000 | ||
END:VEVENT | ||
BEGIN:VEVENT | ||
CREATED:20220316T121102Z | ||
LAST-MODIFIED:20230127T151619Z | ||
DTSTAMP:20230127T151619Z | ||
UID:something-else | ||
SUMMARY:[email protected] | ||
RRULE:FREQ=WEEKLY | ||
DTSTART;TZID=Europe/Madrid:20220309T150000 | ||
DTEND;TZID=Europe/Madrid:20220309T153000 | ||
END:VEVENT | ||
END:VCALENDAR | ||
""" | ||
) | ||
schedule = make_schedule( | ||
organization, | ||
schedule_class=OnCallScheduleICal, | ||
cached_ical_file_primary=cached_ical_primary_schedule, | ||
) | ||
|
||
url = reverse("api-internal:schedule-next-shifts-per-user", kwargs={"pk": schedule.public_primary_key}) | ||
response = client.get(url, format="json", **make_user_auth_headers(admin, token)) | ||
assert response.status_code == status.HTTP_200_OK | ||
|
||
assert set(response.data["users"].keys()) == {user.public_primary_key} | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_related_users( | ||
make_organization_and_user_with_plugin_token, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1304,6 +1304,40 @@ def test_schedule_related_users_usernames( | |
assert set(schedule.related_users()) == set(users) | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_schedule_related_users_emails(make_organization, make_user_for_organization, make_schedule): | ||
organization = make_organization() | ||
user = make_user_for_organization(organization, username="testing", email="[email protected]") | ||
# ical file using email as reference | ||
cached_ical_primary_schedule = textwrap.dedent( | ||
""" | ||
BEGIN:VCALENDAR | ||
VERSION:2.0 | ||
PRODID:testing | ||
CALSCALE:GREGORIAN | ||
BEGIN:VEVENT | ||
CREATED:20220316T121102Z | ||
LAST-MODIFIED:20230127T151619Z | ||
DTSTAMP:20230127T151619Z | ||
UID:something | ||
SUMMARY:[email protected] | ||
RRULE:FREQ=WEEKLY;UNTIL=20221231T010101 | ||
DTSTART;TZID=Europe/Madrid:20220309T130000 | ||
DTEND;TZID=Europe/Madrid:20220309T133000 | ||
SEQUENCE:4 | ||
END:VEVENT | ||
END:VCALENDAR | ||
""" | ||
) | ||
schedule = make_schedule( | ||
organization, | ||
schedule_class=OnCallScheduleICal, | ||
cached_ical_file_primary=cached_ical_primary_schedule, | ||
) | ||
|
||
assert set(schedule.related_users()) == {user} | ||
|
||
|
||
@pytest.mark.django_db(transaction=True) | ||
def test_filter_events_none_cache_unchanged( | ||
make_organization, make_user_for_organization, make_schedule, make_on_call_shift | ||
|