comparison test/test_mailgw.py @ 1888:465dc7dbe67a

Extract _send_mail method, it was duplicated all around the test code.
author Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
date Mon, 03 Nov 2003 19:08:41 +0000
parents 9d8d5fa0d9ad
children e1b3ca0c0f9a
comparison
equal deleted inserted replaced
1887:9d8d5fa0d9ad 1888:465dc7dbe67a
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.58 2003-11-03 18:34:03 jlgijsbers Exp $ 11 # $Id: test_mailgw.py,v 1.59 2003-11-03 19:08:41 jlgijsbers Exp $
12 12
13 import unittest, tempfile, os, shutil, errno, imp, sys, difflib, rfc822 13 import unittest, tempfile, os, shutil, errno, imp, sys, difflib, rfc822
14 14
15 from cStringIO import StringIO 15 from cStringIO import StringIO
16 16
108 try: 108 try:
109 shutil.rmtree(self.dirname) 109 shutil.rmtree(self.dirname)
110 except OSError, error: 110 except OSError, error:
111 if error.errno not in (errno.ENOENT, errno.ESRCH): raise 111 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
112 112
113 def _send_mail(self, message):
114 handler = self.instance.MailGW(self.instance, self.db)
115 handler.trapExceptions = 0
116 return handler.main(StringIO(message))
117
113 def _get_mail(self): 118 def _get_mail(self):
114 f = open(SENDMAILDEBUG) 119 f = open(SENDMAILDEBUG)
115 try: 120 try:
116 return f.read() 121 return f.read()
117 finally: 122 finally:
118 f.close() 123 f.close()
119 124
120 def testEmptyMessage(self): 125 def testEmptyMessage(self):
121 message = StringIO('''Content-Type: text/plain; 126 nodeid = self._send_mail('''Content-Type: text/plain;
122 charset="iso-8859-1" 127 charset="iso-8859-1"
123 From: Chef <chef@bork.bork.bork> 128 From: Chef <chef@bork.bork.bork>
124 To: issue_tracker@your.tracker.email.domain.example 129 To: issue_tracker@your.tracker.email.domain.example
125 Cc: richard@test 130 Cc: richard@test
126 Message-Id: <dummy_test_message_id> 131 Message-Id: <dummy_test_message_id>
127 Subject: [issue] Testing... 132 Subject: [issue] Testing...
128 133
129 ''') 134 ''')
130 handler = self.instance.MailGW(self.instance, self.db)
131 handler.trapExceptions = 0
132 nodeid = handler.main(message)
133 assert not os.path.exists(SENDMAILDEBUG) 135 assert not os.path.exists(SENDMAILDEBUG)
134 self.assertEqual(self.db.issue.get(nodeid, 'title'), 'Testing...') 136 self.assertEqual(self.db.issue.get(nodeid, 'title'), 'Testing...')
135 137
136 def doNewIssue(self): 138 def doNewIssue(self):
137 message = StringIO('''Content-Type: text/plain; 139 nodeid = self._send_mail('''Content-Type: text/plain;
138 charset="iso-8859-1" 140 charset="iso-8859-1"
139 From: Chef <chef@bork.bork.bork> 141 From: Chef <chef@bork.bork.bork>
140 To: issue_tracker@your.tracker.email.domain.example 142 To: issue_tracker@your.tracker.email.domain.example
141 Cc: richard@test 143 Cc: richard@test
142 Message-Id: <dummy_test_message_id> 144 Message-Id: <dummy_test_message_id>
143 Subject: [issue] Testing... 145 Subject: [issue] Testing...
144 146
145 This is a test submission of a new issue. 147 This is a test submission of a new issue.
146 ''') 148 ''')
147 handler = self.instance.MailGW(self.instance, self.db)
148 handler.trapExceptions = 0
149 nodeid = handler.main(message)
150 assert not os.path.exists(SENDMAILDEBUG) 149 assert not os.path.exists(SENDMAILDEBUG)
151 l = self.db.issue.get(nodeid, 'nosy') 150 l = self.db.issue.get(nodeid, 'nosy')
152 l.sort() 151 l.sort()
153 self.assertEqual(l, ['3', '4']) 152 self.assertEqual(l, ['3', '4'])
154 return nodeid 153 return nodeid
156 def testNewIssue(self): 155 def testNewIssue(self):
157 self.doNewIssue() 156 self.doNewIssue()
158 157
159 def testNewIssueNosy(self): 158 def testNewIssueNosy(self):
160 self.instance.config.ADD_AUTHOR_TO_NOSY = 'yes' 159 self.instance.config.ADD_AUTHOR_TO_NOSY = 'yes'
161 message = StringIO('''Content-Type: text/plain; 160 nodeid = self._send_mail('''Content-Type: text/plain;
162 charset="iso-8859-1" 161 charset="iso-8859-1"
163 From: Chef <chef@bork.bork.bork> 162 From: Chef <chef@bork.bork.bork>
164 To: issue_tracker@your.tracker.email.domain.example 163 To: issue_tracker@your.tracker.email.domain.example
165 Cc: richard@test 164 Cc: richard@test
166 Message-Id: <dummy_test_message_id> 165 Message-Id: <dummy_test_message_id>
167 Subject: [issue] Testing... 166 Subject: [issue] Testing...
168 167
169 This is a test submission of a new issue. 168 This is a test submission of a new issue.
170 ''') 169 ''')
171 handler = self.instance.MailGW(self.instance, self.db)
172 handler.trapExceptions = 0
173 nodeid = handler.main(message)
174 assert not os.path.exists(SENDMAILDEBUG) 170 assert not os.path.exists(SENDMAILDEBUG)
175 l = self.db.issue.get(nodeid, 'nosy') 171 l = self.db.issue.get(nodeid, 'nosy')
176 l.sort() 172 l.sort()
177 self.assertEqual(l, ['3', '4']) 173 self.assertEqual(l, ['3', '4'])
178 174
179 def testAlternateAddress(self): 175 def testAlternateAddress(self):
180 message = StringIO('''Content-Type: text/plain; 176 self._send_mail('''Content-Type: text/plain;
181 charset="iso-8859-1" 177 charset="iso-8859-1"
182 From: John Doe <john.doe@test> 178 From: John Doe <john.doe@test>
183 To: issue_tracker@your.tracker.email.domain.example 179 To: issue_tracker@your.tracker.email.domain.example
184 Message-Id: <dummy_test_message_id> 180 Message-Id: <dummy_test_message_id>
185 Subject: [issue] Testing... 181 Subject: [issue] Testing...
186 182
187 This is a test submission of a new issue. 183 This is a test submission of a new issue.
188 ''') 184 ''')
189 userlist = self.db.user.list() 185 userlist = self.db.user.list()
190 handler = self.instance.MailGW(self.instance, self.db)
191 handler.trapExceptions = 0
192 handler.main(message)
193 assert not os.path.exists(SENDMAILDEBUG) 186 assert not os.path.exists(SENDMAILDEBUG)
194 self.assertEqual(userlist, self.db.user.list(), 187 self.assertEqual(userlist, self.db.user.list(),
195 "user created when it shouldn't have been") 188 "user created when it shouldn't have been")
196 189
197 def testNewIssueNoClass(self): 190 def testNewIssueNoClass(self):
198 message = StringIO('''Content-Type: text/plain; 191 self._send_mail('''Content-Type: text/plain;
199 charset="iso-8859-1" 192 charset="iso-8859-1"
200 From: Chef <chef@bork.bork.bork> 193 From: Chef <chef@bork.bork.bork>
201 To: issue_tracker@your.tracker.email.domain.example 194 To: issue_tracker@your.tracker.email.domain.example
202 Cc: richard@test 195 Cc: richard@test
203 Message-Id: <dummy_test_message_id> 196 Message-Id: <dummy_test_message_id>
204 Subject: Testing... 197 Subject: Testing...
205 198
206 This is a test submission of a new issue. 199 This is a test submission of a new issue.
207 ''') 200 ''')
208 handler = self.instance.MailGW(self.instance, self.db)
209 handler.trapExceptions = 0
210 handler.main(message)
211 assert not os.path.exists(SENDMAILDEBUG) 201 assert not os.path.exists(SENDMAILDEBUG)
212 202
213 def testNewIssueAuthMsg(self): 203 def testNewIssueAuthMsg(self):
214 message = StringIO('''Content-Type: text/plain; 204 # TODO: fix the damn config - this is apalling
205 self.db.config.MESSAGES_TO_AUTHOR = 'yes'
206 self._send_mail('''Content-Type: text/plain;
215 charset="iso-8859-1" 207 charset="iso-8859-1"
216 From: Chef <chef@bork.bork.bork> 208 From: Chef <chef@bork.bork.bork>
217 To: issue_tracker@your.tracker.email.domain.example 209 To: issue_tracker@your.tracker.email.domain.example
218 Message-Id: <dummy_test_message_id> 210 Message-Id: <dummy_test_message_id>
219 Subject: [issue] Testing... [nosy=mary; assignedto=richard] 211 Subject: [issue] Testing... [nosy=mary; assignedto=richard]
220 212
221 This is a test submission of a new issue. 213 This is a test submission of a new issue.
222 ''') 214 ''')
223 handler = self.instance.MailGW(self.instance, self.db)
224 handler.trapExceptions = 0
225 # TODO: fix the damn config - this is apalling
226 self.db.config.MESSAGES_TO_AUTHOR = 'yes'
227 handler.main(message)
228
229 self.compareMessages(self._get_mail(), 215 self.compareMessages(self._get_mail(),
230 '''FROM: roundup-admin@your.tracker.email.domain.example 216 '''FROM: roundup-admin@your.tracker.email.domain.example
231 TO: chef@bork.bork.bork, mary@test, richard@test 217 TO: chef@bork.bork.bork, mary@test, richard@test
232 Content-Type: text/plain; charset=utf-8 218 Content-Type: text/plain; charset=utf-8
233 Subject: [issue1] Testing... 219 Subject: [issue1] Testing...
266 252
267 # BUG should test some binary attamchent too. 253 # BUG should test some binary attamchent too.
268 254
269 def testSimpleFollowup(self): 255 def testSimpleFollowup(self):
270 self.doNewIssue() 256 self.doNewIssue()
271 message = StringIO('''Content-Type: text/plain; 257 self._send_mail('''Content-Type: text/plain;
272 charset="iso-8859-1" 258 charset="iso-8859-1"
273 From: mary <mary@test> 259 From: mary <mary@test>
274 To: issue_tracker@your.tracker.email.domain.example 260 To: issue_tracker@your.tracker.email.domain.example
275 Message-Id: <followup_dummy_id> 261 Message-Id: <followup_dummy_id>
276 In-Reply-To: <dummy_test_message_id> 262 In-Reply-To: <dummy_test_message_id>
277 Subject: [issue1] Testing... 263 Subject: [issue1] Testing...
278 264
279 This is a second followup 265 This is a second followup
280 ''') 266 ''')
281 handler = self.instance.MailGW(self.instance, self.db)
282 handler.trapExceptions = 0
283 handler.main(message)
284 self.compareMessages(self._get_mail(), 267 self.compareMessages(self._get_mail(),
285 '''FROM: roundup-admin@your.tracker.email.domain.example 268 '''FROM: roundup-admin@your.tracker.email.domain.example
286 TO: chef@bork.bork.bork, richard@test 269 TO: chef@bork.bork.bork, richard@test
287 Content-Type: text/plain; charset=utf-8 270 Content-Type: text/plain; charset=utf-8
288 Subject: [issue1] Testing... 271 Subject: [issue1] Testing...
310 ''') 293 ''')
311 294
312 def testFollowup(self): 295 def testFollowup(self):
313 self.doNewIssue() 296 self.doNewIssue()
314 297
315 message = StringIO('''Content-Type: text/plain; 298 self._send_mail('''Content-Type: text/plain;
316 charset="iso-8859-1" 299 charset="iso-8859-1"
317 From: richard <richard@test> 300 From: richard <richard@test>
318 To: issue_tracker@your.tracker.email.domain.example 301 To: issue_tracker@your.tracker.email.domain.example
319 Message-Id: <followup_dummy_id> 302 Message-Id: <followup_dummy_id>
320 In-Reply-To: <dummy_test_message_id> 303 In-Reply-To: <dummy_test_message_id>
321 Subject: [issue1] Testing... [assignedto=mary; nosy=+john] 304 Subject: [issue1] Testing... [assignedto=mary; nosy=+john]
322 305
323 This is a followup 306 This is a followup
324 ''') 307 ''')
325 handler = self.instance.MailGW(self.instance, self.db)
326 handler.trapExceptions = 0
327 handler.main(message)
328 l = self.db.issue.get('1', 'nosy') 308 l = self.db.issue.get('1', 'nosy')
329 l.sort() 309 l.sort()
330 self.assertEqual(l, ['3', '4', '5', '6']) 310 self.assertEqual(l, ['3', '4', '5', '6'])
331 311
332 self.compareMessages(self._get_mail(), 312 self.compareMessages(self._get_mail(),
359 _______________________________________________________________________ 339 _______________________________________________________________________
360 ''') 340 ''')
361 341
362 def testFollowupTitleMatch(self): 342 def testFollowupTitleMatch(self):
363 self.doNewIssue() 343 self.doNewIssue()
364 message = StringIO('''Content-Type: text/plain; 344 self._send_mail('''Content-Type: text/plain;
365 charset="iso-8859-1" 345 charset="iso-8859-1"
366 From: richard <richard@test> 346 From: richard <richard@test>
367 To: issue_tracker@your.tracker.email.domain.example 347 To: issue_tracker@your.tracker.email.domain.example
368 Message-Id: <followup_dummy_id> 348 Message-Id: <followup_dummy_id>
369 In-Reply-To: <dummy_test_message_id> 349 In-Reply-To: <dummy_test_message_id>
370 Subject: Re: Testing... [assignedto=mary; nosy=+john] 350 Subject: Re: Testing... [assignedto=mary; nosy=+john]
371 351
372 This is a followup 352 This is a followup
373 ''') 353 ''')
374 handler = self.instance.MailGW(self.instance, self.db)
375 handler.trapExceptions = 0
376 handler.main(message)
377
378 self.compareMessages(self._get_mail(), 354 self.compareMessages(self._get_mail(),
379 '''FROM: roundup-admin@your.tracker.email.domain.example 355 '''FROM: roundup-admin@your.tracker.email.domain.example
380 TO: chef@bork.bork.bork, john@test, mary@test 356 TO: chef@bork.bork.bork, john@test, mary@test
381 Content-Type: text/plain; charset=utf-8 357 Content-Type: text/plain; charset=utf-8
382 Subject: [issue1] Testing... 358 Subject: [issue1] Testing...
406 ''') 382 ''')
407 383
408 def testFollowupNosyAuthor(self): 384 def testFollowupNosyAuthor(self):
409 self.doNewIssue() 385 self.doNewIssue()
410 self.db.config.ADD_AUTHOR_TO_NOSY = 'yes' 386 self.db.config.ADD_AUTHOR_TO_NOSY = 'yes'
411 message = StringIO('''Content-Type: text/plain; 387 self._send_mail('''Content-Type: text/plain;
412 charset="iso-8859-1" 388 charset="iso-8859-1"
413 From: john@test 389 From: john@test
414 To: issue_tracker@your.tracker.email.domain.example 390 To: issue_tracker@your.tracker.email.domain.example
415 Message-Id: <followup_dummy_id> 391 Message-Id: <followup_dummy_id>
416 In-Reply-To: <dummy_test_message_id> 392 In-Reply-To: <dummy_test_message_id>
417 Subject: [issue1] Testing... 393 Subject: [issue1] Testing...
418 394
419 This is a followup 395 This is a followup
420 ''') 396 ''')
421 handler = self.instance.MailGW(self.instance, self.db)
422 handler.trapExceptions = 0
423 handler.main(message)
424 397
425 self.compareMessages(self._get_mail(), 398 self.compareMessages(self._get_mail(),
426 '''FROM: roundup-admin@your.tracker.email.domain.example 399 '''FROM: roundup-admin@your.tracker.email.domain.example
427 TO: chef@bork.bork.bork, richard@test 400 TO: chef@bork.bork.bork, richard@test
428 Content-Type: text/plain; charset=utf-8 401 Content-Type: text/plain; charset=utf-8
453 ''') 426 ''')
454 427
455 def testFollowupNosyRecipients(self): 428 def testFollowupNosyRecipients(self):
456 self.doNewIssue() 429 self.doNewIssue()
457 self.db.config.ADD_RECIPIENTS_TO_NOSY = 'yes' 430 self.db.config.ADD_RECIPIENTS_TO_NOSY = 'yes'
458 message = StringIO('''Content-Type: text/plain; 431 self._send_mail('''Content-Type: text/plain;
459 charset="iso-8859-1" 432 charset="iso-8859-1"
460 From: richard@test 433 From: richard@test
461 To: issue_tracker@your.tracker.email.domain.example 434 To: issue_tracker@your.tracker.email.domain.example
462 Cc: john@test 435 Cc: john@test
463 Message-Id: <followup_dummy_id> 436 Message-Id: <followup_dummy_id>
464 In-Reply-To: <dummy_test_message_id> 437 In-Reply-To: <dummy_test_message_id>
465 Subject: [issue1] Testing... 438 Subject: [issue1] Testing...
466 439
467 This is a followup 440 This is a followup
468 ''') 441 ''')
469 handler = self.instance.MailGW(self.instance, self.db)
470 handler.trapExceptions = 0
471 handler.main(message)
472
473 self.compareMessages(self._get_mail(), 442 self.compareMessages(self._get_mail(),
474 '''FROM: roundup-admin@your.tracker.email.domain.example 443 '''FROM: roundup-admin@your.tracker.email.domain.example
475 TO: chef@bork.bork.bork 444 TO: chef@bork.bork.bork
476 Content-Type: text/plain; charset=utf-8 445 Content-Type: text/plain; charset=utf-8
477 Subject: [issue1] Testing... 446 Subject: [issue1] Testing...
502 471
503 def testFollowupNosyAuthorAndCopy(self): 472 def testFollowupNosyAuthorAndCopy(self):
504 self.doNewIssue() 473 self.doNewIssue()
505 self.db.config.ADD_AUTHOR_TO_NOSY = 'yes' 474 self.db.config.ADD_AUTHOR_TO_NOSY = 'yes'
506 self.db.config.MESSAGES_TO_AUTHOR = 'yes' 475 self.db.config.MESSAGES_TO_AUTHOR = 'yes'
507 message = StringIO('''Content-Type: text/plain; 476 self._send_mail('''Content-Type: text/plain;
508 charset="iso-8859-1" 477 charset="iso-8859-1"
509 From: john@test 478 From: john@test
510 To: issue_tracker@your.tracker.email.domain.example 479 To: issue_tracker@your.tracker.email.domain.example
511 Message-Id: <followup_dummy_id> 480 Message-Id: <followup_dummy_id>
512 In-Reply-To: <dummy_test_message_id> 481 In-Reply-To: <dummy_test_message_id>
513 Subject: [issue1] Testing... 482 Subject: [issue1] Testing...
514 483
515 This is a followup 484 This is a followup
516 ''') 485 ''')
517 handler = self.instance.MailGW(self.instance, self.db)
518 handler.trapExceptions = 0
519 handler.main(message)
520
521 self.compareMessages(self._get_mail(), 486 self.compareMessages(self._get_mail(),
522 '''FROM: roundup-admin@your.tracker.email.domain.example 487 '''FROM: roundup-admin@your.tracker.email.domain.example
523 TO: chef@bork.bork.bork, john@test, richard@test 488 TO: chef@bork.bork.bork, john@test, richard@test
524 Content-Type: text/plain; charset=utf-8 489 Content-Type: text/plain; charset=utf-8
525 Subject: [issue1] Testing... 490 Subject: [issue1] Testing...
549 ''') 514 ''')
550 515
551 def testFollowupNoNosyAuthor(self): 516 def testFollowupNoNosyAuthor(self):
552 self.doNewIssue() 517 self.doNewIssue()
553 self.instance.config.ADD_AUTHOR_TO_NOSY = 'no' 518 self.instance.config.ADD_AUTHOR_TO_NOSY = 'no'
554 message = StringIO('''Content-Type: text/plain; 519 self._send_mail('''Content-Type: text/plain;
555 charset="iso-8859-1" 520 charset="iso-8859-1"
556 From: john@test 521 From: john@test
557 To: issue_tracker@your.tracker.email.domain.example 522 To: issue_tracker@your.tracker.email.domain.example
558 Message-Id: <followup_dummy_id> 523 Message-Id: <followup_dummy_id>
559 In-Reply-To: <dummy_test_message_id> 524 In-Reply-To: <dummy_test_message_id>
560 Subject: [issue1] Testing... 525 Subject: [issue1] Testing...
561 526
562 This is a followup 527 This is a followup
563 ''') 528 ''')
564 handler = self.instance.MailGW(self.instance, self.db)
565 handler.trapExceptions = 0
566 handler.main(message)
567
568 self.compareMessages(self._get_mail(), 529 self.compareMessages(self._get_mail(),
569 '''FROM: roundup-admin@your.tracker.email.domain.example 530 '''FROM: roundup-admin@your.tracker.email.domain.example
570 TO: chef@bork.bork.bork, richard@test 531 TO: chef@bork.bork.bork, richard@test
571 Content-Type: text/plain; charset=utf-8 532 Content-Type: text/plain; charset=utf-8
572 Subject: [issue1] Testing... 533 Subject: [issue1] Testing...
595 ''') 556 ''')
596 557
597 def testFollowupNoNosyRecipients(self): 558 def testFollowupNoNosyRecipients(self):
598 self.doNewIssue() 559 self.doNewIssue()
599 self.instance.config.ADD_RECIPIENTS_TO_NOSY = 'no' 560 self.instance.config.ADD_RECIPIENTS_TO_NOSY = 'no'
600 message = StringIO('''Content-Type: text/plain; 561 self._send_mail('''Content-Type: text/plain;
601 charset="iso-8859-1" 562 charset="iso-8859-1"
602 From: richard@test 563 From: richard@test
603 To: issue_tracker@your.tracker.email.domain.example 564 To: issue_tracker@your.tracker.email.domain.example
604 Cc: john@test 565 Cc: john@test
605 Message-Id: <followup_dummy_id> 566 Message-Id: <followup_dummy_id>
606 In-Reply-To: <dummy_test_message_id> 567 In-Reply-To: <dummy_test_message_id>
607 Subject: [issue1] Testing... 568 Subject: [issue1] Testing...
608 569
609 This is a followup 570 This is a followup
610 ''') 571 ''')
611 handler = self.instance.MailGW(self.instance, self.db)
612 handler.trapExceptions = 0
613 handler.main(message)
614
615 self.compareMessages(self._get_mail(), 572 self.compareMessages(self._get_mail(),
616 '''FROM: roundup-admin@your.tracker.email.domain.example 573 '''FROM: roundup-admin@your.tracker.email.domain.example
617 TO: chef@bork.bork.bork 574 TO: chef@bork.bork.bork
618 Content-Type: text/plain; charset=utf-8 575 Content-Type: text/plain; charset=utf-8
619 Subject: [issue1] Testing... 576 Subject: [issue1] Testing...
642 ''') 599 ''')
643 600
644 def testFollowupEmptyMessage(self): 601 def testFollowupEmptyMessage(self):
645 self.doNewIssue() 602 self.doNewIssue()
646 603
647 message = StringIO('''Content-Type: text/plain; 604 self._send_mail('''Content-Type: text/plain;
648 charset="iso-8859-1" 605 charset="iso-8859-1"
649 From: richard <richard@test> 606 From: richard <richard@test>
650 To: issue_tracker@your.tracker.email.domain.example 607 To: issue_tracker@your.tracker.email.domain.example
651 Message-Id: <followup_dummy_id> 608 Message-Id: <followup_dummy_id>
652 In-Reply-To: <dummy_test_message_id> 609 In-Reply-To: <dummy_test_message_id>
653 Subject: [issue1] Testing... [assignedto=mary; nosy=+john] 610 Subject: [issue1] Testing... [assignedto=mary; nosy=+john]
654 611
655 ''') 612 ''')
656 handler = self.instance.MailGW(self.instance, self.db)
657 handler.trapExceptions = 0
658 handler.main(message)
659 l = self.db.issue.get('1', 'nosy') 613 l = self.db.issue.get('1', 'nosy')
660 l.sort() 614 l.sort()
661 self.assertEqual(l, ['3', '4', '5', '6']) 615 self.assertEqual(l, ['3', '4', '5', '6'])
662 616
663 # should be no file created (ie. no message) 617 # should be no file created (ie. no message)
664 assert not os.path.exists(SENDMAILDEBUG) 618 assert not os.path.exists(SENDMAILDEBUG)
665 619
666 def testNosyRemove(self): 620 def testNosyRemove(self):
667 self.doNewIssue() 621 self.doNewIssue()
668 622
669 message = StringIO('''Content-Type: text/plain; 623 self._send_mail('''Content-Type: text/plain;
670 charset="iso-8859-1" 624 charset="iso-8859-1"
671 From: richard <richard@test> 625 From: richard <richard@test>
672 To: issue_tracker@your.tracker.email.domain.example 626 To: issue_tracker@your.tracker.email.domain.example
673 Message-Id: <followup_dummy_id> 627 Message-Id: <followup_dummy_id>
674 In-Reply-To: <dummy_test_message_id> 628 In-Reply-To: <dummy_test_message_id>
675 Subject: [issue1] Testing... [nosy=-richard] 629 Subject: [issue1] Testing... [nosy=-richard]
676 630
677 ''') 631 ''')
678 handler = self.instance.MailGW(self.instance, self.db)
679 handler.trapExceptions = 0
680 handler.main(message)
681 l = self.db.issue.get('1', 'nosy') 632 l = self.db.issue.get('1', 'nosy')
682 l.sort() 633 l.sort()
683 self.assertEqual(l, ['3']) 634 self.assertEqual(l, ['3'])
684 635
685 # NO NOSY MESSAGE SHOULD BE SENT! 636 # NO NOSY MESSAGE SHOULD BE SENT!
693 self.db.user.set(anonid, roles='Anonymous') 644 self.db.user.set(anonid, roles='Anonymous')
694 645
695 self.db.security.hasPermission('Email Registration', anonid) 646 self.db.security.hasPermission('Email Registration', anonid)
696 l = self.db.user.list() 647 l = self.db.user.list()
697 l.sort() 648 l.sort()
698 s = '''Content-Type: text/plain; 649 message = '''Content-Type: text/plain;
699 charset="iso-8859-1" 650 charset="iso-8859-1"
700 From: fubar <fubar@bork.bork.bork> 651 From: fubar <fubar@bork.bork.bork>
701 To: issue_tracker@your.tracker.email.domain.example 652 To: issue_tracker@your.tracker.email.domain.example
702 Message-Id: <dummy_test_message_id> 653 Message-Id: <dummy_test_message_id>
703 Subject: [issue] Testing... 654 Subject: [issue] Testing...
704 655
705 This is a test submission of a new issue. 656 This is a test submission of a new issue.
706 ''' 657 '''
707 message = StringIO(s) 658 self.assertRaises(Unauthorized, self._send_mail, message)
708 handler = self.instance.MailGW(self.instance, self.db)
709 handler.trapExceptions = 0
710 self.assertRaises(Unauthorized, handler.main, message)
711 m = self.db.user.list() 659 m = self.db.user.list()
712 m.sort() 660 m.sort()
713 self.assertEqual(l, m) 661 self.assertEqual(l, m)
714 662
715 # now with the permission 663 # now with the permission
716 p = self.db.security.getPermission('Email Registration') 664 p = self.db.security.getPermission('Email Registration')
717 self.db.security.role['anonymous'].permissions=[p] 665 self.db.security.role['anonymous'].permissions=[p]
718 handler = self.instance.MailGW(self.instance, self.db) 666 self._send_mail(message)
719 handler.trapExceptions = 0
720 message = StringIO(s)
721 handler.main(message)
722 m = self.db.user.list() 667 m = self.db.user.list()
723 m.sort() 668 m.sort()
724 self.assertNotEqual(l, m) 669 self.assertNotEqual(l, m)
725 670
726 def testEnc01(self): 671 def testEnc01(self):
727 self.doNewIssue() 672 self.doNewIssue()
728 message = StringIO('''Content-Type: text/plain; 673 self._send_mail('''Content-Type: text/plain;
729 charset="iso-8859-1" 674 charset="iso-8859-1"
730 From: mary <mary@test> 675 From: mary <mary@test>
731 To: issue_tracker@your.tracker.email.domain.example 676 To: issue_tracker@your.tracker.email.domain.example
732 Message-Id: <followup_dummy_id> 677 Message-Id: <followup_dummy_id>
733 In-Reply-To: <dummy_test_message_id> 678 In-Reply-To: <dummy_test_message_id>
737 Content-Transfer-Encoding: quoted-printable 682 Content-Transfer-Encoding: quoted-printable
738 683
739 A message with encoding (encoded oe =F6) 684 A message with encoding (encoded oe =F6)
740 685
741 ''') 686 ''')
742 handler = self.instance.MailGW(self.instance, self.db)
743 handler.trapExceptions = 0
744 handler.main(message)
745 self.compareMessages(self._get_mail(), 687 self.compareMessages(self._get_mail(),
746 '''FROM: roundup-admin@your.tracker.email.domain.example 688 '''FROM: roundup-admin@your.tracker.email.domain.example
747 TO: chef@bork.bork.bork, richard@test 689 TO: chef@bork.bork.bork, richard@test
748 Content-Type: text/plain; charset=utf-8 690 Content-Type: text/plain; charset=utf-8
749 Subject: [issue1] Testing... 691 Subject: [issue1] Testing...
771 ''') 713 ''')
772 714
773 715
774 def testMultipartEnc01(self): 716 def testMultipartEnc01(self):
775 self.doNewIssue() 717 self.doNewIssue()
776 message = StringIO('''Content-Type: text/plain; 718 self._send_mail('''Content-Type: text/plain;
777 charset="iso-8859-1" 719 charset="iso-8859-1"
778 From: mary <mary@test> 720 From: mary <mary@test>
779 To: issue_tracker@your.tracker.email.domain.example 721 To: issue_tracker@your.tracker.email.domain.example
780 Message-Id: <followup_dummy_id> 722 Message-Id: <followup_dummy_id>
781 In-Reply-To: <dummy_test_message_id> 723 In-Reply-To: <dummy_test_message_id>
792 Content-Transfer-Encoding: quoted-printable 734 Content-Transfer-Encoding: quoted-printable
793 735
794 A message with first part encoded (encoded oe =F6) 736 A message with first part encoded (encoded oe =F6)
795 737
796 ''') 738 ''')
797 handler = self.instance.MailGW(self.instance, self.db)
798 handler.trapExceptions = 0
799 handler.main(message)
800 self.compareMessages(self._get_mail(), 739 self.compareMessages(self._get_mail(),
801 '''FROM: roundup-admin@your.tracker.email.domain.example 740 '''FROM: roundup-admin@your.tracker.email.domain.example
802 TO: chef@bork.bork.bork, richard@test 741 TO: chef@bork.bork.bork, richard@test
803 Content-Type: text/plain; charset=utf-8 742 Content-Type: text/plain; charset=utf-8
804 Subject: [issue1] Testing... 743 Subject: [issue1] Testing...
825 _______________________________________________________________________ 764 _______________________________________________________________________
826 ''') 765 ''')
827 766
828 def testContentDisposition(self): 767 def testContentDisposition(self):
829 self.doNewIssue() 768 self.doNewIssue()
830 message = StringIO('''Content-Type: text/plain; 769 self._send_mail('''Content-Type: text/plain;
831 charset="iso-8859-1" 770 charset="iso-8859-1"
832 From: mary <mary@test> 771 From: mary <mary@test>
833 To: issue_tracker@your.tracker.email.domain.example 772 To: issue_tracker@your.tracker.email.domain.example
834 Message-Id: <followup_dummy_id> 773 Message-Id: <followup_dummy_id>
835 In-Reply-To: <dummy_test_message_id> 774 In-Reply-To: <dummy_test_message_id>
850 789
851 xxxxxx 790 xxxxxx
852 791
853 --bCsyhTFzCvuiizWE-- 792 --bCsyhTFzCvuiizWE--
854 ''') 793 ''')
855 handler = self.instance.MailGW(self.instance, self.db)
856 handler.trapExceptions = 0
857 handler.main(message)
858 messages = self.db.issue.get('1', 'messages') 794 messages = self.db.issue.get('1', 'messages')
859 messages.sort() 795 messages.sort()
860 file = self.db.msg.get(messages[-1], 'files')[0] 796 file = self.db.msg.get(messages[-1], 'files')[0]
861 self.assertEqual(self.db.file.get(file, 'name'), 'main.dvi') 797 self.assertEqual(self.db.file.get(file, 'name'), 'main.dvi')
862 798
863 def testFollowupStupidQuoting(self): 799 def testFollowupStupidQuoting(self):
864 self.doNewIssue() 800 self.doNewIssue()
865 801
866 message = StringIO('''Content-Type: text/plain; 802 self._send_mail('''Content-Type: text/plain;
867 charset="iso-8859-1" 803 charset="iso-8859-1"
868 From: richard <richard@test> 804 From: richard <richard@test>
869 To: issue_tracker@your.tracker.email.domain.example 805 To: issue_tracker@your.tracker.email.domain.example
870 Message-Id: <followup_dummy_id> 806 Message-Id: <followup_dummy_id>
871 In-Reply-To: <dummy_test_message_id> 807 In-Reply-To: <dummy_test_message_id>
872 Subject: Re: "[issue1] Testing... " 808 Subject: Re: "[issue1] Testing... "
873 809
874 This is a followup 810 This is a followup
875 ''') 811 ''')
876 handler = self.instance.MailGW(self.instance, self.db)
877 handler.trapExceptions = 0
878 handler.main(message)
879
880 self.compareMessages(self._get_mail(), 812 self.compareMessages(self._get_mail(),
881 '''FROM: roundup-admin@your.tracker.email.domain.example 813 '''FROM: roundup-admin@your.tracker.email.domain.example
882 TO: chef@bork.bork.bork 814 TO: chef@bork.bork.bork
883 Content-Type: text/plain; charset=utf-8 815 Content-Type: text/plain; charset=utf-8
884 Subject: [issue1] Testing... 816 Subject: [issue1] Testing...
923 def innerTestQuoting(self, expect): 855 def innerTestQuoting(self, expect):
924 nodeid = self.doNewIssue() 856 nodeid = self.doNewIssue()
925 857
926 messages = self.db.issue.get(nodeid, 'messages') 858 messages = self.db.issue.get(nodeid, 'messages')
927 859
928 message = StringIO('''Content-Type: text/plain; 860 self._send_mail('''Content-Type: text/plain;
929 charset="iso-8859-1" 861 charset="iso-8859-1"
930 From: richard <richard@test> 862 From: richard <richard@test>
931 To: issue_tracker@your.tracker.email.domain.example 863 To: issue_tracker@your.tracker.email.domain.example
932 Message-Id: <followup_dummy_id> 864 Message-Id: <followup_dummy_id>
933 In-Reply-To: <dummy_test_message_id> 865 In-Reply-To: <dummy_test_message_id>
938 > skdjlkjsdfalsdkfjasdlfkj dlfksdfalksd fj 870 > skdjlkjsdfalsdkfjasdlfkj dlfksdfalksd fj
939 > 871 >
940 872
941 This is a followup 873 This is a followup
942 ''') 874 ''')
943 handler = self.instance.MailGW(self.instance, self.db)
944 handler.trapExceptions = 0
945 handler.main(message)
946
947 # figure the new message id 875 # figure the new message id
948 newmessages = self.db.issue.get(nodeid, 'messages') 876 newmessages = self.db.issue.get(nodeid, 'messages')
949 for msg in messages: 877 for msg in messages:
950 newmessages.remove(msg) 878 newmessages.remove(msg)
951 messageid = newmessages[0] 879 messageid = newmessages[0]
978 self.assertEqual(rfc2822.encode_header(unicode_header), unicode_encoded) 906 self.assertEqual(rfc2822.encode_header(unicode_header), unicode_encoded)
979 907
980 def testRegistrationConfirmation(self): 908 def testRegistrationConfirmation(self):
981 otk = "Aj4euk4LZSAdwePohj90SME5SpopLETL" 909 otk = "Aj4euk4LZSAdwePohj90SME5SpopLETL"
982 self.db.otks.set(otk, username='johannes', __time='') 910 self.db.otks.set(otk, username='johannes', __time='')
983 message = StringIO('''Content-Type: text/plain; 911 self._send_mail('''Content-Type: text/plain;
984 charset="iso-8859-1" 912 charset="iso-8859-1"
985 From: Chef <chef@bork.bork.bork> 913 From: Chef <chef@bork.bork.bork>
986 To: issue_tracker@your.tracker.email.domain.example 914 To: issue_tracker@your.tracker.email.domain.example
987 Cc: richard@test 915 Cc: richard@test
988 Message-Id: <dummy_test_message_id> 916 Message-Id: <dummy_test_message_id>
989 Subject: Re: Complete your registration to Roundup issue tracker 917 Subject: Re: Complete your registration to Roundup issue tracker
990 -- key %s 918 -- key %s
991 919
992 This is a test confirmation of registration. 920 This is a test confirmation of registration.
993 ''' % otk) 921 ''' % otk)
994 handler = self.instance.MailGW(self.instance, self.db)
995 handler.trapExceptions = 0
996 handler.main(message)
997
998 self.db.user.lookup('johannes') 922 self.db.user.lookup('johannes')
999 923
1000 def testFollowupOnNonIssue(self): 924 def testFollowupOnNonIssue(self):
1001 self.db.keyword.create(name='Foo') 925 self.db.keyword.create(name='Foo')
1002 message = StringIO('''Content-Type: text/plain; 926 self._send_mail('''Content-Type: text/plain;
1003 charset="iso-8859-1" 927 charset="iso-8859-1"
1004 From: richard <richard@test> 928 From: richard <richard@test>
1005 To: issue_tracker@your.tracker.email.domain.example 929 To: issue_tracker@your.tracker.email.domain.example
1006 Message-Id: <followup_dummy_id> 930 Message-Id: <followup_dummy_id>
1007 In-Reply-To: <dummy_test_message_id> 931 In-Reply-To: <dummy_test_message_id>
1008 Subject: [keyword1] Testing... [name=Bar] 932 Subject: [keyword1] Testing... [name=Bar]
1009 933
1010 ''') 934 ''')
1011 handler = self.instance.MailGW(self.instance, self.db)
1012 handler.trapExceptions = 0
1013 handler.main(message)
1014
1015 self.assertEqual(self.db.keyword.get('1', 'name'), 'Bar') 935 self.assertEqual(self.db.keyword.get('1', 'name'), 'Bar')
1016 936
1017 def test_suite(): 937 def test_suite():
1018 suite = unittest.TestSuite() 938 suite = unittest.TestSuite()
1019 suite.addTest(unittest.makeSuite(MailgwTestCase)) 939 suite.addTest(unittest.makeSuite(MailgwTestCase))

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