5
5
from Email.models import EmailTemplate, EmailRecipient
6
from Users.models import Person, PersonList
6
from django.contrib.auth.models import User, Group
7
7
from django.core import mail
8
8
from django.test import TestCase
16
16
email_reply_to_name = "MyPidge.com",
17
17
email_from = "fergus@mypidge.com",
18
18
email_from_name = "MyPidge.com",
19
subject = "{{ person.firstname }}, would you like it?",
20
body = "You're never going to believe it, {{ person.firstname }}. We've only gone and got the mailing list system working!\n\nFergus Ross Ferrier")
19
subject = "{{ user.first_name }}, would you like it?",
20
body = "You're never going to believe it, {{ user.first_name }}. We've only gone and got the mailing list system working!\n\nFergus Ross Ferrier")
22
self.userone = Person.objects.create(
25
email = "one_must@thepidge.com"
28
self.usertwo = Person.objects.create(
31
email = "two_django@thepidge.com"
34
self.userthree = Person.objects.create(
37
email = "three_company@thepidge.com"
22
self.userone = User.objects.create(
26
email = "one_must@zepidge.com"
29
self.usertwo = User.objects.create(
30
username = "twopidge",
33
email = "two_django@zepidge.com"
36
self.userthree = User.objects.create(
37
username = "usertrois",
39
last_name = "Company",
40
email = "three_company@vepidge.com"
40
self.userlist = PersonList.objects.create(
43
self.userlist = Group.objects.create(
41
44
name = "My First List",
44
self.userlist.people = [self.userone, self.usertwo]
47
self.userlist.user_set = [self.userone, self.usertwo]
46
self.anotheruserlist = PersonList.objects.create(
49
self.anotheruserlist = Group.objects.create(
47
50
name = "My Second List"
49
self.anotheruserlist.people = [self.userthree, self.usertwo]
52
self.anotheruserlist.user_set = [self.userthree, self.usertwo]
51
self.emptylist = PersonList.objects.create(
54
self.emptylist = Group.objects.create(
52
55
name = "My Dull List"
55
58
def test_unicode_name(self):
56
59
''' Check unicode string rep of EmailTemplate '''
57
self.failUnlessEqual(unicode(self.emailtemplate), 'My Test List: "{{ person.firstname }}, would you like it?"')
60
self.failUnlessEqual(unicode(self.emailtemplate), 'My Test List: "{{ user.first_name }}, would you like it?"')
65
68
self.assertEquals(EmailRecipient.objects.filter(email = self.emailtemplate).count(), 1)
67
70
def test_add_recipient_alternate_email(self):
68
''' We can send the email to an email address other than the person's normal email address '''
71
''' We can send the email to an email address other than the user's normal email address '''
69
72
self.assertEquals(EmailRecipient.objects.filter(email = self.emailtemplate).count(), 0)
70
73
alternate_email = "testthisemail@there.com"
71
74
self.emailtemplate.add_recipient(self.userone, alternate_email = alternate_email)
121
124
def test_send_template_leak(self):
122
125
''' Sending EmailTemplate with stray {}s in templates '''
123
self.emailtemplate.subject = "{ person.firstname}} Hey there"
126
self.emailtemplate.subject = "{ user.first_name}} Hey there"
124
127
self.emailtemplate.add_list(self.userlist)
125
128
self.assertRaises(EmailTemplate.EmailTemplateError, self.emailtemplate.send)
127
130
def test_send_alternate_email(self):
128
''' Sending template to Person with alternate email uses that email '''
131
''' Sending template to User with alternate email uses that email '''
129
132
alternate_email = "testthisemail@there.com"
130
133
self.emailtemplate.add_recipient(self.userone, alternate_email = alternate_email)
131
134
self.emailtemplate.send()
158
161
email_reply_to_name = "MyPidge.com",
159
162
email_from = "fergus@mypidge.com",
160
163
email_from_name = "MyPidge.com",
161
subject = "{{ person.firstname }}, would you like it?",
162
body = "You're never going to believe it, {{ person.firstname }}. We've only gone and got the mailing list system working!\n\nFergus Ross Ferrier")
164
subject = "{{ user.first_name }}, would you like it?",
165
body = "You're never going to believe it, {{ user.first_name }}. We've only gone and got the mailing list system working!\n\nFergus Ross Ferrier")
164
self.user = Person.objects.create(
165
firstname = "Fergus",
166
lastname = "Ferrier",
167
self.user = User.objects.create(
168
username = "usnsusus",
169
first_name = "Fergus",
170
last_name = "Ferrier",
167
171
email = "ferg@thepidge.com"
170
174
self.recipient = EmailRecipient.objects.create(
172
176
email = self.emailtemplate
175
179
def test_unicode_name(self):
176
180
''' Check unicode string rep of EmailRecipient '''
177
self.failUnlessEqual(unicode(self.recipient), 'My Test List: "{{ person.firstname }}, would you like it?" Fergus Ferrier [None]')
181
self.failUnlessEqual(unicode(self.recipient), 'My Test List: "{{ user.first_name }}, would you like it?" Fergus Ferrier [None]')