Skip to content

Commit

Permalink
Merge pull request #173 from conancain/145-Calendar_link_not_timezone…
Browse files Browse the repository at this point in the history
…_aware

Issue #145: Make calendar link timezone aware
  • Loading branch information
ykdeal authored May 13, 2022
2 parents c1d5fef + 2e212d6 commit 4e00205
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
35 changes: 35 additions & 0 deletions api/tests/send_email_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import datetime
from urllib.parse import parse_qs
from urllib.parse import urlparse

import pytest
import pytz
from yelp_beans.logic.meeting_spec import get_specs_for_current_week
from yelp_beans.matching.match import generate_meetings
from yelp_beans.models import User
from yelp_beans.models import UserSubscriptionPreferences
from yelp_beans.send_email import create_google_calendar_invitation_link
from yelp_beans.send_email import send_batch_initial_opt_in_email
from yelp_beans.send_email import send_batch_meeting_confirmation_email
from yelp_beans.send_email import send_batch_unmatched_email
Expand Down Expand Up @@ -58,3 +64,32 @@ def test_send_batch_meeting_confirmation_email(database, session):
def test_send_batch_unmatched_email(database, fake_user):
matches, unmatched = generate_meetings([fake_user], database.specs[0])
send_batch_unmatched_email(unmatched)

@pytest.mark.parametrize(
"test_datetime,expected_link_ctz",
[
(
datetime.datetime(2022, 5, 13, 23, 34, 45, tzinfo=pytz.timezone('America/Chicago')),
"America/Chicago"
),
(
datetime.datetime(2022, 5, 13, 23, 34, 45, tzinfo=pytz.timezone('America/Los_Angeles')),
"America/Los_Angeles"
),
(
datetime.datetime(2022, 5, 13, 23, 34, 45, tzinfo=pytz.timezone('Europe/London')),
"Europe/London"
),
(
datetime.datetime(2022, 5, 13, 23, 34, 45),
None
),
]
)
def test_create_google_calendar_invitation_link(test_datetime, expected_link_ctz):
generated_calendar_url = create_google_calendar_invitation_link([], "title", "office", "location", test_datetime,
test_datetime)
parsed_url = urlparse(generated_calendar_url)
ctz_param = parse_qs(parsed_url.query).get("ctz", None)
ctz_value = ctz_param[0] if ctz_param else None
assert ctz_value == expected_link_ctz
6 changes: 6 additions & 0 deletions api/yelp_beans/send_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ def create_google_calendar_invitation_link(user_list, title, office, location, m
'location': office + " " + location,
'add': ','.join([user.email for user in user_list])
}
if meeting_datetime.tzinfo and meeting_datetime.tzinfo.zone:
# If the meeting time have a timezone specified
# and Calendar URL link doesn't contain timezone
# Add the "ctz" parameter to Google's Calendar template link
url_params["ctz"] = meeting_datetime.tzinfo.zone

invite_url += urllib.parse.urlencode(url_params)
return invite_url

Expand Down

0 comments on commit 4e00205

Please sign in to comment.