~pidgeon690/pidge-groups/trunk

« back to all changes in this revision

Viewing changes to Apps/Email/tests/models.py

  • Committer: Fergus Ross Ferrier
  • Date: 2009-05-25 22:10:29 UTC
  • mfrom: (273.2.4 refactor+user)
  • Revision ID: hello@fergusrossferrier.co.uk-20090525221029-gqdycg3rfhxujqpz
Merged user-refactor fun.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
'''
4
4
 
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
9
9
 
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")
21
21
         
22
 
        self.userone = Person.objects.create(
23
 
            firstname = "One",
24
 
            lastname = "Must",
25
 
            email = "one_must@thepidge.com"
26
 
            )
27
 
 
28
 
        self.usertwo = Person.objects.create(
29
 
            firstname = "Two",
30
 
            lastname = "Django",
31
 
            email = "two_django@thepidge.com"
32
 
            )
33
 
 
34
 
        self.userthree = Person.objects.create(
35
 
            firstname = "Three",
36
 
            lastname = "Company",
37
 
            email = "three_company@thepidge.com"
 
22
        self.userone = User.objects.create(
 
23
            username = "userone",
 
24
            first_name = "One",
 
25
            last_name = "Must",
 
26
            email = "one_must@zepidge.com"
 
27
            )
 
28
 
 
29
        self.usertwo = User.objects.create(
 
30
            username = "twopidge",
 
31
            first_name = "Two",
 
32
            last_name = "Django",
 
33
            email = "two_django@zepidge.com"
 
34
            )
 
35
 
 
36
        self.userthree = User.objects.create(
 
37
            username = "usertrois",
 
38
            first_name = "Three",
 
39
            last_name = "Company",
 
40
            email = "three_company@vepidge.com"
38
41
            )
39
42
            
40
 
        self.userlist = PersonList.objects.create(
 
43
        self.userlist = Group.objects.create(
41
44
            name = "My First List",
42
45
            )
43
46
            
44
 
        self.userlist.people = [self.userone, self.usertwo]
 
47
        self.userlist.user_set = [self.userone, self.usertwo]
45
48
        
46
 
        self.anotheruserlist = PersonList.objects.create(
 
49
        self.anotheruserlist = Group.objects.create(
47
50
            name = "My Second List"
48
51
            )
49
 
        self.anotheruserlist.people = [self.userthree, self.usertwo]
 
52
        self.anotheruserlist.user_set = [self.userthree, self.usertwo]
50
53
        
51
 
        self.emptylist = PersonList.objects.create(
 
54
        self.emptylist = Group.objects.create(
52
55
            name = "My Dull List"
53
56
            )
54
57
    
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?"')
58
61
 
59
62
    # Add recipient
60
63
    
65
68
        self.assertEquals(EmailRecipient.objects.filter(email = self.emailtemplate).count(), 1)
66
69
 
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)
120
123
        
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)
126
129
    
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")
163
166
            
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"
168
172
            )
169
173
            
170
174
        self.recipient = EmailRecipient.objects.create(
171
 
            person = self.user,
 
175
            user = self.user,
172
176
            email = self.emailtemplate
173
177
            )
174
178
            
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]')