comparison test/test_mailgw.py @ 666:d1567c2433c4

Made the email checking spit out a diff - much easier to spot the problem!
author Richard Jones <richard@users.sourceforge.net>
date Tue, 19 Mar 2002 06:37:00 +0000
parents 9382ad731c1c
children 4afa9be56dd3
comparison
equal deleted inserted replaced
665:9382ad731c1c 666:d1567c2433c4
6 # 6 #
7 # This module is distributed in the hope that it will be useful, 7 # This module is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of 8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 # 10 #
11 # $Id: test_mailgw.py,v 1.14 2002-03-18 18:32:00 rochecompaan Exp $ 11 # $Id: test_mailgw.py,v 1.15 2002-03-19 06:37:00 richard Exp $
12 12
13 import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys 13 import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys, difflib
14 14
15 from roundup.mailgw import MailGW 15 from roundup.mailgw import MailGW
16 from roundup import init, instance 16 from roundup import init, instance
17 17
18 class MailgwTestCase(unittest.TestCase): 18 # TODO: make this output only enough equal lines for context, not all of
19 # them
20 class DiffHelper:
21 def compareStrings(self, s2, s1):
22 '''Note the reversal of s2 and s1 - difflib.SequenceMatcher wants
23 the first to be the "original" but in the calls in this file,
24 the second arg is the original. Ho hum.
25 '''
26 if s1 == s2:
27 return
28 l1=s1.split('\n')
29 l2=s2.split('\n')
30 s = difflib.SequenceMatcher(None, l1, l2)
31 res = ['Generated message not correct (diff follows):']
32 for value, s1s, s1e, s2s, s2e in s.get_opcodes():
33 if value == 'equal':
34 for i in range(s1s, s1e):
35 res.append(' %s'%l1[i])
36 elif value == 'delete':
37 for i in range(s1s, s1e):
38 res.append('- %s'%l1[i])
39 elif value == 'insert':
40 for i in range(s2s, s2e):
41 res.append('+ %s'%l2[i])
42 elif value == 'replace':
43 for i, j in zip(range(s1s, s1e), range(s2s, s2e)):
44 res.append('- %s'%l1[i])
45 res.append('+ %s'%l2[j])
46
47 raise AssertionError, '\n'.join(res)
48
49 class MailgwTestCase(unittest.TestCase, DiffHelper):
19 count = 0 50 count = 0
20 schema = 'classic' 51 schema = 'classic'
21 def setUp(self): 52 def setUp(self):
22 MailgwTestCase.count = MailgwTestCase.count + 1 53 MailgwTestCase.count = MailgwTestCase.count + 1
23 self.dirname = '_test_%s'%self.count 54 self.dirname = '_test_%s'%self.count
111 handler = self.instance.MailGW(self.instance, self.db) 142 handler = self.instance.MailGW(self.instance, self.db)
112 # TODO: fix the damn config - this is apalling 143 # TODO: fix the damn config - this is apalling
113 self.db.config.MESSAGES_TO_AUTHOR = 'yes' 144 self.db.config.MESSAGES_TO_AUTHOR = 'yes'
114 handler.main(message) 145 handler.main(message)
115 146
116 self.assertEqual(open(os.environ['SENDMAILDEBUG']).read(), 147 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
117 '''FROM: roundup-admin@fill.me.in. 148 '''FROM: roundup-admin@fill.me.in.
118 TO: chef@bork.bork.bork, mary@test, richard@test 149 TO: chef@bork.bork.bork, mary@test, richard@test
119 Content-Type: text/plain 150 Content-Type: text/plain
120 Subject: [issue1] Testing... 151 Subject: [issue1] Testing...
121 To: chef@bork.bork.bork, mary@test, richard@test 152 To: chef@bork.bork.bork, mary@test, richard@test
140 title: Testing... 171 title: Testing...
141 ___________________________________________________ 172 ___________________________________________________
142 "Roundup issue tracker" <issue_tracker@fill.me.in.> 173 "Roundup issue tracker" <issue_tracker@fill.me.in.>
143 http://some.useful.url/issue1 174 http://some.useful.url/issue1
144 ___________________________________________________ 175 ___________________________________________________
145 ''', 'Generated message not correct') 176 ''')
146 177
147 # BUG 178 # BUG
148 # def testMultipart(self): 179 # def testMultipart(self):
149 # '''With more than one part''' 180 # '''With more than one part'''
150 # see MultipartEnc tests: but if there is more than one part 181 # see MultipartEnc tests: but if there is more than one part
166 This is a followup 197 This is a followup
167 ''') 198 ''')
168 handler = self.instance.MailGW(self.instance, self.db) 199 handler = self.instance.MailGW(self.instance, self.db)
169 handler.main(message) 200 handler.main(message)
170 201
171 self.assertEqual(open(os.environ['SENDMAILDEBUG']).read(), 202 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
172 '''FROM: roundup-admin@fill.me.in. 203 '''FROM: roundup-admin@fill.me.in.
173 TO: chef@bork.bork.bork, mary@test, john@test 204 TO: chef@bork.bork.bork, mary@test, john@test
174 Content-Type: text/plain 205 Content-Type: text/plain
175 Subject: [issue1] Testing... 206 Subject: [issue1] Testing...
176 To: chef@bork.bork.bork, mary@test, john@test 207 To: chef@bork.bork.bork, mary@test, john@test
194 status: unread -> chatting 225 status: unread -> chatting
195 ___________________________________________________ 226 ___________________________________________________
196 "Roundup issue tracker" <issue_tracker@fill.me.in.> 227 "Roundup issue tracker" <issue_tracker@fill.me.in.>
197 http://some.useful.url/issue1 228 http://some.useful.url/issue1
198 ___________________________________________________ 229 ___________________________________________________
199 ''', 'Generated message not correct') 230 ''')
200 231
201 def testFollowup2(self): 232 def testFollowup2(self):
202 self.testNewIssue() 233 self.testNewIssue()
203 message = cStringIO.StringIO('''Content-Type: text/plain; 234 message = cStringIO.StringIO('''Content-Type: text/plain;
204 charset="iso-8859-1" 235 charset="iso-8859-1"
210 241
211 This is a second followup 242 This is a second followup
212 ''') 243 ''')
213 handler = self.instance.MailGW(self.instance, self.db) 244 handler = self.instance.MailGW(self.instance, self.db)
214 handler.main(message) 245 handler.main(message)
215 self.assertEqual(open(os.environ['SENDMAILDEBUG']).read(), 246 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
216 '''FROM: roundup-admin@fill.me.in. 247 '''FROM: roundup-admin@fill.me.in.
217 TO: chef@bork.bork.bork, richard@test 248 TO: chef@bork.bork.bork, richard@test
218 Content-Type: text/plain 249 Content-Type: text/plain
219 Subject: [issue1] Testing... 250 Subject: [issue1] Testing...
220 To: chef@bork.bork.bork, richard@test 251 To: chef@bork.bork.bork, richard@test
236 status: unread -> chatting 267 status: unread -> chatting
237 ___________________________________________________ 268 ___________________________________________________
238 "Roundup issue tracker" <issue_tracker@fill.me.in.> 269 "Roundup issue tracker" <issue_tracker@fill.me.in.>
239 http://some.useful.url/issue1 270 http://some.useful.url/issue1
240 ___________________________________________________ 271 ___________________________________________________
241 ''', 'Generated message not correct') 272 ''')
242 273
243 def testFollowupTitleMatch(self): 274 def testFollowupTitleMatch(self):
244 self.testNewIssue() 275 self.testNewIssue()
245 message = cStringIO.StringIO('''Content-Type: text/plain; 276 message = cStringIO.StringIO('''Content-Type: text/plain;
246 charset="iso-8859-1" 277 charset="iso-8859-1"
253 This is a followup 284 This is a followup
254 ''') 285 ''')
255 handler = self.instance.MailGW(self.instance, self.db) 286 handler = self.instance.MailGW(self.instance, self.db)
256 handler.main(message) 287 handler.main(message)
257 288
258 self.assertEqual(open(os.environ['SENDMAILDEBUG']).read(), 289 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
259 '''FROM: roundup-admin@fill.me.in. 290 '''FROM: roundup-admin@fill.me.in.
260 TO: chef@bork.bork.bork, mary@test, john@test 291 TO: chef@bork.bork.bork, mary@test, john@test
261 Content-Type: text/plain 292 Content-Type: text/plain
262 Subject: [issue1] Testing... 293 Subject: [issue1] Testing...
263 To: chef@bork.bork.bork, mary@test, john@test 294 To: chef@bork.bork.bork, mary@test, john@test
281 status: unread -> chatting 312 status: unread -> chatting
282 ___________________________________________________ 313 ___________________________________________________
283 "Roundup issue tracker" <issue_tracker@fill.me.in.> 314 "Roundup issue tracker" <issue_tracker@fill.me.in.>
284 http://some.useful.url/issue1 315 http://some.useful.url/issue1
285 ___________________________________________________ 316 ___________________________________________________
286 ''') #, 'Generated message not correct') 317 ''')
287 318
288 def testEnc01(self): 319 def testEnc01(self):
289 self.testNewIssue() 320 self.testNewIssue()
290 message = cStringIO.StringIO('''Content-Type: text/plain; 321 message = cStringIO.StringIO('''Content-Type: text/plain;
291 charset="iso-8859-1" 322 charset="iso-8859-1"
301 A message with encoding (encoded oe =F6) 332 A message with encoding (encoded oe =F6)
302 333
303 ''') 334 ''')
304 handler = self.instance.MailGW(self.instance, self.db) 335 handler = self.instance.MailGW(self.instance, self.db)
305 handler.main(message) 336 handler.main(message)
306 message_data = open(os.environ['SENDMAILDEBUG']).read() 337 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
307 self.assertEqual(message_data,
308 '''FROM: roundup-admin@fill.me.in. 338 '''FROM: roundup-admin@fill.me.in.
309 TO: chef@bork.bork.bork, richard@test 339 TO: chef@bork.bork.bork, richard@test
310 Content-Type: text/plain 340 Content-Type: text/plain
311 Subject: [issue1] Testing... 341 Subject: [issue1] Testing...
312 To: chef@bork.bork.bork, richard@test 342 To: chef@bork.bork.bork, richard@test
327 status: unread -> chatting 357 status: unread -> chatting
328 ___________________________________________________ 358 ___________________________________________________
329 "Roundup issue tracker" <issue_tracker@fill.me.in.> 359 "Roundup issue tracker" <issue_tracker@fill.me.in.>
330 http://some.useful.url/issue1 360 http://some.useful.url/issue1
331 ___________________________________________________ 361 ___________________________________________________
332 ''', 'Generated message not correct') 362 ''')
333 363
334 364
335 def testMultipartEnc01(self): 365 def testMultipartEnc01(self):
336 self.testNewIssue() 366 self.testNewIssue()
337 message = cStringIO.StringIO('''Content-Type: text/plain; 367 message = cStringIO.StringIO('''Content-Type: text/plain;
355 A message with first part encoded (encoded oe =F6) 385 A message with first part encoded (encoded oe =F6)
356 386
357 ''') 387 ''')
358 handler = self.instance.MailGW(self.instance, self.db) 388 handler = self.instance.MailGW(self.instance, self.db)
359 handler.main(message) 389 handler.main(message)
360 message_data = open(os.environ['SENDMAILDEBUG']).read() 390 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
361 self.assertEqual(message_data,
362 '''FROM: roundup-admin@fill.me.in. 391 '''FROM: roundup-admin@fill.me.in.
363 TO: chef@bork.bork.bork, richard@test 392 TO: chef@bork.bork.bork, richard@test
364 Content-Type: text/plain 393 Content-Type: text/plain
365 Subject: [issue1] Testing... 394 Subject: [issue1] Testing...
366 To: chef@bork.bork.bork, richard@test 395 To: chef@bork.bork.bork, richard@test
381 status: unread -> chatting 410 status: unread -> chatting
382 ___________________________________________________ 411 ___________________________________________________
383 "Roundup issue tracker" <issue_tracker@fill.me.in.> 412 "Roundup issue tracker" <issue_tracker@fill.me.in.>
384 http://some.useful.url/issue1 413 http://some.useful.url/issue1
385 ___________________________________________________ 414 ___________________________________________________
386 ''', 'Generated message not correct') 415 ''')
387 416
388 class ExtMailgwTestCase(MailgwTestCase): 417 class ExtMailgwTestCase(MailgwTestCase):
389 schema = 'extended' 418 schema = 'extended'
390 419
391 def suite(): 420 def suite():
392 l = [unittest.makeSuite(MailgwTestCase, 'test'), 421 l = [unittest.makeSuite(MailgwTestCase, 'test'),
393 unittest.makeSuite(ExtMailgwTestCase, 'test') 422 # unittest.makeSuite(ExtMailgwTestCase, 'test')
394 ] 423 ]
395 return unittest.TestSuite(l) 424 return unittest.TestSuite(l)
396 425
397 426
398 # 427 #
399 # $Log: not supported by cvs2svn $ 428 # $Log: not supported by cvs2svn $
429 # Revision 1.14 2002/03/18 18:32:00 rochecompaan
430 # All messages sent to the nosy list are now encoded as quoted-printable.
431 #
400 # Revision 1.13 2002/02/15 07:08:45 richard 432 # Revision 1.13 2002/02/15 07:08:45 richard
401 # . Alternate email addresses are now available for users. See the MIGRATION 433 # . Alternate email addresses are now available for users. See the MIGRATION
402 # file for info on how to activate the feature. 434 # file for info on how to activate the feature.
403 # 435 #
404 # Revision 1.12 2002/02/15 00:13:38 richard 436 # Revision 1.12 2002/02/15 00:13:38 richard

Roundup Issue Tracker: http://roundup-tracker.org/