Skip to content

Commit

Permalink
populate subscription data for initial setup #23
Browse files Browse the repository at this point in the history
  • Loading branch information
kentwills committed Mar 18, 2017
1 parent a1e1e66 commit cabdf98
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cron.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ cron:
url: /tasks/match_employees
schedule: every wednesday 11:00
timezone: US/Pacific

- description: Initialization (noop when subscriptions)
url: /tasks/init
schedule: every monday 11:00
timezone: US/Pacific
12 changes: 12 additions & 0 deletions tests/routes/tasks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
from google.appengine.ext import ndb

from yelp_beans.models import MeetingSpec
from yelp_beans.models import MeetingSubscription
from yelp_beans.models import User
from yelp_beans.models import UserSubscriptionPreferences
from yelp_beans.routes.tasks import generate_meeting_specs
from yelp_beans.routes.tasks import init
from yelp_beans.routes.tasks import weekly_opt_in


Expand Down Expand Up @@ -42,3 +44,13 @@ def test_weekly_opt_in(minimal_database, subscription):
user1.put()
response = weekly_opt_in()
assert response == 'OK'


def test_init(minimal_database):
assert len(MeetingSubscription.query().fetch()) == 0
response = init()
assert response == 'OK'
assert len(MeetingSubscription.query().fetch()) == 1
response = init()
assert response == 'OK'
assert len(MeetingSubscription.query().fetch()) == 1
32 changes: 32 additions & 0 deletions yelp_beans/routes/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from __future__ import unicode_literals

import logging
from datetime import datetime
from datetime import timedelta

from flask import Blueprint

Expand All @@ -19,6 +21,8 @@
from yelp_beans.models import MeetingParticipant
from yelp_beans.models import MeetingRequest
from yelp_beans.models import MeetingSubscription
from yelp_beans.models import Rule
from yelp_beans.models import SubscriptionDateTime
from yelp_beans.send_email import send_batch_meeting_confirmation_email
from yelp_beans.send_email import send_batch_unmatched_email
from yelp_beans.send_email import send_batch_weekly_opt_in_email
Expand Down Expand Up @@ -92,3 +96,31 @@ def send_match_emails():
logging.info(matches)
send_batch_meeting_confirmation_email(matches, spec)
return "OK"


@tasks.route('/init', methods=['GET'])
def init():
subscriptions = MeetingSubscription.query().fetch()
if not subscriptions:
preference_1 = SubscriptionDateTime(
datetime=datetime.now()
).put()
preference_2 = SubscriptionDateTime(
datetime=datetime.now() + timedelta(days=1)
).put()
rule = Rule(
name='office',
value='USA: CA SF New Montgomery Office'
).put()

MeetingSubscription(
title='Yelp Weekly',
size=2,
location='8th Floor',
office='USA: CA SF New Montgomery Office',
timezone='US/Pacific',
datetime=[preference_1, preference_2],
rules=[rule],
rule_logic='any'
).put()
return "OK"

0 comments on commit cabdf98

Please sign in to comment.