1 #
2 # Copyright (c) 2001 Richard Jones, richard@bofh.asn.au.
3 # This module is free software, and you may redistribute it and/or modify
4 # under the same terms as Python, so long as this copyright message and
5 # disclaimer are retained in their original form.
6 #
7 # This module is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 #
11 # $Id: test_mailgw.py,v 1.35 2002-12-10 00:46:55 richard Exp $
13 import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys, difflib
15 # Note: Should parse emails according to RFC2822 instead of performing a
16 # literal string comparision. Parsing the messages allows the tests to work for
17 # any legal serialization of an email.
18 #try :
19 # import email
20 #except ImportError :
21 # import rfc822 as email
23 from roundup.mailgw import MailGW, Unauthorized
24 from roundup import init, instance
26 # TODO: make this output only enough equal lines for context, not all of
27 # them
28 class DiffHelper:
29 def compareStrings(self, s2, s1):
30 '''Note the reversal of s2 and s1 - difflib.SequenceMatcher wants
31 the first to be the "original" but in the calls in this file,
32 the second arg is the original. Ho hum.
33 '''
34 if s1 == s2:
35 return
37 # under python2.[12] we allow a difference of one trailing empty line.
38 if sys.version_info[0:2] == (2,1):
39 if s1+'\n' == s2:
40 return
41 if sys.version_info[0:2] == (2,2):
42 if s1 == s2+'\n':
43 return
45 l1=s1.split('\n')
46 l2=s2.split('\n')
47 s = difflib.SequenceMatcher(None, l1, l2)
48 res = ['Generated message not correct (diff follows):']
49 for value, s1s, s1e, s2s, s2e in s.get_opcodes():
50 if value == 'equal':
51 for i in range(s1s, s1e):
52 res.append(' %s'%l1[i])
53 elif value == 'delete':
54 for i in range(s1s, s1e):
55 res.append('- %s'%l1[i])
56 elif value == 'insert':
57 for i in range(s2s, s2e):
58 res.append('+ %s'%l2[i])
59 elif value == 'replace':
60 for i, j in zip(range(s1s, s1e), range(s2s, s2e)):
61 res.append('- %s'%l1[i])
62 res.append('+ %s'%l2[j])
64 raise AssertionError, '\n'.join(res)
66 class MailgwTestCase(unittest.TestCase, DiffHelper):
67 count = 0
68 schema = 'classic'
69 def setUp(self):
70 MailgwTestCase.count = MailgwTestCase.count + 1
71 self.dirname = '_test_mailgw_%s'%self.count
72 try:
73 shutil.rmtree(self.dirname)
74 except OSError, error:
75 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
76 # create the instance
77 init.install(self.dirname, 'classic', 'anydbm')
78 init.initialise(self.dirname, 'sekrit')
79 # check we can load the package
80 self.instance = instance.open(self.dirname)
81 # and open the database
82 self.db = self.instance.open('admin')
83 self.db.user.create(username='Chef', address='chef@bork.bork.bork',
84 realname='Bork, Chef', roles='User')
85 self.db.user.create(username='richard', address='richard@test',
86 roles='User')
87 self.db.user.create(username='mary', address='mary@test',
88 roles='User', realname='Contrary, Mary')
89 self.db.user.create(username='john', address='john@test',
90 alternate_addresses='jondoe@test\njohn.doe@test', roles='User',
91 realname='John Doe')
93 def tearDown(self):
94 if os.path.exists(os.environ['SENDMAILDEBUG']):
95 os.remove(os.environ['SENDMAILDEBUG'])
96 self.db.close()
97 try:
98 shutil.rmtree(self.dirname)
99 except OSError, error:
100 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
102 def doNewIssue(self):
103 message = cStringIO.StringIO('''Content-Type: text/plain;
104 charset="iso-8859-1"
105 From: Chef <chef@bork.bork.bork>
106 To: issue_tracker@your.tracker.email.domain.example
107 Cc: richard@test
108 Message-Id: <dummy_test_message_id>
109 Subject: [issue] Testing...
111 This is a test submission of a new issue.
112 ''')
113 handler = self.instance.MailGW(self.instance, self.db)
114 handler.trapExceptions = 0
115 nodeid = handler.main(message)
116 if os.path.exists(os.environ['SENDMAILDEBUG']):
117 error = open(os.environ['SENDMAILDEBUG']).read()
118 self.assertEqual('no error', error)
119 l = self.db.issue.get(nodeid, 'nosy')
120 l.sort()
121 self.assertEqual(l, ['3', '4'])
122 return nodeid
124 def testNewIssue(self):
125 self.doNewIssue()
127 def testNewIssueNosy(self):
128 self.instance.config.ADD_AUTHOR_TO_NOSY = 'yes'
129 message = cStringIO.StringIO('''Content-Type: text/plain;
130 charset="iso-8859-1"
131 From: Chef <chef@bork.bork.bork>
132 To: issue_tracker@your.tracker.email.domain.example
133 Cc: richard@test
134 Message-Id: <dummy_test_message_id>
135 Subject: [issue] Testing...
137 This is a test submission of a new issue.
138 ''')
139 handler = self.instance.MailGW(self.instance, self.db)
140 handler.trapExceptions = 0
141 nodeid = handler.main(message)
142 if os.path.exists(os.environ['SENDMAILDEBUG']):
143 error = open(os.environ['SENDMAILDEBUG']).read()
144 self.assertEqual('no error', error)
145 l = self.db.issue.get(nodeid, 'nosy')
146 l.sort()
147 self.assertEqual(l, ['3', '4'])
149 def testAlternateAddress(self):
150 message = cStringIO.StringIO('''Content-Type: text/plain;
151 charset="iso-8859-1"
152 From: John Doe <john.doe@test>
153 To: issue_tracker@your.tracker.email.domain.example
154 Message-Id: <dummy_test_message_id>
155 Subject: [issue] Testing...
157 This is a test submission of a new issue.
158 ''')
159 userlist = self.db.user.list()
160 handler = self.instance.MailGW(self.instance, self.db)
161 handler.trapExceptions = 0
162 handler.main(message)
163 if os.path.exists(os.environ['SENDMAILDEBUG']):
164 error = open(os.environ['SENDMAILDEBUG']).read()
165 self.assertEqual('no error', error)
166 self.assertEqual(userlist, self.db.user.list(),
167 "user created when it shouldn't have been")
169 def testNewIssueNoClass(self):
170 message = cStringIO.StringIO('''Content-Type: text/plain;
171 charset="iso-8859-1"
172 From: Chef <chef@bork.bork.bork>
173 To: issue_tracker@your.tracker.email.domain.example
174 Cc: richard@test
175 Message-Id: <dummy_test_message_id>
176 Subject: Testing...
178 This is a test submission of a new issue.
179 ''')
180 handler = self.instance.MailGW(self.instance, self.db)
181 handler.trapExceptions = 0
182 handler.main(message)
183 if os.path.exists(os.environ['SENDMAILDEBUG']):
184 error = open(os.environ['SENDMAILDEBUG']).read()
185 self.assertEqual('no error', error)
187 def testNewIssueAuthMsg(self):
188 message = cStringIO.StringIO('''Content-Type: text/plain;
189 charset="iso-8859-1"
190 From: Chef <chef@bork.bork.bork>
191 To: issue_tracker@your.tracker.email.domain.example
192 Message-Id: <dummy_test_message_id>
193 Subject: [issue] Testing... [nosy=mary; assignedto=richard]
195 This is a test submission of a new issue.
196 ''')
197 handler = self.instance.MailGW(self.instance, self.db)
198 handler.trapExceptions = 0
199 # TODO: fix the damn config - this is apalling
200 self.db.config.MESSAGES_TO_AUTHOR = 'yes'
201 handler.main(message)
203 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
204 '''FROM: roundup-admin@your.tracker.email.domain.example
205 TO: chef@bork.bork.bork, mary@test, richard@test
206 Content-Type: text/plain
207 Subject: [issue1] Testing...
208 To: chef@bork.bork.bork, mary@test, richard@test
209 From: "Bork, Chef" <issue_tracker@your.tracker.email.domain.example>
210 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
211 MIME-Version: 1.0
212 Message-Id: <dummy_test_message_id>
213 X-Roundup-Name: Roundup issue tracker
214 X-Roundup-Loop: hello
215 Content-Transfer-Encoding: quoted-printable
218 New submission from Bork, Chef <chef@bork.bork.bork>:
220 This is a test submission of a new issue.
223 ----------
224 assignedto: richard
225 messages: 1
226 nosy: Chef, mary, richard
227 status: unread
228 title: Testing...
229 _______________________________________________________________________
230 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
231 http://your.tracker.url.example/issue1
232 _______________________________________________________________________
233 ''')
235 # BUG
236 # def testMultipart(self):
237 # '''With more than one part'''
238 # see MultipartEnc tests: but if there is more than one part
239 # we return a multipart/mixed and the boundary contains
240 # the ip address of the test machine.
242 # BUG should test some binary attamchent too.
244 def testSimpleFollowup(self):
245 self.doNewIssue()
246 message = cStringIO.StringIO('''Content-Type: text/plain;
247 charset="iso-8859-1"
248 From: mary <mary@test>
249 To: issue_tracker@your.tracker.email.domain.example
250 Message-Id: <followup_dummy_id>
251 In-Reply-To: <dummy_test_message_id>
252 Subject: [issue1] Testing...
254 This is a second followup
255 ''')
256 handler = self.instance.MailGW(self.instance, self.db)
257 handler.trapExceptions = 0
258 handler.main(message)
259 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
260 '''FROM: roundup-admin@your.tracker.email.domain.example
261 TO: chef@bork.bork.bork, richard@test
262 Content-Type: text/plain
263 Subject: [issue1] Testing...
264 To: chef@bork.bork.bork, richard@test
265 From: "Contrary, Mary" <issue_tracker@your.tracker.email.domain.example>
266 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
267 MIME-Version: 1.0
268 Message-Id: <followup_dummy_id>
269 In-Reply-To: <dummy_test_message_id>
270 X-Roundup-Name: Roundup issue tracker
271 X-Roundup-Loop: hello
272 Content-Transfer-Encoding: quoted-printable
275 Contrary, Mary <mary@test> added the comment:
277 This is a second followup
280 ----------
281 status: unread -> chatting
282 _______________________________________________________________________
283 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
284 http://your.tracker.url.example/issue1
285 _______________________________________________________________________
286 ''')
288 def testFollowup(self):
289 self.doNewIssue()
291 message = cStringIO.StringIO('''Content-Type: text/plain;
292 charset="iso-8859-1"
293 From: richard <richard@test>
294 To: issue_tracker@your.tracker.email.domain.example
295 Message-Id: <followup_dummy_id>
296 In-Reply-To: <dummy_test_message_id>
297 Subject: [issue1] Testing... [assignedto=mary; nosy=+john]
299 This is a followup
300 ''')
301 handler = self.instance.MailGW(self.instance, self.db)
302 handler.trapExceptions = 0
303 handler.main(message)
304 l = self.db.issue.get('1', 'nosy')
305 l.sort()
306 self.assertEqual(l, ['3', '4', '5', '6'])
308 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
309 '''FROM: roundup-admin@your.tracker.email.domain.example
310 TO: chef@bork.bork.bork, john@test, mary@test
311 Content-Type: text/plain
312 Subject: [issue1] Testing...
313 To: chef@bork.bork.bork, john@test, mary@test
314 From: richard <issue_tracker@your.tracker.email.domain.example>
315 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
316 MIME-Version: 1.0
317 Message-Id: <followup_dummy_id>
318 In-Reply-To: <dummy_test_message_id>
319 X-Roundup-Name: Roundup issue tracker
320 X-Roundup-Loop: hello
321 Content-Transfer-Encoding: quoted-printable
324 richard <richard@test> added the comment:
326 This is a followup
329 ----------
330 assignedto: -> mary
331 nosy: +john, mary
332 status: unread -> chatting
333 _______________________________________________________________________
334 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
335 http://your.tracker.url.example/issue1
336 _______________________________________________________________________
337 ''')
339 def testFollowupTitleMatch(self):
340 self.doNewIssue()
341 message = cStringIO.StringIO('''Content-Type: text/plain;
342 charset="iso-8859-1"
343 From: richard <richard@test>
344 To: issue_tracker@your.tracker.email.domain.example
345 Message-Id: <followup_dummy_id>
346 In-Reply-To: <dummy_test_message_id>
347 Subject: Re: Testing... [assignedto=mary; nosy=+john]
349 This is a followup
350 ''')
351 handler = self.instance.MailGW(self.instance, self.db)
352 handler.trapExceptions = 0
353 handler.main(message)
355 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
356 '''FROM: roundup-admin@your.tracker.email.domain.example
357 TO: chef@bork.bork.bork, john@test, mary@test
358 Content-Type: text/plain
359 Subject: [issue1] Testing...
360 To: chef@bork.bork.bork, john@test, mary@test
361 From: richard <issue_tracker@your.tracker.email.domain.example>
362 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
363 MIME-Version: 1.0
364 Message-Id: <followup_dummy_id>
365 In-Reply-To: <dummy_test_message_id>
366 X-Roundup-Name: Roundup issue tracker
367 X-Roundup-Loop: hello
368 Content-Transfer-Encoding: quoted-printable
371 richard <richard@test> added the comment:
373 This is a followup
376 ----------
377 assignedto: -> mary
378 nosy: +john, mary
379 status: unread -> chatting
380 _______________________________________________________________________
381 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
382 http://your.tracker.url.example/issue1
383 _______________________________________________________________________
384 ''')
386 def testFollowupNosyAuthor(self):
387 self.doNewIssue()
388 self.db.config.ADD_AUTHOR_TO_NOSY = 'yes'
389 message = cStringIO.StringIO('''Content-Type: text/plain;
390 charset="iso-8859-1"
391 From: john@test
392 To: issue_tracker@your.tracker.email.domain.example
393 Message-Id: <followup_dummy_id>
394 In-Reply-To: <dummy_test_message_id>
395 Subject: [issue1] Testing...
397 This is a followup
398 ''')
399 handler = self.instance.MailGW(self.instance, self.db)
400 handler.trapExceptions = 0
401 handler.main(message)
403 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
404 '''FROM: roundup-admin@your.tracker.email.domain.example
405 TO: chef@bork.bork.bork, richard@test
406 Content-Type: text/plain
407 Subject: [issue1] Testing...
408 To: chef@bork.bork.bork, richard@test
409 From: John Doe <issue_tracker@your.tracker.email.domain.example>
410 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
411 MIME-Version: 1.0
412 Message-Id: <followup_dummy_id>
413 In-Reply-To: <dummy_test_message_id>
414 X-Roundup-Name: Roundup issue tracker
415 X-Roundup-Loop: hello
416 Content-Transfer-Encoding: quoted-printable
419 John Doe <john@test> added the comment:
421 This is a followup
424 ----------
425 nosy: +john
426 status: unread -> chatting
427 _______________________________________________________________________
428 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
429 http://your.tracker.url.example/issue1
430 _______________________________________________________________________
432 ''')
434 def testFollowupNosyRecipients(self):
435 self.doNewIssue()
436 self.db.config.ADD_RECIPIENTS_TO_NOSY = 'yes'
437 message = cStringIO.StringIO('''Content-Type: text/plain;
438 charset="iso-8859-1"
439 From: richard@test
440 To: issue_tracker@your.tracker.email.domain.example
441 Cc: john@test
442 Message-Id: <followup_dummy_id>
443 In-Reply-To: <dummy_test_message_id>
444 Subject: [issue1] Testing...
446 This is a followup
447 ''')
448 handler = self.instance.MailGW(self.instance, self.db)
449 handler.trapExceptions = 0
450 handler.main(message)
452 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
453 '''FROM: roundup-admin@your.tracker.email.domain.example
454 TO: chef@bork.bork.bork
455 Content-Type: text/plain
456 Subject: [issue1] Testing...
457 To: chef@bork.bork.bork
458 From: richard <issue_tracker@your.tracker.email.domain.example>
459 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
460 MIME-Version: 1.0
461 Message-Id: <followup_dummy_id>
462 In-Reply-To: <dummy_test_message_id>
463 X-Roundup-Name: Roundup issue tracker
464 X-Roundup-Loop: hello
465 Content-Transfer-Encoding: quoted-printable
468 richard <richard@test> added the comment:
470 This is a followup
473 ----------
474 nosy: +john
475 status: unread -> chatting
476 _______________________________________________________________________
477 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
478 http://your.tracker.url.example/issue1
479 _______________________________________________________________________
481 ''')
483 def testFollowupNosyAuthorAndCopy(self):
484 self.doNewIssue()
485 self.db.config.ADD_AUTHOR_TO_NOSY = 'yes'
486 self.db.config.MESSAGES_TO_AUTHOR = 'yes'
487 message = cStringIO.StringIO('''Content-Type: text/plain;
488 charset="iso-8859-1"
489 From: john@test
490 To: issue_tracker@your.tracker.email.domain.example
491 Message-Id: <followup_dummy_id>
492 In-Reply-To: <dummy_test_message_id>
493 Subject: [issue1] Testing...
495 This is a followup
496 ''')
497 handler = self.instance.MailGW(self.instance, self.db)
498 handler.trapExceptions = 0
499 handler.main(message)
501 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
502 '''FROM: roundup-admin@your.tracker.email.domain.example
503 TO: chef@bork.bork.bork, john@test, richard@test
504 Content-Type: text/plain
505 Subject: [issue1] Testing...
506 To: chef@bork.bork.bork, john@test, richard@test
507 From: John Doe <issue_tracker@your.tracker.email.domain.example>
508 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
509 MIME-Version: 1.0
510 Message-Id: <followup_dummy_id>
511 In-Reply-To: <dummy_test_message_id>
512 X-Roundup-Name: Roundup issue tracker
513 X-Roundup-Loop: hello
514 Content-Transfer-Encoding: quoted-printable
517 John Doe <john@test> added the comment:
519 This is a followup
522 ----------
523 nosy: +john
524 status: unread -> chatting
525 _______________________________________________________________________
526 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
527 http://your.tracker.url.example/issue1
528 _______________________________________________________________________
530 ''')
532 def testFollowupNoNosyAuthor(self):
533 self.doNewIssue()
534 self.instance.config.ADD_AUTHOR_TO_NOSY = 'no'
535 message = cStringIO.StringIO('''Content-Type: text/plain;
536 charset="iso-8859-1"
537 From: john@test
538 To: issue_tracker@your.tracker.email.domain.example
539 Message-Id: <followup_dummy_id>
540 In-Reply-To: <dummy_test_message_id>
541 Subject: [issue1] Testing...
543 This is a followup
544 ''')
545 handler = self.instance.MailGW(self.instance, self.db)
546 handler.trapExceptions = 0
547 handler.main(message)
549 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
550 '''FROM: roundup-admin@your.tracker.email.domain.example
551 TO: chef@bork.bork.bork, richard@test
552 Content-Type: text/plain
553 Subject: [issue1] Testing...
554 To: chef@bork.bork.bork, richard@test
555 From: John Doe <issue_tracker@your.tracker.email.domain.example>
556 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
557 MIME-Version: 1.0
558 Message-Id: <followup_dummy_id>
559 In-Reply-To: <dummy_test_message_id>
560 X-Roundup-Name: Roundup issue tracker
561 X-Roundup-Loop: hello
562 Content-Transfer-Encoding: quoted-printable
565 John Doe <john@test> added the comment:
567 This is a followup
570 ----------
571 status: unread -> chatting
572 _______________________________________________________________________
573 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
574 http://your.tracker.url.example/issue1
575 _______________________________________________________________________
577 ''')
579 def testFollowupNoNosyRecipients(self):
580 self.doNewIssue()
581 self.instance.config.ADD_RECIPIENTS_TO_NOSY = 'no'
582 message = cStringIO.StringIO('''Content-Type: text/plain;
583 charset="iso-8859-1"
584 From: richard@test
585 To: issue_tracker@your.tracker.email.domain.example
586 Cc: john@test
587 Message-Id: <followup_dummy_id>
588 In-Reply-To: <dummy_test_message_id>
589 Subject: [issue1] Testing...
591 This is a followup
592 ''')
593 handler = self.instance.MailGW(self.instance, self.db)
594 handler.trapExceptions = 0
595 handler.main(message)
597 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
598 '''FROM: roundup-admin@your.tracker.email.domain.example
599 TO: chef@bork.bork.bork
600 Content-Type: text/plain
601 Subject: [issue1] Testing...
602 To: chef@bork.bork.bork
603 From: richard <issue_tracker@your.tracker.email.domain.example>
604 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
605 MIME-Version: 1.0
606 Message-Id: <followup_dummy_id>
607 In-Reply-To: <dummy_test_message_id>
608 X-Roundup-Name: Roundup issue tracker
609 X-Roundup-Loop: hello
610 Content-Transfer-Encoding: quoted-printable
613 richard <richard@test> added the comment:
615 This is a followup
618 ----------
619 status: unread -> chatting
620 _______________________________________________________________________
621 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
622 http://your.tracker.url.example/issue1
623 _______________________________________________________________________
625 ''')
627 def testNosyRemove(self):
628 self.doNewIssue()
630 message = cStringIO.StringIO('''Content-Type: text/plain;
631 charset="iso-8859-1"
632 From: richard <richard@test>
633 To: issue_tracker@your.tracker.email.domain.example
634 Message-Id: <followup_dummy_id>
635 In-Reply-To: <dummy_test_message_id>
636 Subject: [issue1] Testing... [nosy=-richard]
638 ''')
639 handler = self.instance.MailGW(self.instance, self.db)
640 handler.trapExceptions = 0
641 handler.main(message)
642 l = self.db.issue.get('1', 'nosy')
643 l.sort()
644 self.assertEqual(l, ['3'])
646 # NO NOSY MESSAGE SHOULD BE SENT!
647 self.assert_(not os.path.exists(os.environ['SENDMAILDEBUG']))
649 def testNewUserAuthor(self):
650 # first without the permission
651 # heh... just ignore the API for a second ;)
652 self.db.security.role['Anonymous'].permissions=[]
653 anonid = self.db.user.lookup('anonymous')
654 self.db.user.set(anonid, roles='Anonymous')
656 self.db.security.hasPermission('Email Registration', anonid)
657 l = self.db.user.list()
658 l.sort()
659 s = '''Content-Type: text/plain;
660 charset="iso-8859-1"
661 From: fubar <fubar@bork.bork.bork>
662 To: issue_tracker@your.tracker.email.domain.example
663 Message-Id: <dummy_test_message_id>
664 Subject: [issue] Testing...
666 This is a test submission of a new issue.
667 '''
668 message = cStringIO.StringIO(s)
669 handler = self.instance.MailGW(self.instance, self.db)
670 handler.trapExceptions = 0
671 self.assertRaises(Unauthorized, handler.main, message)
672 m = self.db.user.list()
673 m.sort()
674 self.assertEqual(l, m)
676 # now with the permission
677 p = self.db.security.getPermission('Email Registration')
678 self.db.security.role['Anonymous'].permissions=[p]
679 handler = self.instance.MailGW(self.instance, self.db)
680 handler.trapExceptions = 0
681 message = cStringIO.StringIO(s)
682 handler.main(message)
683 m = self.db.user.list()
684 m.sort()
685 self.assertNotEqual(l, m)
687 def testEnc01(self):
688 self.doNewIssue()
689 message = cStringIO.StringIO('''Content-Type: text/plain;
690 charset="iso-8859-1"
691 From: mary <mary@test>
692 To: issue_tracker@your.tracker.email.domain.example
693 Message-Id: <followup_dummy_id>
694 In-Reply-To: <dummy_test_message_id>
695 Subject: [issue1] Testing...
696 Content-Type: text/plain;
697 charset="iso-8859-1"
698 Content-Transfer-Encoding: quoted-printable
700 A message with encoding (encoded oe =F6)
702 ''')
703 handler = self.instance.MailGW(self.instance, self.db)
704 handler.trapExceptions = 0
705 handler.main(message)
706 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
707 '''FROM: roundup-admin@your.tracker.email.domain.example
708 TO: chef@bork.bork.bork, richard@test
709 Content-Type: text/plain
710 Subject: [issue1] Testing...
711 To: chef@bork.bork.bork, richard@test
712 From: "Contrary, Mary" <issue_tracker@your.tracker.email.domain.example>
713 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
714 MIME-Version: 1.0
715 Message-Id: <followup_dummy_id>
716 In-Reply-To: <dummy_test_message_id>
717 X-Roundup-Name: Roundup issue tracker
718 X-Roundup-Loop: hello
719 Content-Transfer-Encoding: quoted-printable
722 Contrary, Mary <mary@test> added the comment:
724 A message with encoding (encoded oe =F6)
726 ----------
727 status: unread -> chatting
728 _______________________________________________________________________
729 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
730 http://your.tracker.url.example/issue1
731 _______________________________________________________________________
732 ''')
735 def testMultipartEnc01(self):
736 self.doNewIssue()
737 message = cStringIO.StringIO('''Content-Type: text/plain;
738 charset="iso-8859-1"
739 From: mary <mary@test>
740 To: issue_tracker@your.tracker.email.domain.example
741 Message-Id: <followup_dummy_id>
742 In-Reply-To: <dummy_test_message_id>
743 Subject: [issue1] Testing...
744 Content-Type: multipart/mixed;
745 boundary="----_=_NextPart_000_01"
747 This message is in MIME format. Since your mail reader does not understand
748 this format, some or all of this message may not be legible.
750 ------_=_NextPart_000_01
751 Content-Type: text/plain;
752 charset="iso-8859-1"
753 Content-Transfer-Encoding: quoted-printable
755 A message with first part encoded (encoded oe =F6)
757 ''')
758 handler = self.instance.MailGW(self.instance, self.db)
759 handler.trapExceptions = 0
760 handler.main(message)
761 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
762 '''FROM: roundup-admin@your.tracker.email.domain.example
763 TO: chef@bork.bork.bork, richard@test
764 Content-Type: text/plain
765 Subject: [issue1] Testing...
766 To: chef@bork.bork.bork, richard@test
767 From: "Contrary, Mary" <issue_tracker@your.tracker.email.domain.example>
768 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
769 MIME-Version: 1.0
770 Message-Id: <followup_dummy_id>
771 In-Reply-To: <dummy_test_message_id>
772 X-Roundup-Name: Roundup issue tracker
773 X-Roundup-Loop: hello
774 Content-Transfer-Encoding: quoted-printable
777 Contrary, Mary <mary@test> added the comment:
779 A message with first part encoded (encoded oe =F6)
781 ----------
782 status: unread -> chatting
783 _______________________________________________________________________
784 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
785 http://your.tracker.url.example/issue1
786 _______________________________________________________________________
787 ''')
789 def testFollowupStupidQuoting(self):
790 self.doNewIssue()
792 message = cStringIO.StringIO('''Content-Type: text/plain;
793 charset="iso-8859-1"
794 From: richard <richard@test>
795 To: issue_tracker@your.tracker.email.domain.example
796 Message-Id: <followup_dummy_id>
797 In-Reply-To: <dummy_test_message_id>
798 Subject: Re: "[issue1] Testing... "
800 This is a followup
801 ''')
802 handler = self.instance.MailGW(self.instance, self.db)
803 handler.trapExceptions = 0
804 handler.main(message)
806 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
807 '''FROM: roundup-admin@your.tracker.email.domain.example
808 TO: chef@bork.bork.bork
809 Content-Type: text/plain
810 Subject: [issue1] Testing...
811 To: chef@bork.bork.bork
812 From: richard <issue_tracker@your.tracker.email.domain.example>
813 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
814 MIME-Version: 1.0
815 Message-Id: <followup_dummy_id>
816 In-Reply-To: <dummy_test_message_id>
817 X-Roundup-Name: Roundup issue tracker
818 X-Roundup-Loop: hello
819 Content-Transfer-Encoding: quoted-printable
822 richard <richard@test> added the comment:
824 This is a followup
827 ----------
828 status: unread -> chatting
829 _______________________________________________________________________
830 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
831 http://your.tracker.url.example/issue1
832 _______________________________________________________________________
833 ''')
835 def testEmailQuoting(self):
836 self.instance.config.EMAIL_KEEP_QUOTED_TEXT = 'no'
837 self.innerTestQuoting('''This is a followup
838 ''')
840 def testEmailQuotingRemove(self):
841 self.instance.config.EMAIL_KEEP_QUOTED_TEXT = 'yes'
842 self.innerTestQuoting('''Blah blah wrote:
843 > Blah bklaskdfj sdf asdf jlaskdf skj sdkfjl asdf
844 > skdjlkjsdfalsdkfjasdlfkj dlfksdfalksd fj
845 >
847 This is a followup
848 ''')
850 def innerTestQuoting(self, expect):
851 nodeid = self.doNewIssue()
853 messages = self.db.issue.get(nodeid, 'messages')
855 message = cStringIO.StringIO('''Content-Type: text/plain;
856 charset="iso-8859-1"
857 From: richard <richard@test>
858 To: issue_tracker@your.tracker.email.domain.example
859 Message-Id: <followup_dummy_id>
860 In-Reply-To: <dummy_test_message_id>
861 Subject: Re: [issue1] Testing...
863 Blah blah wrote:
864 > Blah bklaskdfj sdf asdf jlaskdf skj sdkfjl asdf
865 > skdjlkjsdfalsdkfjasdlfkj dlfksdfalksd fj
866 >
868 This is a followup
869 ''')
870 handler = self.instance.MailGW(self.instance, self.db)
871 handler.trapExceptions = 0
872 handler.main(message)
874 # figure the new message id
875 newmessages = self.db.issue.get(nodeid, 'messages')
876 for msg in messages:
877 newmessages.remove(msg)
878 messageid = newmessages[0]
880 self.compareStrings(self.db.msg.get(messageid, 'content'), expect)
882 def suite():
883 l = [unittest.makeSuite(MailgwTestCase),
884 ]
885 return unittest.TestSuite(l)
888 # vim: set filetype=python ts=4 sw=4 et si