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.39 2003-02-06 05:43:49 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 # we have to special-case the Date: header here 'cos we can't test
35 # for it properly
36 l1=s1.strip().split('\n')
37 l2=[x for x in s2.strip().split('\n') if not x.startswith('Date: ')]
38 if l1 == l2:
39 return
41 s = difflib.SequenceMatcher(None, l1, l2)
42 res = ['Generated message not correct (diff follows):']
43 for value, s1s, s1e, s2s, s2e in s.get_opcodes():
44 if value == 'equal':
45 for i in range(s1s, s1e):
46 res.append(' %s'%l1[i])
47 elif value == 'delete':
48 for i in range(s1s, s1e):
49 res.append('- %s'%l1[i])
50 elif value == 'insert':
51 for i in range(s2s, s2e):
52 res.append('+ %s'%l2[i])
53 elif value == 'replace':
54 for i, j in zip(range(s1s, s1e), range(s2s, s2e)):
55 res.append('- %s'%l1[i])
56 res.append('+ %s'%l2[j])
58 raise AssertionError, '\n'.join(res)
60 class MailgwTestCase(unittest.TestCase, DiffHelper):
61 count = 0
62 schema = 'classic'
63 def setUp(self):
64 MailgwTestCase.count = MailgwTestCase.count + 1
65 self.dirname = '_test_mailgw_%s'%self.count
66 try:
67 shutil.rmtree(self.dirname)
68 except OSError, error:
69 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
70 # create the instance
71 init.install(self.dirname, 'classic', 'anydbm')
72 init.initialise(self.dirname, 'sekrit')
73 # check we can load the package
74 self.instance = instance.open(self.dirname)
75 # and open the database
76 self.db = self.instance.open('admin')
77 self.db.user.create(username='Chef', address='chef@bork.bork.bork',
78 realname='Bork, Chef', roles='User')
79 self.db.user.create(username='richard', address='richard@test',
80 roles='User')
81 self.db.user.create(username='mary', address='mary@test',
82 roles='User', realname='Contrary, Mary')
83 self.db.user.create(username='john', address='john@test',
84 alternate_addresses='jondoe@test\njohn.doe@test', roles='User',
85 realname='John Doe')
87 def tearDown(self):
88 if os.path.exists(os.environ['SENDMAILDEBUG']):
89 os.remove(os.environ['SENDMAILDEBUG'])
90 self.db.close()
91 try:
92 shutil.rmtree(self.dirname)
93 except OSError, error:
94 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
96 def doNewIssue(self):
97 message = cStringIO.StringIO('''Content-Type: text/plain;
98 charset="iso-8859-1"
99 From: Chef <chef@bork.bork.bork>
100 To: issue_tracker@your.tracker.email.domain.example
101 Cc: richard@test
102 Message-Id: <dummy_test_message_id>
103 Subject: [issue] Testing...
105 This is a test submission of a new issue.
106 ''')
107 handler = self.instance.MailGW(self.instance, self.db)
108 handler.trapExceptions = 0
109 nodeid = handler.main(message)
110 if os.path.exists(os.environ['SENDMAILDEBUG']):
111 error = open(os.environ['SENDMAILDEBUG']).read()
112 self.assertEqual('no error', error)
113 l = self.db.issue.get(nodeid, 'nosy')
114 l.sort()
115 self.assertEqual(l, ['3', '4'])
116 return nodeid
118 def testNewIssue(self):
119 self.doNewIssue()
121 def testNewIssueNosy(self):
122 self.instance.config.ADD_AUTHOR_TO_NOSY = 'yes'
123 message = cStringIO.StringIO('''Content-Type: text/plain;
124 charset="iso-8859-1"
125 From: Chef <chef@bork.bork.bork>
126 To: issue_tracker@your.tracker.email.domain.example
127 Cc: richard@test
128 Message-Id: <dummy_test_message_id>
129 Subject: [issue] Testing...
131 This is a test submission of a new issue.
132 ''')
133 handler = self.instance.MailGW(self.instance, self.db)
134 handler.trapExceptions = 0
135 nodeid = handler.main(message)
136 if os.path.exists(os.environ['SENDMAILDEBUG']):
137 error = open(os.environ['SENDMAILDEBUG']).read()
138 self.assertEqual('no error', error)
139 l = self.db.issue.get(nodeid, 'nosy')
140 l.sort()
141 self.assertEqual(l, ['3', '4'])
143 def testAlternateAddress(self):
144 message = cStringIO.StringIO('''Content-Type: text/plain;
145 charset="iso-8859-1"
146 From: John Doe <john.doe@test>
147 To: issue_tracker@your.tracker.email.domain.example
148 Message-Id: <dummy_test_message_id>
149 Subject: [issue] Testing...
151 This is a test submission of a new issue.
152 ''')
153 userlist = self.db.user.list()
154 handler = self.instance.MailGW(self.instance, self.db)
155 handler.trapExceptions = 0
156 handler.main(message)
157 if os.path.exists(os.environ['SENDMAILDEBUG']):
158 error = open(os.environ['SENDMAILDEBUG']).read()
159 self.assertEqual('no error', error)
160 self.assertEqual(userlist, self.db.user.list(),
161 "user created when it shouldn't have been")
163 def testNewIssueNoClass(self):
164 message = cStringIO.StringIO('''Content-Type: text/plain;
165 charset="iso-8859-1"
166 From: Chef <chef@bork.bork.bork>
167 To: issue_tracker@your.tracker.email.domain.example
168 Cc: richard@test
169 Message-Id: <dummy_test_message_id>
170 Subject: Testing...
172 This is a test submission of a new issue.
173 ''')
174 handler = self.instance.MailGW(self.instance, self.db)
175 handler.trapExceptions = 0
176 handler.main(message)
177 if os.path.exists(os.environ['SENDMAILDEBUG']):
178 error = open(os.environ['SENDMAILDEBUG']).read()
179 self.assertEqual('no error', error)
181 def testNewIssueAuthMsg(self):
182 message = cStringIO.StringIO('''Content-Type: text/plain;
183 charset="iso-8859-1"
184 From: Chef <chef@bork.bork.bork>
185 To: issue_tracker@your.tracker.email.domain.example
186 Message-Id: <dummy_test_message_id>
187 Subject: [issue] Testing... [nosy=mary; assignedto=richard]
189 This is a test submission of a new issue.
190 ''')
191 handler = self.instance.MailGW(self.instance, self.db)
192 handler.trapExceptions = 0
193 # TODO: fix the damn config - this is apalling
194 self.db.config.MESSAGES_TO_AUTHOR = 'yes'
195 handler.main(message)
197 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
198 '''FROM: roundup-admin@your.tracker.email.domain.example
199 TO: chef@bork.bork.bork, mary@test, richard@test
200 Content-Type: text/plain; charset=utf-8
201 Subject: [issue1] Testing...
202 To: chef@bork.bork.bork, mary@test, richard@test
203 From: "Bork, Chef" <issue_tracker@your.tracker.email.domain.example>
204 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
205 MIME-Version: 1.0
206 Message-Id: <dummy_test_message_id>
207 X-Roundup-Name: Roundup issue tracker
208 X-Roundup-Loop: hello
209 Content-Transfer-Encoding: quoted-printable
212 New submission from Bork, Chef <chef@bork.bork.bork>:
214 This is a test submission of a new issue.
217 ----------
218 assignedto: richard
219 messages: 1
220 nosy: Chef, mary, richard
221 status: unread
222 title: Testing...
223 _______________________________________________________________________
224 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
225 http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1
226 _______________________________________________________________________
227 ''')
229 # BUG
230 # def testMultipart(self):
231 # '''With more than one part'''
232 # see MultipartEnc tests: but if there is more than one part
233 # we return a multipart/mixed and the boundary contains
234 # the ip address of the test machine.
236 # BUG should test some binary attamchent too.
238 def testSimpleFollowup(self):
239 self.doNewIssue()
240 message = cStringIO.StringIO('''Content-Type: text/plain;
241 charset="iso-8859-1"
242 From: mary <mary@test>
243 To: issue_tracker@your.tracker.email.domain.example
244 Message-Id: <followup_dummy_id>
245 In-Reply-To: <dummy_test_message_id>
246 Subject: [issue1] Testing...
248 This is a second followup
249 ''')
250 handler = self.instance.MailGW(self.instance, self.db)
251 handler.trapExceptions = 0
252 handler.main(message)
253 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
254 '''FROM: roundup-admin@your.tracker.email.domain.example
255 TO: chef@bork.bork.bork, richard@test
256 Content-Type: text/plain; charset=utf-8
257 Subject: [issue1] Testing...
258 To: chef@bork.bork.bork, richard@test
259 From: "Contrary, Mary" <issue_tracker@your.tracker.email.domain.example>
260 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
261 MIME-Version: 1.0
262 Message-Id: <followup_dummy_id>
263 In-Reply-To: <dummy_test_message_id>
264 X-Roundup-Name: Roundup issue tracker
265 X-Roundup-Loop: hello
266 Content-Transfer-Encoding: quoted-printable
269 Contrary, Mary <mary@test> added the comment:
271 This is a second followup
274 ----------
275 status: unread -> chatting
276 _______________________________________________________________________
277 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
278 http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1
279 _______________________________________________________________________
280 ''')
282 def testFollowup(self):
283 self.doNewIssue()
285 message = cStringIO.StringIO('''Content-Type: text/plain;
286 charset="iso-8859-1"
287 From: richard <richard@test>
288 To: issue_tracker@your.tracker.email.domain.example
289 Message-Id: <followup_dummy_id>
290 In-Reply-To: <dummy_test_message_id>
291 Subject: [issue1] Testing... [assignedto=mary; nosy=+john]
293 This is a followup
294 ''')
295 handler = self.instance.MailGW(self.instance, self.db)
296 handler.trapExceptions = 0
297 handler.main(message)
298 l = self.db.issue.get('1', 'nosy')
299 l.sort()
300 self.assertEqual(l, ['3', '4', '5', '6'])
302 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
303 '''FROM: roundup-admin@your.tracker.email.domain.example
304 TO: chef@bork.bork.bork, john@test, mary@test
305 Content-Type: text/plain; charset=utf-8
306 Subject: [issue1] Testing...
307 To: chef@bork.bork.bork, john@test, mary@test
308 From: richard <issue_tracker@your.tracker.email.domain.example>
309 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
310 MIME-Version: 1.0
311 Message-Id: <followup_dummy_id>
312 In-Reply-To: <dummy_test_message_id>
313 X-Roundup-Name: Roundup issue tracker
314 X-Roundup-Loop: hello
315 Content-Transfer-Encoding: quoted-printable
318 richard <richard@test> added the comment:
320 This is a followup
323 ----------
324 assignedto: -> mary
325 nosy: +john, mary
326 status: unread -> chatting
327 _______________________________________________________________________
328 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
329 http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1
330 _______________________________________________________________________
331 ''')
333 def testFollowupTitleMatch(self):
334 self.doNewIssue()
335 message = cStringIO.StringIO('''Content-Type: text/plain;
336 charset="iso-8859-1"
337 From: richard <richard@test>
338 To: issue_tracker@your.tracker.email.domain.example
339 Message-Id: <followup_dummy_id>
340 In-Reply-To: <dummy_test_message_id>
341 Subject: Re: Testing... [assignedto=mary; nosy=+john]
343 This is a followup
344 ''')
345 handler = self.instance.MailGW(self.instance, self.db)
346 handler.trapExceptions = 0
347 handler.main(message)
349 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
350 '''FROM: roundup-admin@your.tracker.email.domain.example
351 TO: chef@bork.bork.bork, john@test, mary@test
352 Content-Type: text/plain; charset=utf-8
353 Subject: [issue1] Testing...
354 To: chef@bork.bork.bork, john@test, mary@test
355 From: richard <issue_tracker@your.tracker.email.domain.example>
356 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
357 MIME-Version: 1.0
358 Message-Id: <followup_dummy_id>
359 In-Reply-To: <dummy_test_message_id>
360 X-Roundup-Name: Roundup issue tracker
361 X-Roundup-Loop: hello
362 Content-Transfer-Encoding: quoted-printable
365 richard <richard@test> added the comment:
367 This is a followup
370 ----------
371 assignedto: -> mary
372 nosy: +john, mary
373 status: unread -> chatting
374 _______________________________________________________________________
375 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
376 http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1
377 _______________________________________________________________________
378 ''')
380 def testFollowupNosyAuthor(self):
381 self.doNewIssue()
382 self.db.config.ADD_AUTHOR_TO_NOSY = 'yes'
383 message = cStringIO.StringIO('''Content-Type: text/plain;
384 charset="iso-8859-1"
385 From: john@test
386 To: issue_tracker@your.tracker.email.domain.example
387 Message-Id: <followup_dummy_id>
388 In-Reply-To: <dummy_test_message_id>
389 Subject: [issue1] Testing...
391 This is a followup
392 ''')
393 handler = self.instance.MailGW(self.instance, self.db)
394 handler.trapExceptions = 0
395 handler.main(message)
397 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
398 '''FROM: roundup-admin@your.tracker.email.domain.example
399 TO: chef@bork.bork.bork, richard@test
400 Content-Type: text/plain; charset=utf-8
401 Subject: [issue1] Testing...
402 To: chef@bork.bork.bork, richard@test
403 From: John Doe <issue_tracker@your.tracker.email.domain.example>
404 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
405 MIME-Version: 1.0
406 Message-Id: <followup_dummy_id>
407 In-Reply-To: <dummy_test_message_id>
408 X-Roundup-Name: Roundup issue tracker
409 X-Roundup-Loop: hello
410 Content-Transfer-Encoding: quoted-printable
413 John Doe <john@test> added the comment:
415 This is a followup
418 ----------
419 nosy: +john
420 status: unread -> chatting
421 _______________________________________________________________________
422 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
423 http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1
424 _______________________________________________________________________
426 ''')
428 def testFollowupNosyRecipients(self):
429 self.doNewIssue()
430 self.db.config.ADD_RECIPIENTS_TO_NOSY = 'yes'
431 message = cStringIO.StringIO('''Content-Type: text/plain;
432 charset="iso-8859-1"
433 From: richard@test
434 To: issue_tracker@your.tracker.email.domain.example
435 Cc: john@test
436 Message-Id: <followup_dummy_id>
437 In-Reply-To: <dummy_test_message_id>
438 Subject: [issue1] Testing...
440 This is a followup
441 ''')
442 handler = self.instance.MailGW(self.instance, self.db)
443 handler.trapExceptions = 0
444 handler.main(message)
446 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
447 '''FROM: roundup-admin@your.tracker.email.domain.example
448 TO: chef@bork.bork.bork
449 Content-Type: text/plain; charset=utf-8
450 Subject: [issue1] Testing...
451 To: chef@bork.bork.bork
452 From: richard <issue_tracker@your.tracker.email.domain.example>
453 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
454 MIME-Version: 1.0
455 Message-Id: <followup_dummy_id>
456 In-Reply-To: <dummy_test_message_id>
457 X-Roundup-Name: Roundup issue tracker
458 X-Roundup-Loop: hello
459 Content-Transfer-Encoding: quoted-printable
462 richard <richard@test> added the comment:
464 This is a followup
467 ----------
468 nosy: +john
469 status: unread -> chatting
470 _______________________________________________________________________
471 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
472 http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1
473 _______________________________________________________________________
475 ''')
477 def testFollowupNosyAuthorAndCopy(self):
478 self.doNewIssue()
479 self.db.config.ADD_AUTHOR_TO_NOSY = 'yes'
480 self.db.config.MESSAGES_TO_AUTHOR = 'yes'
481 message = cStringIO.StringIO('''Content-Type: text/plain;
482 charset="iso-8859-1"
483 From: john@test
484 To: issue_tracker@your.tracker.email.domain.example
485 Message-Id: <followup_dummy_id>
486 In-Reply-To: <dummy_test_message_id>
487 Subject: [issue1] Testing...
489 This is a followup
490 ''')
491 handler = self.instance.MailGW(self.instance, self.db)
492 handler.trapExceptions = 0
493 handler.main(message)
495 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
496 '''FROM: roundup-admin@your.tracker.email.domain.example
497 TO: chef@bork.bork.bork, john@test, richard@test
498 Content-Type: text/plain; charset=utf-8
499 Subject: [issue1] Testing...
500 To: chef@bork.bork.bork, john@test, richard@test
501 From: John Doe <issue_tracker@your.tracker.email.domain.example>
502 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
503 MIME-Version: 1.0
504 Message-Id: <followup_dummy_id>
505 In-Reply-To: <dummy_test_message_id>
506 X-Roundup-Name: Roundup issue tracker
507 X-Roundup-Loop: hello
508 Content-Transfer-Encoding: quoted-printable
511 John Doe <john@test> added the comment:
513 This is a followup
516 ----------
517 nosy: +john
518 status: unread -> chatting
519 _______________________________________________________________________
520 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
521 http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1
522 _______________________________________________________________________
524 ''')
526 def testFollowupNoNosyAuthor(self):
527 self.doNewIssue()
528 self.instance.config.ADD_AUTHOR_TO_NOSY = 'no'
529 message = cStringIO.StringIO('''Content-Type: text/plain;
530 charset="iso-8859-1"
531 From: john@test
532 To: issue_tracker@your.tracker.email.domain.example
533 Message-Id: <followup_dummy_id>
534 In-Reply-To: <dummy_test_message_id>
535 Subject: [issue1] Testing...
537 This is a followup
538 ''')
539 handler = self.instance.MailGW(self.instance, self.db)
540 handler.trapExceptions = 0
541 handler.main(message)
543 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
544 '''FROM: roundup-admin@your.tracker.email.domain.example
545 TO: chef@bork.bork.bork, richard@test
546 Content-Type: text/plain; charset=utf-8
547 Subject: [issue1] Testing...
548 To: chef@bork.bork.bork, richard@test
549 From: John Doe <issue_tracker@your.tracker.email.domain.example>
550 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
551 MIME-Version: 1.0
552 Message-Id: <followup_dummy_id>
553 In-Reply-To: <dummy_test_message_id>
554 X-Roundup-Name: Roundup issue tracker
555 X-Roundup-Loop: hello
556 Content-Transfer-Encoding: quoted-printable
559 John Doe <john@test> added the comment:
561 This is a followup
564 ----------
565 status: unread -> chatting
566 _______________________________________________________________________
567 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
568 http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1
569 _______________________________________________________________________
571 ''')
573 def testFollowupNoNosyRecipients(self):
574 self.doNewIssue()
575 self.instance.config.ADD_RECIPIENTS_TO_NOSY = 'no'
576 message = cStringIO.StringIO('''Content-Type: text/plain;
577 charset="iso-8859-1"
578 From: richard@test
579 To: issue_tracker@your.tracker.email.domain.example
580 Cc: john@test
581 Message-Id: <followup_dummy_id>
582 In-Reply-To: <dummy_test_message_id>
583 Subject: [issue1] Testing...
585 This is a followup
586 ''')
587 handler = self.instance.MailGW(self.instance, self.db)
588 handler.trapExceptions = 0
589 handler.main(message)
591 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
592 '''FROM: roundup-admin@your.tracker.email.domain.example
593 TO: chef@bork.bork.bork
594 Content-Type: text/plain; charset=utf-8
595 Subject: [issue1] Testing...
596 To: chef@bork.bork.bork
597 From: richard <issue_tracker@your.tracker.email.domain.example>
598 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
599 MIME-Version: 1.0
600 Message-Id: <followup_dummy_id>
601 In-Reply-To: <dummy_test_message_id>
602 X-Roundup-Name: Roundup issue tracker
603 X-Roundup-Loop: hello
604 Content-Transfer-Encoding: quoted-printable
607 richard <richard@test> added the comment:
609 This is a followup
612 ----------
613 status: unread -> chatting
614 _______________________________________________________________________
615 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
616 http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1
617 _______________________________________________________________________
619 ''')
621 def testNosyRemove(self):
622 self.doNewIssue()
624 message = cStringIO.StringIO('''Content-Type: text/plain;
625 charset="iso-8859-1"
626 From: richard <richard@test>
627 To: issue_tracker@your.tracker.email.domain.example
628 Message-Id: <followup_dummy_id>
629 In-Reply-To: <dummy_test_message_id>
630 Subject: [issue1] Testing... [nosy=-richard]
632 ''')
633 handler = self.instance.MailGW(self.instance, self.db)
634 handler.trapExceptions = 0
635 handler.main(message)
636 l = self.db.issue.get('1', 'nosy')
637 l.sort()
638 self.assertEqual(l, ['3'])
640 # NO NOSY MESSAGE SHOULD BE SENT!
641 self.assert_(not os.path.exists(os.environ['SENDMAILDEBUG']))
643 def testNewUserAuthor(self):
644 # first without the permission
645 # heh... just ignore the API for a second ;)
646 self.db.security.role['Anonymous'].permissions=[]
647 anonid = self.db.user.lookup('anonymous')
648 self.db.user.set(anonid, roles='Anonymous')
650 self.db.security.hasPermission('Email Registration', anonid)
651 l = self.db.user.list()
652 l.sort()
653 s = '''Content-Type: text/plain;
654 charset="iso-8859-1"
655 From: fubar <fubar@bork.bork.bork>
656 To: issue_tracker@your.tracker.email.domain.example
657 Message-Id: <dummy_test_message_id>
658 Subject: [issue] Testing...
660 This is a test submission of a new issue.
661 '''
662 message = cStringIO.StringIO(s)
663 handler = self.instance.MailGW(self.instance, self.db)
664 handler.trapExceptions = 0
665 self.assertRaises(Unauthorized, handler.main, message)
666 m = self.db.user.list()
667 m.sort()
668 self.assertEqual(l, m)
670 # now with the permission
671 p = self.db.security.getPermission('Email Registration')
672 self.db.security.role['Anonymous'].permissions=[p]
673 handler = self.instance.MailGW(self.instance, self.db)
674 handler.trapExceptions = 0
675 message = cStringIO.StringIO(s)
676 handler.main(message)
677 m = self.db.user.list()
678 m.sort()
679 self.assertNotEqual(l, m)
681 def testEnc01(self):
682 self.doNewIssue()
683 message = cStringIO.StringIO('''Content-Type: text/plain;
684 charset="iso-8859-1"
685 From: mary <mary@test>
686 To: issue_tracker@your.tracker.email.domain.example
687 Message-Id: <followup_dummy_id>
688 In-Reply-To: <dummy_test_message_id>
689 Subject: [issue1] Testing...
690 Content-Type: text/plain;
691 charset="iso-8859-1"
692 Content-Transfer-Encoding: quoted-printable
694 A message with encoding (encoded oe =F6)
696 ''')
697 handler = self.instance.MailGW(self.instance, self.db)
698 handler.trapExceptions = 0
699 handler.main(message)
700 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
701 '''FROM: roundup-admin@your.tracker.email.domain.example
702 TO: chef@bork.bork.bork, richard@test
703 Content-Type: text/plain; charset=utf-8
704 Subject: [issue1] Testing...
705 To: chef@bork.bork.bork, richard@test
706 From: "Contrary, Mary" <issue_tracker@your.tracker.email.domain.example>
707 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
708 MIME-Version: 1.0
709 Message-Id: <followup_dummy_id>
710 In-Reply-To: <dummy_test_message_id>
711 X-Roundup-Name: Roundup issue tracker
712 X-Roundup-Loop: hello
713 Content-Transfer-Encoding: quoted-printable
716 Contrary, Mary <mary@test> added the comment:
718 A message with encoding (encoded oe =C3=B6)
720 ----------
721 status: unread -> chatting
722 _______________________________________________________________________
723 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
724 http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1
725 _______________________________________________________________________
726 ''')
729 def testMultipartEnc01(self):
730 self.doNewIssue()
731 message = cStringIO.StringIO('''Content-Type: text/plain;
732 charset="iso-8859-1"
733 From: mary <mary@test>
734 To: issue_tracker@your.tracker.email.domain.example
735 Message-Id: <followup_dummy_id>
736 In-Reply-To: <dummy_test_message_id>
737 Subject: [issue1] Testing...
738 Content-Type: multipart/mixed;
739 boundary="----_=_NextPart_000_01"
741 This message is in MIME format. Since your mail reader does not understand
742 this format, some or all of this message may not be legible.
744 ------_=_NextPart_000_01
745 Content-Type: text/plain;
746 charset="iso-8859-1"
747 Content-Transfer-Encoding: quoted-printable
749 A message with first part encoded (encoded oe =F6)
751 ''')
752 handler = self.instance.MailGW(self.instance, self.db)
753 handler.trapExceptions = 0
754 handler.main(message)
755 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
756 '''FROM: roundup-admin@your.tracker.email.domain.example
757 TO: chef@bork.bork.bork, richard@test
758 Content-Type: text/plain; charset=utf-8
759 Subject: [issue1] Testing...
760 To: chef@bork.bork.bork, richard@test
761 From: "Contrary, Mary" <issue_tracker@your.tracker.email.domain.example>
762 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
763 MIME-Version: 1.0
764 Message-Id: <followup_dummy_id>
765 In-Reply-To: <dummy_test_message_id>
766 X-Roundup-Name: Roundup issue tracker
767 X-Roundup-Loop: hello
768 Content-Transfer-Encoding: quoted-printable
771 Contrary, Mary <mary@test> added the comment:
773 A message with first part encoded (encoded oe =C3=B6)
775 ----------
776 status: unread -> chatting
777 _______________________________________________________________________
778 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
779 http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1
780 _______________________________________________________________________
781 ''')
783 def testContentDisposition(self):
784 self.doNewIssue()
785 message = cStringIO.StringIO('''Content-Type: text/plain;
786 charset="iso-8859-1"
787 From: mary <mary@test>
788 To: issue_tracker@your.tracker.email.domain.example
789 Message-Id: <followup_dummy_id>
790 In-Reply-To: <dummy_test_message_id>
791 Subject: [issue1] Testing...
792 Content-Type: multipart/mixed; boundary="bCsyhTFzCvuiizWE"
793 Content-Disposition: inline
796 --bCsyhTFzCvuiizWE
797 Content-Type: text/plain; charset=us-ascii
798 Content-Disposition: inline
800 test attachment binary
802 --bCsyhTFzCvuiizWE
803 Content-Type: application/octet-stream
804 Content-Disposition: attachment; filename="main.dvi"
806 xxxxxx
808 --bCsyhTFzCvuiizWE--
809 ''')
810 handler = self.instance.MailGW(self.instance, self.db)
811 handler.trapExceptions = 0
812 handler.main(message)
813 messages = self.db.issue.get('1', 'messages')
814 messages.sort()
815 file = self.db.msg.get(messages[-1], 'files')[0]
816 self.assertEqual(self.db.file.get(file, 'name'), 'main.dvi')
818 def testFollowupStupidQuoting(self):
819 self.doNewIssue()
821 message = cStringIO.StringIO('''Content-Type: text/plain;
822 charset="iso-8859-1"
823 From: richard <richard@test>
824 To: issue_tracker@your.tracker.email.domain.example
825 Message-Id: <followup_dummy_id>
826 In-Reply-To: <dummy_test_message_id>
827 Subject: Re: "[issue1] Testing... "
829 This is a followup
830 ''')
831 handler = self.instance.MailGW(self.instance, self.db)
832 handler.trapExceptions = 0
833 handler.main(message)
835 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
836 '''FROM: roundup-admin@your.tracker.email.domain.example
837 TO: chef@bork.bork.bork
838 Content-Type: text/plain; charset=utf-8
839 Subject: [issue1] Testing...
840 To: chef@bork.bork.bork
841 From: richard <issue_tracker@your.tracker.email.domain.example>
842 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
843 MIME-Version: 1.0
844 Message-Id: <followup_dummy_id>
845 In-Reply-To: <dummy_test_message_id>
846 X-Roundup-Name: Roundup issue tracker
847 X-Roundup-Loop: hello
848 Content-Transfer-Encoding: quoted-printable
851 richard <richard@test> added the comment:
853 This is a followup
856 ----------
857 status: unread -> chatting
858 _______________________________________________________________________
859 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
860 http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1
861 _______________________________________________________________________
862 ''')
864 def testEmailQuoting(self):
865 self.instance.config.EMAIL_KEEP_QUOTED_TEXT = 'no'
866 self.innerTestQuoting('''This is a followup
867 ''')
869 def testEmailQuotingRemove(self):
870 self.instance.config.EMAIL_KEEP_QUOTED_TEXT = 'yes'
871 self.innerTestQuoting('''Blah blah wrote:
872 > Blah bklaskdfj sdf asdf jlaskdf skj sdkfjl asdf
873 > skdjlkjsdfalsdkfjasdlfkj dlfksdfalksd fj
874 >
876 This is a followup
877 ''')
879 def innerTestQuoting(self, expect):
880 nodeid = self.doNewIssue()
882 messages = self.db.issue.get(nodeid, 'messages')
884 message = cStringIO.StringIO('''Content-Type: text/plain;
885 charset="iso-8859-1"
886 From: richard <richard@test>
887 To: issue_tracker@your.tracker.email.domain.example
888 Message-Id: <followup_dummy_id>
889 In-Reply-To: <dummy_test_message_id>
890 Subject: Re: [issue1] Testing...
892 Blah blah wrote:
893 > Blah bklaskdfj sdf asdf jlaskdf skj sdkfjl asdf
894 > skdjlkjsdfalsdkfjasdlfkj dlfksdfalksd fj
895 >
897 This is a followup
898 ''')
899 handler = self.instance.MailGW(self.instance, self.db)
900 handler.trapExceptions = 0
901 handler.main(message)
903 # figure the new message id
904 newmessages = self.db.issue.get(nodeid, 'messages')
905 for msg in messages:
906 newmessages.remove(msg)
907 messageid = newmessages[0]
909 self.compareStrings(self.db.msg.get(messageid, 'content'), expect)
911 def suite():
912 l = [unittest.makeSuite(MailgwTestCase),
913 ]
914 return unittest.TestSuite(l)
917 # vim: set filetype=python ts=4 sw=4 et si