-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_mail.py
60 lines (49 loc) · 1.88 KB
/
test_mail.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import unittest
import mail
import model
from google.appengine.ext import testbed
from google.appengine.api import users
class MailTestCase(unittest.TestCase):
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
def tearDown(self):
self.testbed.deactivate()
def test_generate_new_week_emails(self):
email = 'homer@snpp.com'
week_id = '201101'
body = 'line1\nline2\n'
user = users.User(email=email)
up = model.UserPreference.get_by_user(user)
model.WeekUpdate.add(up, week_id, body)
l = list(mail.Mail.generate_new_week_emails(week_id))
self.assertEqual(1, len(l))
self.assertEqual(email, l[0][0])
self.assertEqual('What are you up to this week?', l[0][1])
self.assertTrue(l[0][2].find(body) > 0)
def test_generate_reminder_emails(self):
email = 'homer@snpp.com'
week_id = '201101'
body = 'line1\nline2\n'
user = users.User(email=email)
up = model.UserPreference.get_by_user(user)
model.WeekUpdate.add(up, week_id, body)
l = list(mail.Mail.generate_reminder_emails('201102', week_id))
self.assertEqual(1, len(l))
self.assertEqual(email, l[0][0])
self.assertEqual('We want to know what you are up to this week.',
l[0][1])
self.assertTrue(l[0][2].find(body) > 0)
def test_generate_summary_emails(self):
email = 'homer@snpp.com'
week_id = '201101'
body = 'line1\nline2\n'
user = users.User(email=email)
up = model.UserPreference.get_by_user(user)
model.WeekUpdate.add(up, week_id, body)
l = list(mail.Mail.generate_summary_emails(week_id))
self.assertEqual(1, len(l))
self.assertEqual(email, l[0][0])
self.assertEqual('Everyone\'s updates for this week', l[0][1])
self.assertTrue(l[0][2].find(body) > 0)