Skip to content

Commit

Permalink
thank team responds in json with total and num sent
Browse files Browse the repository at this point in the history
  • Loading branch information
jparker165 committed Jun 22, 2014
1 parent e0963b8 commit c87cd71
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
11 changes: 9 additions & 2 deletions backend/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,13 @@ def post(self):
'team =',self.request.POST['team']).filter(
'email !=', self.request.POST['reply_to'])

# if only sending to new members, filter out those that have already received emails
# yes this is executing another query, and it's ok because
# this will be done so infrequently
# FIXME: lookup from cache.Get.. or TeamTotal once those are sorted out
total_pledges = model.Pledge.all().filter(
'team =',self.request.POST['team']).count()

# if only sending to new members, filter out those that have already received emails
if self.request.POST['new_members'] == 'True':
pledges = pledges.filter('thank_you_sent_at =', None)

Expand All @@ -426,7 +431,9 @@ def post(self):
pledge.put()

logging.info('THANKING: %d PLEDGERS!!' % i)
self.response.write(i)
response_data = {'num_emailed': i, 'total_pledges': total_pledges}
self.response.content_type = 'application/json'
self.response.write(json.dumps(response_data))

options = util.EnableCors

Expand Down
13 changes: 10 additions & 3 deletions unittests/test_e2e.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
import logging
import datetime
import json

from google.appengine.api import mail_stub
from google.appengine.ext import db
Expand Down Expand Up @@ -373,7 +374,9 @@ def testThankTeam(self):
# 1 email sent is the created pledge
self.assertEquals(len(messages), 1)
# post response should be zero sent thank you emails
self.assertEquals(resp.text, '0')
resp_data = json.loads(resp.text)
self.assertEquals(resp_data['num_emailed'], 0)
self.assertEquals(resp_data['total_pledges'], 1)

# this is the happy path
post_data['reply_to'] = 'another@email.com'
Expand All @@ -384,14 +387,18 @@ def testThankTeam(self):
self.assertEquals(messages[1].reply_to, post_data["reply_to"])
self.assertEquals(messages[1].subject, post_data["subject"])
self.assertEquals(type(model.Pledge.all()[0].thank_you_sent_at), datetime.datetime)
self.assertEquals(resp.text, '1')
resp_data = json.loads(resp.text)
self.assertEquals(resp_data['num_emailed'], 1)
self.assertEquals(resp_data['total_pledges'], 1)

# make sure it isn't sent a message again when new_member is set to true
post_data['new_members'] = True
resp = self.app.post('/r/thank', post_data)
messages = self.mail_stub.get_sent_messages(to=self.pledge["email"])
self.assertEquals(len(messages), 2)
self.assertEquals(resp.text, '0')
resp_data = json.loads(resp.text)
self.assertEquals(resp_data['num_emailed'], 0)
self.assertEquals(resp_data['total_pledges'], 1)

def testUserInfoNotFound(self):
resp = self.app.get('/user-info/nouserhere', status=404)
Expand Down

0 comments on commit c87cd71

Please sign in to comment.