~pidgeon690/pidge-events/trunk

« back to all changes in this revision

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

  • Committer: Fergus Ross Ferrier
  • Date: 2009-05-26 15:09:25 UTC
  • Revision ID: hello@fergusrossferrier.co.uk-20090526150925-695q8cy20mahagdw
Split events to separate app and repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
'''
2
 
Publicity.tests.models
3
 
'''
4
 
 
5
 
from Publicity.models import CommsOfficer
6
 
from Groups.models import Group, GroupCategory
7
 
from django.contrib.auth.models import User
8
 
from Email.models import EmailTemplate, EmailRecipient
9
 
from django.core import mail
10
 
from django.test import TestCase
11
 
 
12
 
class CommsOfficerTests(TestCase):
13
 
    
14
 
    def setUp(self):
15
 
        # Add People
16
 
        self.anna = User.objects.create(
17
 
            username = "annaza",
18
 
            first_name = "Anna",
19
 
            last_name = "Binton",
20
 
            email = "abz222@cam.ac.uk")
21
 
        self.bobo = User.objects.create(
22
 
            username = "bobzaa",
23
 
            first_name = "Bobo",
24
 
            last_name = "The Bear",
25
 
            email = "bobothebear@cam.ac.uk")
26
 
        self.charliferous = User.objects.create(
27
 
            username = "charlz",
28
 
            first_name = "Charliferous",
29
 
            last_name = "III",
30
 
            email = "cIII@cam.ac.uk")
31
 
        
32
 
        # College Group Type
33
 
        self.college, created = GroupCategory.objects.get_or_create(name = "College", defaults = {'small_name': "COL", 'all_can_create': False})
34
 
        # College Student Union Group Type
35
 
        self.college_union, created = GroupCategory.objects.get_or_create(name = "College Students' Union", defaults = {'small_name': "CSU", 'all_can_create': False})
36
 
        
37
 
        # Create two colleges
38
 
        self.binary = Group.objects.create(official_name = "Binary College", category = self.college)
39
 
        self.porterhouse = Group.objects.create(official_name = "Porterhouse", category = self.college)
40
 
 
41
 
        # Create three SUs - two notionally at one college
42
 
        self.binary_juniors = Group.objects.create(official_name = "Binary Juniors", category = self.college_union)
43
 
        self.binary_seniors = Group.objects.create(official_name = "Binary Seniors", category = self.college_union)
44
 
        self.porterhouse_six_club = Group.objects.create(official_name = "Porterhouse Six Club", category = self.college_union)
45
 
        
46
 
        # Anna is comms officer of binary juniors
47
 
        self.anna_work = CommsOfficer.objects.create(
48
 
            college = self.binary,
49
 
            body = self.binary_juniors,
50
 
            body_grad = False,
51
 
            position_name = "Comms Officer",
52
 
            position_email = "anna@binaryjs.com",
53
 
            contact = self.anna
54
 
        )
55
 
        # Bobo is secretary of binary seniors
56
 
        self.bobo_work = CommsOfficer.objects.create(
57
 
            college = self.binary,
58
 
            body = self.binary_seniors,
59
 
            body_grad = True,
60
 
            position_name = "Secretary",
61
 
            position_email = "sec@binaryseniorroom.com",
62
 
            contact = self.bobo
63
 
        )        
64
 
        # Charliferous is an officer of porterhouse six club
65
 
        self.char_work = CommsOfficer.objects.create(
66
 
            college = self.porterhouse,
67
 
            body = self.porterhouse_six_club,
68
 
            body_grad = False,
69
 
            contact = self.charliferous
70
 
        )
71
 
        
72
 
        # And an emailtemplate
73
 
        self.theemail = EmailTemplate.objects.create(
74
 
            name = "Fergus' Email",
75
 
            email_reply_to = "friverlous@gmail.com",
76
 
            email_reply_to_name = "Fergus McQueen",
77
 
            email_from = "fergus@mypidge.com",
78
 
            email_from_name = "Fergus McQueen",
79
 
            subject = "{{ user.firstname }}, this is it",
80
 
            body = "Dear {{ user.firstname }}, here's an exciting email for you."
81
 
        )
82
 
 
83
 
 
84
 
    def testCommsOfficerStringRep(self):
85
 
        ''' CommsOfficer has a suitable string representation '''
86
 
        self.failUnlessEqual(unicode(self.char_work), "Charliferous III - Porterhouse Six Club relevant officer")
87
 
 
88
 
    def testSendOne(self):
89
 
        ''' Send a mailing to one particular comms officer. '''
90
 
        CommsOfficer.objects.send(self.theemail, [self.char_work])
91
 
        # Queues one recipient
92
 
        self.assertEquals(EmailRecipient.objects.filter(email = self.theemail).count(), 1)
93
 
        # And it's to Charliferous to his personal email address
94
 
        self.assertEquals(EmailRecipient.objects.get(email = self.theemail).alternate_address, '')
95
 
        
96
 
    def testSendAll(self):
97
 
        ''' Send a mailing to all SU's comms officers. '''
98
 
        CommsOfficer.objects.send_all(self.theemail)
99
 
        # Queues three recipients
100
 
        self.assertEquals(EmailRecipient.objects.filter(email = self.theemail).count(), 3)
101
 
        # Each message has one of their names etc
102
 
        
103
 
    def testSendUndergrad(self):
104
 
        ''' Send a mailing to undergrad SU's comms officers. '''
105
 
        CommsOfficer.objects.send_undergrad(self.theemail)
106
 
        # Creates 2 recipients - one to Anna and one to Char
107
 
        self.assertEquals(EmailRecipient.objects.filter(email = self.theemail).count(), 2)
108
 
    
109
 
    def testSendPostgrad(self):
110
 
        ''' Send a mailing to postgrad SU's comms officers. '''
111
 
        CommsOfficer.objects.send_postgrad(self.theemail)
112
 
        # Creates 1 email message
113
 
        self.assertEquals(EmailRecipient.objects.filter(email = self.theemail).count(), 1)
114
 
        # And it's to Bobo
115
 
        self.assertEquals(EmailRecipient.objects.get(email = self.theemail).alternate_address, 'sec@binaryseniorroom.com')
116