Skip to content

Commit

Permalink
Fix test get meeting participants (#110)
Browse files Browse the repository at this point in the history
* fix get meeting datetime

* fix tests and change subscription base time to something realistic

* Change to America/Los_Angeles tz and use localize function for email timezones

* fix tests
  • Loading branch information
kentwills authored Jan 30, 2018
1 parent ee70488 commit 8a3c9bd
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 49 deletions.
8 changes: 4 additions & 4 deletions cron.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ cron:
- description: Syncs employee data from s3
url: /tasks/populate_employees
schedule: every day 03:00
timezone: US/Pacific
timezone: America/Los_Angeles

- description: weekly meeting spec generation
url: /tasks/generate_meeting_specs_for_week
schedule: every monday 9:00
timezone: US/Pacific
timezone: America/Los_Angeles

- description: weekly opt-in email
url: /tasks/email_users_for_weekly_opt_in
schedule: every monday 11:00
timezone: US/Pacific
timezone: America/Los_Angeles

- description: weekly match
url: /tasks/match_employees
schedule: every wednesday 11:00
timezone: US/Pacific
timezone: America/Los_Angeles
2 changes: 1 addition & 1 deletion js/reducers/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const defaultValue = [
id: 'None',
location: 'Unknown',
title: 'No Meetings Set Up',
timezone: 'US/Pacific',
timezone: 'America/Los_Angeles',
size: 0,
office: 'None',
datetime: [],
Expand Down
14 changes: 3 additions & 11 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import pytest
from google.appengine.ext import ndb
from google.appengine.ext import testbed
from pytz import timezone
from pytz import utc

from yelp_beans import send_email
from yelp_beans.logic.subscription import get_specs_from_subscription
Expand Down Expand Up @@ -73,17 +71,11 @@ def subscription():


def _subscription():
zone = 'US/Pacific'
preference_1 = SubscriptionDateTime(datetime=datetime(2017, 1, 20, 23, 0, tzinfo=utc))
# Easier to think/verify in Pacific time since we are based in SF
assert preference_1.datetime.astimezone(timezone(zone)).hour == 15
preference_1.datetime = preference_1.datetime.replace(tzinfo=None)
zone = 'America/Los_Angeles'
preference_1 = SubscriptionDateTime(datetime=datetime(2017, 1, 20, 13, 0))
preference_1.put()

preference_2 = SubscriptionDateTime(datetime=datetime(2017, 1, 20, 19, 0, tzinfo=utc))
# Easier to think/verify in Pacific time since we are based in SF
assert preference_2.datetime.astimezone(timezone(zone)).hour == 11
preference_2.datetime = preference_2.datetime.replace(tzinfo=None)
preference_2 = SubscriptionDateTime(datetime=datetime(2017, 1, 20, 11, 0))
preference_2.put()

rule = Rule(name='office', value='USA: CA SF New Montgomery Office').put()
Expand Down
29 changes: 22 additions & 7 deletions tests/logic/subscription_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,37 @@
from __future__ import print_function
from __future__ import unicode_literals

from datetime import datetime

import pytest

from yelp_beans.logic.meeting_spec import get_meeting_datetime
from yelp_beans.logic.subscription import filter_subscriptions_by_user_data
from yelp_beans.logic.subscription import get_specs_from_subscription
from yelp_beans.logic.subscription import get_subscription_dates
from yelp_beans.logic.subscription import merge_subscriptions_with_preferences
from yelp_beans.logic.subscription import store_specs_from_subscription
from yelp_beans.models import MeetingSpec
from yelp_beans.models import MeetingSubscription
from yelp_beans.models import Rule
from yelp_beans.models import SubscriptionDateTime
from yelp_beans.models import User
from yelp_beans.models import UserSubscriptionPreferences


def test_get_specs_from_subscription(database):
week_start, specs = get_specs_from_subscription(database.sub)
assert len(specs) == 2
def test_get_specs_from_subscription_pst(minimal_database):
preference = SubscriptionDateTime(datetime=datetime(2017, 7, 20, 13, 0)).put()
subscription = MeetingSubscription(timezone='America/Los_Angeles', datetime=[preference]).put()
_, specs = get_specs_from_subscription(subscription.get())
assert len(specs) == 1
assert get_meeting_datetime(specs[0]).hour == 13


def test_get_specs_from_subscription_pdt(minimal_database):
preference = SubscriptionDateTime(datetime=datetime(2017, 1, 20, 13, 0)).put()
subscription = MeetingSubscription(timezone='America/Los_Angeles', datetime=[preference]).put()
_, specs = get_specs_from_subscription(subscription.get())
assert get_meeting_datetime(specs[0]).hour == 13


def test_store_specs_from_subscription(database):
Expand All @@ -30,7 +45,7 @@ def test_store_specs_from_subscription(database):
def test_get_subscription_dates(database):
dates = get_subscription_dates(database.sub)
assert len(dates) == 2
assert dates[1]['date'] == '2017-01-20T19:00:00+00:00'
assert dates[1]['date'] == '2017-01-20T11:00:00'


def test_merge_subscriptions_with_preferences(database, fake_user):
Expand All @@ -40,18 +55,18 @@ def test_merge_subscriptions_with_preferences(database, fake_user):
'title': 'Yelp Weekly',
'location': '8th Floor',
'office': 'USA: CA SF New Montgomery Office',
'timezone': 'US/Pacific',
'timezone': 'America/Los_Angeles',
'size': 2,
'rule_logic': None,
'datetime': [
{
'active': True,
'date': '2017-01-20T23:00:00+00:00',
'date': '2017-01-20T13:00:00',
'id': database.sub.datetime[0].urlsafe()
},
{
'active': False,
'date': '2017-01-20T19:00:00+00:00',
'date': '2017-01-20T11:00:00',
'id': database.sub.datetime[1].urlsafe()
}
]
Expand Down
20 changes: 4 additions & 16 deletions tests/routes/api/v1/metrics_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,10 @@ def test_get_meeting_participants(app, database):
MeetingParticipant(meeting=meeting1, user=user2.key).put()
with app.test_request_context('/v1/metrics/meeting_participants'):
participants = json.loads(meeting_participants())
assert participants == [
{
'date': '2017-10-27T23:00:00',
'meeting': 'agx0ZXN0YmVkLXRlc3RyDQsSB01lZXRpbmcYCgw',
'meeting_title': 'Yelp Weekly',
'participant': '[email protected]',
'time': '04:00PM'
},
{
'date': '2017-10-27T23:00:00',
'meeting': 'agx0ZXN0YmVkLXRlc3RyDQsSB01lZXRpbmcYCgw',
'meeting_title': 'Yelp Weekly',
'participant': '[email protected]',
'time': '04:00PM'
}
]
assert len(participants) == 2
assert set(participants[0].keys()) == set(['date', 'meeting', 'meeting_title', 'participant', 'time'])
assert participants[0]['date'] == database.specs[0].datetime.isoformat()
assert participants[0]['time'] == database.specs[0].datetime.strftime('%I:%M%p')


def test_get_meeting_requests(app, database):
Expand Down
6 changes: 3 additions & 3 deletions tests/routes/api/v1/preference_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ def test_preferences_api_user_exists(app, database, fake_user):
'title': 'Yelp Weekly',
'location': '8th Floor',
'office': 'USA: CA SF New Montgomery Office',
'timezone': 'US/Pacific',
'timezone': 'America/Los_Angeles',
'size': 2,
'rule_logic': None,
'datetime': [
{
'active': True,
'date': '2017-01-20T23:00:00+00:00',
'date': '2017-01-20T13:00:00',
'id': database.sub.datetime[0].urlsafe()
},
{
'active': False,
'date': '2017-01-20T19:00:00+00:00',
'date': '2017-01-20T11:00:00',
'id': database.sub.datetime[1].urlsafe()
}
],
Expand Down
10 changes: 7 additions & 3 deletions yelp_beans/logic/meeting_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from datetime import timedelta

from pytz import timezone
from pytz import utc

from yelp_beans.models import MeetingSpec
from yelp_beans.models import User
Expand Down Expand Up @@ -56,6 +55,11 @@ def get_users_from_spec(meeting_spec):


def get_meeting_datetime(meeting_spec):
"""
Given a meeting_spec, returns the meeting datetime in the appropriate timezone.
:param meeting_spec: models.meeting_spec
:return: datetime.datetime in the correct timezone
"""
meeting_datetime = meeting_spec.datetime
meeting_timezone = meeting_spec.meeting_subscription.get().timezone
return meeting_datetime.replace(tzinfo=utc).astimezone(timezone(meeting_timezone))
meeting_timezone = timezone(meeting_spec.meeting_subscription.get().timezone)
return meeting_timezone.localize(meeting_datetime)
3 changes: 1 addition & 2 deletions yelp_beans/logic/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from google.appengine.ext import ndb
from google.appengine.ext.db import NeedIndexError
from pytz import utc

from yelp_beans.models import MeetingSpec
from yelp_beans.models import MeetingSubscription
Expand Down Expand Up @@ -87,7 +86,7 @@ def get_subscription_dates(subscription):
return [
{
'id': date.urlsafe(),
'date': date.get().datetime.replace(tzinfo=utc).isoformat(),
'date': date.get().datetime.isoformat(),
'active': False
}
for date in subscription.datetime
Expand Down
4 changes: 2 additions & 2 deletions yelp_beans/send_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ def send_match_email(user, participants, meeting_spec):
'location': subscription.office + " " + subscription.location,
'meeting_start_day': meeting_datetime.strftime('%A'),
'meeting_start_date': meeting_datetime.strftime('%m/%d/%Y'),
'meeting_start_time': meeting_datetime.strftime('%I:%M %p'),
'meeting_end_time': meeting_datetime_end.strftime('%I:%M %p'),
'meeting_start_time': meeting_datetime.strftime('%I:%M %p %Z'),
'meeting_end_time': meeting_datetime_end.strftime('%I:%M %p %Z'),
'calendar_invite_url': create_google_calendar_invitation_link(
participants,
subscription.title,
Expand Down

0 comments on commit 8a3c9bd

Please sign in to comment.