1+ import datetime
2+
3+ from django .conf import settings
14import django .test
25
36from ietf .utils .test_utils import SimpleUrlTestCase , canonicalize_sitemap
4- from ietf .utils .test_runner import mail_outbox
7+ from ietf .utils .test_data import make_test_data
8+ from ietf .utils .mail import outbox
59
610from ietf .announcements .models import ScheduledAnnouncement
711
@@ -27,13 +31,13 @@ def test_send_plain_announcement(self):
2731 content_type = "" ,
2832 )
2933
30- mailbox_before = len (mail_outbox )
34+ mailbox_before = len (outbox )
3135
3236 from ietf .announcements .send_scheduled import send_scheduled_announcement
3337 send_scheduled_announcement (a )
3438
35- self .assertEquals (len (mail_outbox ), mailbox_before + 1 )
36- self .assertTrue ("This is a test" in mail_outbox [- 1 ]["Subject" ])
39+ self .assertEquals (len (outbox ), mailbox_before + 1 )
40+ self .assertTrue ("This is a test" in outbox [- 1 ]["Subject" ])
3741 self .assertTrue (ScheduledAnnouncement .objects .get (id = a .id ).mail_sent )
3842
3943 def test_send_mime_announcement (self ):
@@ -48,12 +52,84 @@ def test_send_mime_announcement(self):
4852 content_type = 'Multipart/Mixed; Boundary="NextPart"' ,
4953 )
5054
51- mailbox_before = len (mail_outbox )
55+ mailbox_before = len (outbox )
5256
5357 from ietf .announcements .send_scheduled import send_scheduled_announcement
5458 send_scheduled_announcement (a )
5559
56- self .assertEquals (len (mail_outbox ), mailbox_before + 1 )
57- self .assertTrue ("This is a test" in mail_outbox [- 1 ]["Subject" ])
58- self .assertTrue ("--NextPart" in mail_outbox [- 1 ].as_string ())
60+ self .assertEquals (len (outbox ), mailbox_before + 1 )
61+ self .assertTrue ("This is a test" in outbox [- 1 ]["Subject" ])
62+ self .assertTrue ("--NextPart" in outbox [- 1 ].as_string ())
5963 self .assertTrue (ScheduledAnnouncement .objects .get (id = a .id ).mail_sent )
64+
65+
66+ class SendScheduledAnnouncementsTestCaseREDESIGN (django .test .TestCase ):
67+ fixtures = ["names" ]
68+
69+ def test_send_plain_announcement (self ):
70+ from ietf .announcements .models import Message , SendQueue
71+ from redesign .person .models import Person
72+
73+ make_test_data ()
74+
75+ msg = Message .objects .create (
76+ by = Person .objects .get (name = "(System)" ),
77+ subject = "This is a test" ,
78+ to = "test@example.com" ,
79+ frm = "testmonkey@example.com" ,
80+ cc = "cc.a@example.com, cc.b@example.com" ,
81+ bcc = "bcc@example.com" ,
82+ body = "Hello World!" ,
83+ content_type = "" ,
84+ )
85+
86+ q = SendQueue .objects .create (
87+ by = Person .objects .get (name = "(System)" ),
88+ message = msg ,
89+ send_at = datetime .datetime .now () + datetime .timedelta (hours = 12 )
90+ )
91+
92+ mailbox_before = len (outbox )
93+
94+ from ietf .announcements .send_scheduled import send_scheduled_announcement
95+ send_scheduled_announcement (q )
96+
97+ self .assertEquals (len (outbox ), mailbox_before + 1 )
98+ self .assertTrue ("This is a test" in outbox [- 1 ]["Subject" ])
99+ self .assertTrue (SendQueue .objects .get (id = q .id ).sent_at )
100+
101+ def test_send_mime_announcement (self ):
102+ from ietf .announcements .models import Message , SendQueue
103+ from redesign .person .models import Person
104+
105+ make_test_data ()
106+
107+ msg = Message .objects .create (
108+ by = Person .objects .get (name = "(System)" ),
109+ subject = "This is a test" ,
110+ to = "test@example.com" ,
111+ frm = "testmonkey@example.com" ,
112+ cc = "cc.a@example.com, cc.b@example.com" ,
113+ bcc = "bcc@example.com" ,
114+ body = '--NextPart\r \n \r \n A New Internet-Draft is available from the on-line Internet-Drafts directories.\r \n --NextPart\r \n Content-Type: Message/External-body;\r \n \t name="draft-huang-behave-bih-01.txt";\r \n \t site="ftp.ietf.org";\r \n \t access-type="anon-ftp";\r \n \t directory="internet-drafts"\r \n \r \n Content-Type: text/plain\r \n Content-ID: <2010-07-30001541.I-D@ietf.org>\r \n \r \n --NextPart--' ,
115+ content_type = 'Multipart/Mixed; Boundary="NextPart"' ,
116+ )
117+
118+ q = SendQueue .objects .create (
119+ by = Person .objects .get (name = "(System)" ),
120+ message = msg ,
121+ send_at = datetime .datetime .now () + datetime .timedelta (hours = 12 )
122+ )
123+
124+ mailbox_before = len (outbox )
125+
126+ from ietf .announcements .send_scheduled import send_scheduled_announcement
127+ send_scheduled_announcement (q )
128+
129+ self .assertEquals (len (outbox ), mailbox_before + 1 )
130+ self .assertTrue ("This is a test" in outbox [- 1 ]["Subject" ])
131+ self .assertTrue ("--NextPart" in outbox [- 1 ].as_string ())
132+ self .assertTrue (SendQueue .objects .get (id = q .id ).sent_at )
133+
134+ if settings .USE_DB_REDESIGN_PROXY_CLASSES :
135+ SendScheduledAnnouncementsTestCase = SendScheduledAnnouncementsTestCaseREDESIGN
0 commit comments