11import datetime
22import os
33import shutil
4+ from collections import OrderedDict
45
56from django .conf import settings
67from django .urls import reverse as urlreverse
78from django .utils .http import urlencode
9+ from pyquery import PyQuery
810
911import debug # pyflakes:ignore
1012
1517from ietf .person .factories import PersonFactory
1618from ietf .person .models import Person
1719from ietf .submit .models import Preapproval
20+ from ietf .utils .mail import outbox
1821from ietf .utils .test_utils import TestCase , login_testing_unauthorized
1922from ietf .utils .test_data import make_test_data
2023from ietf .secr .drafts .email import get_email_initial
@@ -134,23 +137,31 @@ def test_resurrect(self):
134137 confirm_url = urlreverse ('ietf.secr.drafts.views.confirm' , kwargs = {'id' :draft .name })
135138 do_action_url = urlreverse ('ietf.secr.drafts.views.do_action' , kwargs = {'id' :draft .name })
136139 view_url = urlreverse ('ietf.secr.drafts.views.view' , kwargs = {'id' :draft .name })
140+ subject = 'Resurrection of %s' % draft .get_base_name ()
137141 self .client .login (username = "secretary" , password = "secretary+password" )
138142 response = self .client .get (email_url )
139143 self .assertEqual (response .status_code , 200 )
144+ self .assertTrue ('<title>Drafts - Email</title>' in response .content )
145+ q = PyQuery (response .content )
146+ self .assertEqual (q ("#id_subject" ).val (), subject )
140147 post_data = {
141148 'action' : 'resurrect' ,
142149 'to' : 'john@example.com' ,
143150 'cc' : 'joe@example.com' ,
144- 'subject' : 'test' ,
151+ 'subject' : subject ,
145152 'body' : 'draft resurrected' ,
146153 'submit' : 'Save'
147154 }
148- response = self .client .post (email_url , post_data )
149155 response = self .client .post (confirm_url , post_data )
156+ self .assertEqual (response .status_code , 200 )
157+ self .assertTrue ('<title>Drafts - Confirm</title>' in response .content )
158+ self .assertEqual (response .context ['email' ]['subject' ], subject )
150159 response = self .client .post (do_action_url , post_data )
151160 self .assertRedirects (response , view_url )
152161 draft = Document .objects .get (name = draft .name )
153162 self .assertTrue (draft .get_state_slug ('draft' ) == 'active' )
163+ recv = outbox [- 1 ]
164+ self .assertEqual (recv ['Subject' ], subject )
154165
155166 def test_extend (self ):
156167 draft = make_test_data ()
@@ -161,10 +172,11 @@ def test_extend(self):
161172 view_url = urlreverse ('ietf.secr.drafts.views.view' , kwargs = {'id' :draft .name })
162173 expiration = datetime .datetime .today () + datetime .timedelta (days = 180 )
163174 expiration = expiration .replace (hour = 0 ,minute = 0 ,second = 0 ,microsecond = 0 )
175+ subject = 'Extension of Expiration Date for %s' % draft .get_base_name ()
164176 self .client .login (username = "secretary" , password = "secretary+password" )
165177 response = self .client .get (url )
166178 self .assertEqual (response .status_code , 200 )
167- get_data = {
179+ extend_data = {
168180 'action' : 'extend' ,
169181 'expiration_date' : expiration .strftime ('%Y-%m-%d' ),
170182 }
@@ -173,17 +185,22 @@ def test_extend(self):
173185 'expiration_date' : expiration .strftime ('%Y-%m-%d' ),
174186 'to' : 'john@example.com' ,
175187 'cc' : 'joe@example.com' ,
176- 'subject' : 'test' ,
177- 'body' : 'draft resurrected ' ,
188+ 'subject' : subject ,
189+ 'body' : 'draft extended ' ,
178190 'submit' : 'Save'
179191 }
180- response = self .client .get ( email_url + '?' + urlencode ( get_data ))
181- self .assertEqual (response . status_code , 200 )
192+ response = self .client .post ( url , extend_data )
193+ self .assertRedirects (response , email_url + '?' + urlencode ( extend_data ) )
182194 response = self .client .post (confirm_url , post_data )
195+ self .assertEqual (response .status_code , 200 )
196+ self .assertTrue ('<title>Drafts - Confirm</title>' in response .content )
197+ self .assertEqual (response .context ['email' ]['subject' ], subject )
183198 response = self .client .post (do_action_url , post_data )
184199 self .assertRedirects (response , view_url )
185200 draft = Document .objects .get (name = draft .name )
186201 self .assertTrue (draft .expires == expiration )
202+ recv = outbox [- 1 ]
203+ self .assertEqual (recv ['Subject' ], subject )
187204
188205 def test_withdraw (self ):
189206 draft = make_test_data ()
@@ -192,29 +209,32 @@ def test_withdraw(self):
192209 confirm_url = urlreverse ('ietf.secr.drafts.views.confirm' , kwargs = {'id' :draft .name })
193210 do_action_url = urlreverse ('ietf.secr.drafts.views.do_action' , kwargs = {'id' :draft .name })
194211 view_url = urlreverse ('ietf.secr.drafts.views.view' , kwargs = {'id' :draft .name })
212+ subject = 'Withdraw of %s' % draft .get_base_name ()
195213 self .client .login (username = "secretary" , password = "secretary+password" )
196214 response = self .client .get (url )
197215 self .assertEqual (response .status_code , 200 )
198- get_data = {
199- 'action' : 'withdraw' ,
200- 'withdraw_type' : 'ietf' ,
201- }
216+ withdraw_data = OrderedDict ([('action' , 'withdraw' ), ('withdraw_type' , 'ietf' )])
202217 post_data = {
203218 'action' : 'withdraw' ,
204219 'withdraw_type' : 'ietf' ,
205220 'to' : 'john@example.com' ,
206221 'cc' : 'joe@example.com' ,
207- 'subject' : 'test' ,
222+ 'subject' : subject ,
208223 'body' : 'draft resurrected' ,
209224 'submit' : 'Save'
210225 }
211- response = self .client .get ( email_url + '?' + urlencode ( get_data ))
212- self .assertEqual (response . status_code , 200 )
226+ response = self .client .post ( url , withdraw_data )
227+ self .assertRedirects (response , email_url + '?' + urlencode ( withdraw_data ) )
213228 response = self .client .post (confirm_url , post_data )
229+ self .assertEqual (response .status_code , 200 )
230+ self .assertTrue ('<title>Drafts - Confirm</title>' in response .content )
231+ self .assertEqual (response .context ['email' ]['subject' ], subject )
214232 response = self .client .post (do_action_url , post_data )
215233 self .assertRedirects (response , view_url )
216234 draft = Document .objects .get (name = draft .name )
217235 self .assertTrue (draft .get_state_slug ('draft' ) == 'ietf-rm' )
236+ recv = outbox [- 1 ]
237+ self .assertEqual (recv ['Subject' ], subject )
218238
219239 def test_authors (self ):
220240 draft = DocumentFactory ()
0 commit comments