comparison test/test_mailgw.py @ 1795:08b013acfec8

Message comparison is no longer a straight text comparison... ...but a semantic comparison. The header order changed while refactoring email sending, but this way we won't have to worry about that affecting the tests anymore.
author Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
date Sun, 07 Sep 2003 13:08:08 +0000
parents dbe541c1aa39
children 4de2e611b6f3
comparison
equal deleted inserted replaced
1794:2724d14f0c42 1795:08b013acfec8
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.48 2003-09-06 10:37:10 jlgijsbers Exp $ 11 # $Id: test_mailgw.py,v 1.49 2003-09-07 13:08:08 jlgijsbers Exp $
12 12
13 import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys, difflib 13 import unittest, tempfile, os, shutil, errno, imp, sys, difflib, rfc822
14 import rfc822 14
15 15 from cStringIO import StringIO
16 # Note: Should parse emails according to RFC2822 instead of performing a
17 # literal string comparision. Parsing the messages allows the tests to work for
18 # any legal serialization of an email.
19 #try :
20 # import email
21 #except ImportError :
22 # import rfc822 as email
23 16
24 from roundup.mailgw import MailGW, Unauthorized, uidFromAddress 17 from roundup.mailgw import MailGW, Unauthorized, uidFromAddress
25 from roundup import init, instance, rfc2822 18 from roundup import init, instance, rfc2822
26 19
27 # TODO: make this output only enough equal lines for context, not all of 20 class Message(rfc822.Message):
28 # them 21 """String-based Message class with equivalence test."""
22 def __init__(self, s):
23 rfc822.Message.__init__(self, StringIO(s.strip()))
24
25 def __eq__(self, other):
26 del self['date'], other['date']
27
28 self.headers.sort()
29 other.headers.sort()
30
31 self.rewindbody()
32 other.rewindbody()
33
34 return (self.headers == other.headers and
35 self.fp.read() == other.fp.read())
36
37 # TODO: Do a semantic diff instead of a straight text diff when a test fails.
29 class DiffHelper: 38 class DiffHelper:
39 def compareMessages(self, s2, s1):
40 """Compare messages for semantic equivalence."""
41 if not Message(s2) == Message(s1):
42 self.compareStrings(s2, s1)
43
30 def compareStrings(self, s2, s1): 44 def compareStrings(self, s2, s1):
31 '''Note the reversal of s2 and s1 - difflib.SequenceMatcher wants 45 '''Note the reversal of s2 and s1 - difflib.SequenceMatcher wants
32 the first to be the "original" but in the calls in this file, 46 the first to be the "original" but in the calls in this file,
33 the second arg is the original. Ho hum. 47 the second arg is the original. Ho hum.
34 ''' 48 '''
94 shutil.rmtree(self.dirname) 108 shutil.rmtree(self.dirname)
95 except OSError, error: 109 except OSError, error:
96 if error.errno not in (errno.ENOENT, errno.ESRCH): raise 110 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
97 111
98 def testEmptyMessage(self): 112 def testEmptyMessage(self):
99 message = cStringIO.StringIO('''Content-Type: text/plain; 113 message = StringIO('''Content-Type: text/plain;
100 charset="iso-8859-1" 114 charset="iso-8859-1"
101 From: Chef <chef@bork.bork.bork> 115 From: Chef <chef@bork.bork.bork>
102 To: issue_tracker@your.tracker.email.domain.example 116 To: issue_tracker@your.tracker.email.domain.example
103 Cc: richard@test 117 Cc: richard@test
104 Message-Id: <dummy_test_message_id> 118 Message-Id: <dummy_test_message_id>
112 error = open(os.environ['SENDMAILDEBUG']).read() 126 error = open(os.environ['SENDMAILDEBUG']).read()
113 self.assertEqual('no error', error) 127 self.assertEqual('no error', error)
114 self.assertEqual(self.db.issue.get(nodeid, 'title'), 'Testing...') 128 self.assertEqual(self.db.issue.get(nodeid, 'title'), 'Testing...')
115 129
116 def doNewIssue(self): 130 def doNewIssue(self):
117 message = cStringIO.StringIO('''Content-Type: text/plain; 131 message = StringIO('''Content-Type: text/plain;
118 charset="iso-8859-1" 132 charset="iso-8859-1"
119 From: Chef <chef@bork.bork.bork> 133 From: Chef <chef@bork.bork.bork>
120 To: issue_tracker@your.tracker.email.domain.example 134 To: issue_tracker@your.tracker.email.domain.example
121 Cc: richard@test 135 Cc: richard@test
122 Message-Id: <dummy_test_message_id> 136 Message-Id: <dummy_test_message_id>
138 def testNewIssue(self): 152 def testNewIssue(self):
139 self.doNewIssue() 153 self.doNewIssue()
140 154
141 def testNewIssueNosy(self): 155 def testNewIssueNosy(self):
142 self.instance.config.ADD_AUTHOR_TO_NOSY = 'yes' 156 self.instance.config.ADD_AUTHOR_TO_NOSY = 'yes'
143 message = cStringIO.StringIO('''Content-Type: text/plain; 157 message = StringIO('''Content-Type: text/plain;
144 charset="iso-8859-1" 158 charset="iso-8859-1"
145 From: Chef <chef@bork.bork.bork> 159 From: Chef <chef@bork.bork.bork>
146 To: issue_tracker@your.tracker.email.domain.example 160 To: issue_tracker@your.tracker.email.domain.example
147 Cc: richard@test 161 Cc: richard@test
148 Message-Id: <dummy_test_message_id> 162 Message-Id: <dummy_test_message_id>
159 l = self.db.issue.get(nodeid, 'nosy') 173 l = self.db.issue.get(nodeid, 'nosy')
160 l.sort() 174 l.sort()
161 self.assertEqual(l, ['3', '4']) 175 self.assertEqual(l, ['3', '4'])
162 176
163 def testAlternateAddress(self): 177 def testAlternateAddress(self):
164 message = cStringIO.StringIO('''Content-Type: text/plain; 178 message = StringIO('''Content-Type: text/plain;
165 charset="iso-8859-1" 179 charset="iso-8859-1"
166 From: John Doe <john.doe@test> 180 From: John Doe <john.doe@test>
167 To: issue_tracker@your.tracker.email.domain.example 181 To: issue_tracker@your.tracker.email.domain.example
168 Message-Id: <dummy_test_message_id> 182 Message-Id: <dummy_test_message_id>
169 Subject: [issue] Testing... 183 Subject: [issue] Testing...
179 self.assertEqual('no error', error) 193 self.assertEqual('no error', error)
180 self.assertEqual(userlist, self.db.user.list(), 194 self.assertEqual(userlist, self.db.user.list(),
181 "user created when it shouldn't have been") 195 "user created when it shouldn't have been")
182 196
183 def testNewIssueNoClass(self): 197 def testNewIssueNoClass(self):
184 message = cStringIO.StringIO('''Content-Type: text/plain; 198 message = StringIO('''Content-Type: text/plain;
185 charset="iso-8859-1" 199 charset="iso-8859-1"
186 From: Chef <chef@bork.bork.bork> 200 From: Chef <chef@bork.bork.bork>
187 To: issue_tracker@your.tracker.email.domain.example 201 To: issue_tracker@your.tracker.email.domain.example
188 Cc: richard@test 202 Cc: richard@test
189 Message-Id: <dummy_test_message_id> 203 Message-Id: <dummy_test_message_id>
197 if os.path.exists(os.environ['SENDMAILDEBUG']): 211 if os.path.exists(os.environ['SENDMAILDEBUG']):
198 error = open(os.environ['SENDMAILDEBUG']).read() 212 error = open(os.environ['SENDMAILDEBUG']).read()
199 self.assertEqual('no error', error) 213 self.assertEqual('no error', error)
200 214
201 def testNewIssueAuthMsg(self): 215 def testNewIssueAuthMsg(self):
202 message = cStringIO.StringIO('''Content-Type: text/plain; 216 message = StringIO('''Content-Type: text/plain;
203 charset="iso-8859-1" 217 charset="iso-8859-1"
204 From: Chef <chef@bork.bork.bork> 218 From: Chef <chef@bork.bork.bork>
205 To: issue_tracker@your.tracker.email.domain.example 219 To: issue_tracker@your.tracker.email.domain.example
206 Message-Id: <dummy_test_message_id> 220 Message-Id: <dummy_test_message_id>
207 Subject: [issue] Testing... [nosy=mary; assignedto=richard] 221 Subject: [issue] Testing... [nosy=mary; assignedto=richard]
212 handler.trapExceptions = 0 226 handler.trapExceptions = 0
213 # TODO: fix the damn config - this is apalling 227 # TODO: fix the damn config - this is apalling
214 self.db.config.MESSAGES_TO_AUTHOR = 'yes' 228 self.db.config.MESSAGES_TO_AUTHOR = 'yes'
215 handler.main(message) 229 handler.main(message)
216 230
217 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(), 231 self.compareMessages(open(os.environ['SENDMAILDEBUG']).read(),
218 '''FROM: roundup-admin@your.tracker.email.domain.example 232 '''FROM: roundup-admin@your.tracker.email.domain.example
219 TO: chef@bork.bork.bork, mary@test, richard@test 233 TO: chef@bork.bork.bork, mary@test, richard@test
220 Content-Type: text/plain; charset=utf-8 234 Content-Type: text/plain; charset=utf-8
221 Subject: [issue1] Testing... 235 Subject: [issue1] Testing...
222 To: chef@bork.bork.bork, mary@test, richard@test 236 To: chef@bork.bork.bork, mary@test, richard@test
254 268
255 # BUG should test some binary attamchent too. 269 # BUG should test some binary attamchent too.
256 270
257 def testSimpleFollowup(self): 271 def testSimpleFollowup(self):
258 self.doNewIssue() 272 self.doNewIssue()
259 message = cStringIO.StringIO('''Content-Type: text/plain; 273 message = StringIO('''Content-Type: text/plain;
260 charset="iso-8859-1" 274 charset="iso-8859-1"
261 From: mary <mary@test> 275 From: mary <mary@test>
262 To: issue_tracker@your.tracker.email.domain.example 276 To: issue_tracker@your.tracker.email.domain.example
263 Message-Id: <followup_dummy_id> 277 Message-Id: <followup_dummy_id>
264 In-Reply-To: <dummy_test_message_id> 278 In-Reply-To: <dummy_test_message_id>
267 This is a second followup 281 This is a second followup
268 ''') 282 ''')
269 handler = self.instance.MailGW(self.instance, self.db) 283 handler = self.instance.MailGW(self.instance, self.db)
270 handler.trapExceptions = 0 284 handler.trapExceptions = 0
271 handler.main(message) 285 handler.main(message)
272 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(), 286 self.compareMessages(open(os.environ['SENDMAILDEBUG']).read(),
273 '''FROM: roundup-admin@your.tracker.email.domain.example 287 '''FROM: roundup-admin@your.tracker.email.domain.example
274 TO: chef@bork.bork.bork, richard@test 288 TO: chef@bork.bork.bork, richard@test
275 Content-Type: text/plain; charset=utf-8 289 Content-Type: text/plain; charset=utf-8
276 Subject: [issue1] Testing... 290 Subject: [issue1] Testing...
277 To: chef@bork.bork.bork, richard@test 291 To: chef@bork.bork.bork, richard@test
298 ''') 312 ''')
299 313
300 def testFollowup(self): 314 def testFollowup(self):
301 self.doNewIssue() 315 self.doNewIssue()
302 316
303 message = cStringIO.StringIO('''Content-Type: text/plain; 317 message = StringIO('''Content-Type: text/plain;
304 charset="iso-8859-1" 318 charset="iso-8859-1"
305 From: richard <richard@test> 319 From: richard <richard@test>
306 To: issue_tracker@your.tracker.email.domain.example 320 To: issue_tracker@your.tracker.email.domain.example
307 Message-Id: <followup_dummy_id> 321 Message-Id: <followup_dummy_id>
308 In-Reply-To: <dummy_test_message_id> 322 In-Reply-To: <dummy_test_message_id>
315 handler.main(message) 329 handler.main(message)
316 l = self.db.issue.get('1', 'nosy') 330 l = self.db.issue.get('1', 'nosy')
317 l.sort() 331 l.sort()
318 self.assertEqual(l, ['3', '4', '5', '6']) 332 self.assertEqual(l, ['3', '4', '5', '6'])
319 333
320 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(), 334 self.compareMessages(open(os.environ['SENDMAILDEBUG']).read(),
321 '''FROM: roundup-admin@your.tracker.email.domain.example 335 '''FROM: roundup-admin@your.tracker.email.domain.example
322 TO: chef@bork.bork.bork, john@test, mary@test 336 TO: chef@bork.bork.bork, john@test, mary@test
323 Content-Type: text/plain; charset=utf-8 337 Content-Type: text/plain; charset=utf-8
324 Subject: [issue1] Testing... 338 Subject: [issue1] Testing...
325 To: chef@bork.bork.bork, john@test, mary@test 339 To: chef@bork.bork.bork, john@test, mary@test
347 _______________________________________________________________________ 361 _______________________________________________________________________
348 ''') 362 ''')
349 363
350 def testFollowupTitleMatch(self): 364 def testFollowupTitleMatch(self):
351 self.doNewIssue() 365 self.doNewIssue()
352 message = cStringIO.StringIO('''Content-Type: text/plain; 366 message = StringIO('''Content-Type: text/plain;
353 charset="iso-8859-1" 367 charset="iso-8859-1"
354 From: richard <richard@test> 368 From: richard <richard@test>
355 To: issue_tracker@your.tracker.email.domain.example 369 To: issue_tracker@your.tracker.email.domain.example
356 Message-Id: <followup_dummy_id> 370 Message-Id: <followup_dummy_id>
357 In-Reply-To: <dummy_test_message_id> 371 In-Reply-To: <dummy_test_message_id>
361 ''') 375 ''')
362 handler = self.instance.MailGW(self.instance, self.db) 376 handler = self.instance.MailGW(self.instance, self.db)
363 handler.trapExceptions = 0 377 handler.trapExceptions = 0
364 handler.main(message) 378 handler.main(message)
365 379
366 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(), 380 self.compareMessages(open(os.environ['SENDMAILDEBUG']).read(),
367 '''FROM: roundup-admin@your.tracker.email.domain.example 381 '''FROM: roundup-admin@your.tracker.email.domain.example
368 TO: chef@bork.bork.bork, john@test, mary@test 382 TO: chef@bork.bork.bork, john@test, mary@test
369 Content-Type: text/plain; charset=utf-8 383 Content-Type: text/plain; charset=utf-8
370 Subject: [issue1] Testing... 384 Subject: [issue1] Testing...
371 To: chef@bork.bork.bork, john@test, mary@test 385 To: chef@bork.bork.bork, john@test, mary@test
394 ''') 408 ''')
395 409
396 def testFollowupNosyAuthor(self): 410 def testFollowupNosyAuthor(self):
397 self.doNewIssue() 411 self.doNewIssue()
398 self.db.config.ADD_AUTHOR_TO_NOSY = 'yes' 412 self.db.config.ADD_AUTHOR_TO_NOSY = 'yes'
399 message = cStringIO.StringIO('''Content-Type: text/plain; 413 message = StringIO('''Content-Type: text/plain;
400 charset="iso-8859-1" 414 charset="iso-8859-1"
401 From: john@test 415 From: john@test
402 To: issue_tracker@your.tracker.email.domain.example 416 To: issue_tracker@your.tracker.email.domain.example
403 Message-Id: <followup_dummy_id> 417 Message-Id: <followup_dummy_id>
404 In-Reply-To: <dummy_test_message_id> 418 In-Reply-To: <dummy_test_message_id>
408 ''') 422 ''')
409 handler = self.instance.MailGW(self.instance, self.db) 423 handler = self.instance.MailGW(self.instance, self.db)
410 handler.trapExceptions = 0 424 handler.trapExceptions = 0
411 handler.main(message) 425 handler.main(message)
412 426
413 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(), 427 self.compareMessages(open(os.environ['SENDMAILDEBUG']).read(),
414 '''FROM: roundup-admin@your.tracker.email.domain.example 428 '''FROM: roundup-admin@your.tracker.email.domain.example
415 TO: chef@bork.bork.bork, richard@test 429 TO: chef@bork.bork.bork, richard@test
416 Content-Type: text/plain; charset=utf-8 430 Content-Type: text/plain; charset=utf-8
417 Subject: [issue1] Testing... 431 Subject: [issue1] Testing...
418 To: chef@bork.bork.bork, richard@test 432 To: chef@bork.bork.bork, richard@test
441 ''') 455 ''')
442 456
443 def testFollowupNosyRecipients(self): 457 def testFollowupNosyRecipients(self):
444 self.doNewIssue() 458 self.doNewIssue()
445 self.db.config.ADD_RECIPIENTS_TO_NOSY = 'yes' 459 self.db.config.ADD_RECIPIENTS_TO_NOSY = 'yes'
446 message = cStringIO.StringIO('''Content-Type: text/plain; 460 message = StringIO('''Content-Type: text/plain;
447 charset="iso-8859-1" 461 charset="iso-8859-1"
448 From: richard@test 462 From: richard@test
449 To: issue_tracker@your.tracker.email.domain.example 463 To: issue_tracker@your.tracker.email.domain.example
450 Cc: john@test 464 Cc: john@test
451 Message-Id: <followup_dummy_id> 465 Message-Id: <followup_dummy_id>
456 ''') 470 ''')
457 handler = self.instance.MailGW(self.instance, self.db) 471 handler = self.instance.MailGW(self.instance, self.db)
458 handler.trapExceptions = 0 472 handler.trapExceptions = 0
459 handler.main(message) 473 handler.main(message)
460 474
461 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(), 475 self.compareMessages(open(os.environ['SENDMAILDEBUG']).read(),
462 '''FROM: roundup-admin@your.tracker.email.domain.example 476 '''FROM: roundup-admin@your.tracker.email.domain.example
463 TO: chef@bork.bork.bork 477 TO: chef@bork.bork.bork
464 Content-Type: text/plain; charset=utf-8 478 Content-Type: text/plain; charset=utf-8
465 Subject: [issue1] Testing... 479 Subject: [issue1] Testing...
466 To: chef@bork.bork.bork 480 To: chef@bork.bork.bork
490 504
491 def testFollowupNosyAuthorAndCopy(self): 505 def testFollowupNosyAuthorAndCopy(self):
492 self.doNewIssue() 506 self.doNewIssue()
493 self.db.config.ADD_AUTHOR_TO_NOSY = 'yes' 507 self.db.config.ADD_AUTHOR_TO_NOSY = 'yes'
494 self.db.config.MESSAGES_TO_AUTHOR = 'yes' 508 self.db.config.MESSAGES_TO_AUTHOR = 'yes'
495 message = cStringIO.StringIO('''Content-Type: text/plain; 509 message = StringIO('''Content-Type: text/plain;
496 charset="iso-8859-1" 510 charset="iso-8859-1"
497 From: john@test 511 From: john@test
498 To: issue_tracker@your.tracker.email.domain.example 512 To: issue_tracker@your.tracker.email.domain.example
499 Message-Id: <followup_dummy_id> 513 Message-Id: <followup_dummy_id>
500 In-Reply-To: <dummy_test_message_id> 514 In-Reply-To: <dummy_test_message_id>
504 ''') 518 ''')
505 handler = self.instance.MailGW(self.instance, self.db) 519 handler = self.instance.MailGW(self.instance, self.db)
506 handler.trapExceptions = 0 520 handler.trapExceptions = 0
507 handler.main(message) 521 handler.main(message)
508 522
509 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(), 523 self.compareMessages(open(os.environ['SENDMAILDEBUG']).read(),
510 '''FROM: roundup-admin@your.tracker.email.domain.example 524 '''FROM: roundup-admin@your.tracker.email.domain.example
511 TO: chef@bork.bork.bork, john@test, richard@test 525 TO: chef@bork.bork.bork, john@test, richard@test
512 Content-Type: text/plain; charset=utf-8 526 Content-Type: text/plain; charset=utf-8
513 Subject: [issue1] Testing... 527 Subject: [issue1] Testing...
514 To: chef@bork.bork.bork, john@test, richard@test 528 To: chef@bork.bork.bork, john@test, richard@test
537 ''') 551 ''')
538 552
539 def testFollowupNoNosyAuthor(self): 553 def testFollowupNoNosyAuthor(self):
540 self.doNewIssue() 554 self.doNewIssue()
541 self.instance.config.ADD_AUTHOR_TO_NOSY = 'no' 555 self.instance.config.ADD_AUTHOR_TO_NOSY = 'no'
542 message = cStringIO.StringIO('''Content-Type: text/plain; 556 message = StringIO('''Content-Type: text/plain;
543 charset="iso-8859-1" 557 charset="iso-8859-1"
544 From: john@test 558 From: john@test
545 To: issue_tracker@your.tracker.email.domain.example 559 To: issue_tracker@your.tracker.email.domain.example
546 Message-Id: <followup_dummy_id> 560 Message-Id: <followup_dummy_id>
547 In-Reply-To: <dummy_test_message_id> 561 In-Reply-To: <dummy_test_message_id>
551 ''') 565 ''')
552 handler = self.instance.MailGW(self.instance, self.db) 566 handler = self.instance.MailGW(self.instance, self.db)
553 handler.trapExceptions = 0 567 handler.trapExceptions = 0
554 handler.main(message) 568 handler.main(message)
555 569
556 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(), 570 self.compareMessages(open(os.environ['SENDMAILDEBUG']).read(),
557 '''FROM: roundup-admin@your.tracker.email.domain.example 571 '''FROM: roundup-admin@your.tracker.email.domain.example
558 TO: chef@bork.bork.bork, richard@test 572 TO: chef@bork.bork.bork, richard@test
559 Content-Type: text/plain; charset=utf-8 573 Content-Type: text/plain; charset=utf-8
560 Subject: [issue1] Testing... 574 Subject: [issue1] Testing...
561 To: chef@bork.bork.bork, richard@test 575 To: chef@bork.bork.bork, richard@test
583 ''') 597 ''')
584 598
585 def testFollowupNoNosyRecipients(self): 599 def testFollowupNoNosyRecipients(self):
586 self.doNewIssue() 600 self.doNewIssue()
587 self.instance.config.ADD_RECIPIENTS_TO_NOSY = 'no' 601 self.instance.config.ADD_RECIPIENTS_TO_NOSY = 'no'
588 message = cStringIO.StringIO('''Content-Type: text/plain; 602 message = StringIO('''Content-Type: text/plain;
589 charset="iso-8859-1" 603 charset="iso-8859-1"
590 From: richard@test 604 From: richard@test
591 To: issue_tracker@your.tracker.email.domain.example 605 To: issue_tracker@your.tracker.email.domain.example
592 Cc: john@test 606 Cc: john@test
593 Message-Id: <followup_dummy_id> 607 Message-Id: <followup_dummy_id>
598 ''') 612 ''')
599 handler = self.instance.MailGW(self.instance, self.db) 613 handler = self.instance.MailGW(self.instance, self.db)
600 handler.trapExceptions = 0 614 handler.trapExceptions = 0
601 handler.main(message) 615 handler.main(message)
602 616
603 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(), 617 self.compareMessages(open(os.environ['SENDMAILDEBUG']).read(),
604 '''FROM: roundup-admin@your.tracker.email.domain.example 618 '''FROM: roundup-admin@your.tracker.email.domain.example
605 TO: chef@bork.bork.bork 619 TO: chef@bork.bork.bork
606 Content-Type: text/plain; charset=utf-8 620 Content-Type: text/plain; charset=utf-8
607 Subject: [issue1] Testing... 621 Subject: [issue1] Testing...
608 To: chef@bork.bork.bork 622 To: chef@bork.bork.bork
630 ''') 644 ''')
631 645
632 def testFollowupEmptyMessage(self): 646 def testFollowupEmptyMessage(self):
633 self.doNewIssue() 647 self.doNewIssue()
634 648
635 message = cStringIO.StringIO('''Content-Type: text/plain; 649 message = StringIO('''Content-Type: text/plain;
636 charset="iso-8859-1" 650 charset="iso-8859-1"
637 From: richard <richard@test> 651 From: richard <richard@test>
638 To: issue_tracker@your.tracker.email.domain.example 652 To: issue_tracker@your.tracker.email.domain.example
639 Message-Id: <followup_dummy_id> 653 Message-Id: <followup_dummy_id>
640 In-Reply-To: <dummy_test_message_id> 654 In-Reply-To: <dummy_test_message_id>
652 assert not os.path.exists(os.environ['SENDMAILDEBUG']) 666 assert not os.path.exists(os.environ['SENDMAILDEBUG'])
653 667
654 def testNosyRemove(self): 668 def testNosyRemove(self):
655 self.doNewIssue() 669 self.doNewIssue()
656 670
657 message = cStringIO.StringIO('''Content-Type: text/plain; 671 message = StringIO('''Content-Type: text/plain;
658 charset="iso-8859-1" 672 charset="iso-8859-1"
659 From: richard <richard@test> 673 From: richard <richard@test>
660 To: issue_tracker@your.tracker.email.domain.example 674 To: issue_tracker@your.tracker.email.domain.example
661 Message-Id: <followup_dummy_id> 675 Message-Id: <followup_dummy_id>
662 In-Reply-To: <dummy_test_message_id> 676 In-Reply-To: <dummy_test_message_id>
690 Message-Id: <dummy_test_message_id> 704 Message-Id: <dummy_test_message_id>
691 Subject: [issue] Testing... 705 Subject: [issue] Testing...
692 706
693 This is a test submission of a new issue. 707 This is a test submission of a new issue.
694 ''' 708 '''
695 message = cStringIO.StringIO(s) 709 message = StringIO(s)
696 handler = self.instance.MailGW(self.instance, self.db) 710 handler = self.instance.MailGW(self.instance, self.db)
697 handler.trapExceptions = 0 711 handler.trapExceptions = 0
698 self.assertRaises(Unauthorized, handler.main, message) 712 self.assertRaises(Unauthorized, handler.main, message)
699 m = self.db.user.list() 713 m = self.db.user.list()
700 m.sort() 714 m.sort()
703 # now with the permission 717 # now with the permission
704 p = self.db.security.getPermission('Email Registration') 718 p = self.db.security.getPermission('Email Registration')
705 self.db.security.role['anonymous'].permissions=[p] 719 self.db.security.role['anonymous'].permissions=[p]
706 handler = self.instance.MailGW(self.instance, self.db) 720 handler = self.instance.MailGW(self.instance, self.db)
707 handler.trapExceptions = 0 721 handler.trapExceptions = 0
708 message = cStringIO.StringIO(s) 722 message = StringIO(s)
709 handler.main(message) 723 handler.main(message)
710 m = self.db.user.list() 724 m = self.db.user.list()
711 m.sort() 725 m.sort()
712 self.assertNotEqual(l, m) 726 self.assertNotEqual(l, m)
713 727
714 def testEnc01(self): 728 def testEnc01(self):
715 self.doNewIssue() 729 self.doNewIssue()
716 message = cStringIO.StringIO('''Content-Type: text/plain; 730 message = StringIO('''Content-Type: text/plain;
717 charset="iso-8859-1" 731 charset="iso-8859-1"
718 From: mary <mary@test> 732 From: mary <mary@test>
719 To: issue_tracker@your.tracker.email.domain.example 733 To: issue_tracker@your.tracker.email.domain.example
720 Message-Id: <followup_dummy_id> 734 Message-Id: <followup_dummy_id>
721 In-Reply-To: <dummy_test_message_id> 735 In-Reply-To: <dummy_test_message_id>
728 742
729 ''') 743 ''')
730 handler = self.instance.MailGW(self.instance, self.db) 744 handler = self.instance.MailGW(self.instance, self.db)
731 handler.trapExceptions = 0 745 handler.trapExceptions = 0
732 handler.main(message) 746 handler.main(message)
733 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(), 747 self.compareMessages(open(os.environ['SENDMAILDEBUG']).read(),
734 '''FROM: roundup-admin@your.tracker.email.domain.example 748 '''FROM: roundup-admin@your.tracker.email.domain.example
735 TO: chef@bork.bork.bork, richard@test 749 TO: chef@bork.bork.bork, richard@test
736 Content-Type: text/plain; charset=utf-8 750 Content-Type: text/plain; charset=utf-8
737 Subject: [issue1] Testing... 751 Subject: [issue1] Testing...
738 To: chef@bork.bork.bork, richard@test 752 To: chef@bork.bork.bork, richard@test
759 ''') 773 ''')
760 774
761 775
762 def testMultipartEnc01(self): 776 def testMultipartEnc01(self):
763 self.doNewIssue() 777 self.doNewIssue()
764 message = cStringIO.StringIO('''Content-Type: text/plain; 778 message = StringIO('''Content-Type: text/plain;
765 charset="iso-8859-1" 779 charset="iso-8859-1"
766 From: mary <mary@test> 780 From: mary <mary@test>
767 To: issue_tracker@your.tracker.email.domain.example 781 To: issue_tracker@your.tracker.email.domain.example
768 Message-Id: <followup_dummy_id> 782 Message-Id: <followup_dummy_id>
769 In-Reply-To: <dummy_test_message_id> 783 In-Reply-To: <dummy_test_message_id>
783 797
784 ''') 798 ''')
785 handler = self.instance.MailGW(self.instance, self.db) 799 handler = self.instance.MailGW(self.instance, self.db)
786 handler.trapExceptions = 0 800 handler.trapExceptions = 0
787 handler.main(message) 801 handler.main(message)
788 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(), 802 self.compareMessages(open(os.environ['SENDMAILDEBUG']).read(),
789 '''FROM: roundup-admin@your.tracker.email.domain.example 803 '''FROM: roundup-admin@your.tracker.email.domain.example
790 TO: chef@bork.bork.bork, richard@test 804 TO: chef@bork.bork.bork, richard@test
791 Content-Type: text/plain; charset=utf-8 805 Content-Type: text/plain; charset=utf-8
792 Subject: [issue1] Testing... 806 Subject: [issue1] Testing...
793 To: chef@bork.bork.bork, richard@test 807 To: chef@bork.bork.bork, richard@test
813 _______________________________________________________________________ 827 _______________________________________________________________________
814 ''') 828 ''')
815 829
816 def testContentDisposition(self): 830 def testContentDisposition(self):
817 self.doNewIssue() 831 self.doNewIssue()
818 message = cStringIO.StringIO('''Content-Type: text/plain; 832 message = StringIO('''Content-Type: text/plain;
819 charset="iso-8859-1" 833 charset="iso-8859-1"
820 From: mary <mary@test> 834 From: mary <mary@test>
821 To: issue_tracker@your.tracker.email.domain.example 835 To: issue_tracker@your.tracker.email.domain.example
822 Message-Id: <followup_dummy_id> 836 Message-Id: <followup_dummy_id>
823 In-Reply-To: <dummy_test_message_id> 837 In-Reply-To: <dummy_test_message_id>
849 self.assertEqual(self.db.file.get(file, 'name'), 'main.dvi') 863 self.assertEqual(self.db.file.get(file, 'name'), 'main.dvi')
850 864
851 def testFollowupStupidQuoting(self): 865 def testFollowupStupidQuoting(self):
852 self.doNewIssue() 866 self.doNewIssue()
853 867
854 message = cStringIO.StringIO('''Content-Type: text/plain; 868 message = StringIO('''Content-Type: text/plain;
855 charset="iso-8859-1" 869 charset="iso-8859-1"
856 From: richard <richard@test> 870 From: richard <richard@test>
857 To: issue_tracker@your.tracker.email.domain.example 871 To: issue_tracker@your.tracker.email.domain.example
858 Message-Id: <followup_dummy_id> 872 Message-Id: <followup_dummy_id>
859 In-Reply-To: <dummy_test_message_id> 873 In-Reply-To: <dummy_test_message_id>
863 ''') 877 ''')
864 handler = self.instance.MailGW(self.instance, self.db) 878 handler = self.instance.MailGW(self.instance, self.db)
865 handler.trapExceptions = 0 879 handler.trapExceptions = 0
866 handler.main(message) 880 handler.main(message)
867 881
868 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(), 882 self.compareMessages(open(os.environ['SENDMAILDEBUG']).read(),
869 '''FROM: roundup-admin@your.tracker.email.domain.example 883 '''FROM: roundup-admin@your.tracker.email.domain.example
870 TO: chef@bork.bork.bork 884 TO: chef@bork.bork.bork
871 Content-Type: text/plain; charset=utf-8 885 Content-Type: text/plain; charset=utf-8
872 Subject: [issue1] Testing... 886 Subject: [issue1] Testing...
873 To: chef@bork.bork.bork 887 To: chef@bork.bork.bork
911 def innerTestQuoting(self, expect): 925 def innerTestQuoting(self, expect):
912 nodeid = self.doNewIssue() 926 nodeid = self.doNewIssue()
913 927
914 messages = self.db.issue.get(nodeid, 'messages') 928 messages = self.db.issue.get(nodeid, 'messages')
915 929
916 message = cStringIO.StringIO('''Content-Type: text/plain; 930 message = StringIO('''Content-Type: text/plain;
917 charset="iso-8859-1" 931 charset="iso-8859-1"
918 From: richard <richard@test> 932 From: richard <richard@test>
919 To: issue_tracker@your.tracker.email.domain.example 933 To: issue_tracker@your.tracker.email.domain.example
920 Message-Id: <followup_dummy_id> 934 Message-Id: <followup_dummy_id>
921 In-Reply-To: <dummy_test_message_id> 935 In-Reply-To: <dummy_test_message_id>
936 newmessages = self.db.issue.get(nodeid, 'messages') 950 newmessages = self.db.issue.get(nodeid, 'messages')
937 for msg in messages: 951 for msg in messages:
938 newmessages.remove(msg) 952 newmessages.remove(msg)
939 messageid = newmessages[0] 953 messageid = newmessages[0]
940 954
941 self.compareStrings(self.db.msg.get(messageid, 'content'), expect) 955 self.compareMessages(self.db.msg.get(messageid, 'content'), expect)
942 956
943 def testUserLookup(self): 957 def testUserLookup(self):
944 i = self.db.user.create(username='user1', address='user1@foo.com') 958 i = self.db.user.create(username='user1', address='user1@foo.com')
945 self.assertEqual(uidFromAddress(self.db, ('', 'user1@foo.com'), 0), i) 959 self.assertEqual(uidFromAddress(self.db, ('', 'user1@foo.com'), 0), i)
946 self.assertEqual(uidFromAddress(self.db, ('', 'USER1@foo.com'), 0), i) 960 self.assertEqual(uidFromAddress(self.db, ('', 'USER1@foo.com'), 0), i)
960 self.assertEqual(rfc2822.encode_header(unicode_header), unicode_encoded) 974 self.assertEqual(rfc2822.encode_header(unicode_header), unicode_encoded)
961 975
962 def testRegistrationConfirmation(self): 976 def testRegistrationConfirmation(self):
963 otk = "Aj4euk4LZSAdwePohj90SME5SpopLETL" 977 otk = "Aj4euk4LZSAdwePohj90SME5SpopLETL"
964 self.db.otks.set(otk, username='johannes', __time='') 978 self.db.otks.set(otk, username='johannes', __time='')
965 message = cStringIO.StringIO('''Content-Type: text/plain; 979 message = StringIO('''Content-Type: text/plain;
966 charset="iso-8859-1" 980 charset="iso-8859-1"
967 From: Chef <chef@bork.bork.bork> 981 From: Chef <chef@bork.bork.bork>
968 To: issue_tracker@your.tracker.email.domain.example 982 To: issue_tracker@your.tracker.email.domain.example
969 Cc: richard@test 983 Cc: richard@test
970 Message-Id: <dummy_test_message_id> 984 Message-Id: <dummy_test_message_id>

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