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.32 2002-09-26 03:04:24 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 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')
89 self.db.user.create(username='john', address='john@test',
90 alternate_addresses='jondoe@test\njohn.doe@test', roles='User')
92 def tearDown(self):
93 if os.path.exists(os.environ['SENDMAILDEBUG']):
94 os.remove(os.environ['SENDMAILDEBUG'])
95 self.db.close()
96 try:
97 shutil.rmtree(self.dirname)
98 except OSError, error:
99 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
101 def doNewIssue(self):
102 message = cStringIO.StringIO('''Content-Type: text/plain;
103 charset="iso-8859-1"
104 From: Chef <chef@bork.bork.bork>
105 To: issue_tracker@your.tracker.email.domain.example
106 Cc: richard@test
107 Message-Id: <dummy_test_message_id>
108 Subject: [issue] Testing...
110 This is a test submission of a new issue.
111 ''')
112 handler = self.instance.MailGW(self.instance, self.db)
113 handler.trapExceptions = 0
114 nodeid = handler.main(message)
115 if os.path.exists(os.environ['SENDMAILDEBUG']):
116 error = open(os.environ['SENDMAILDEBUG']).read()
117 self.assertEqual('no error', error)
118 l = self.db.issue.get(nodeid, 'nosy')
119 l.sort()
120 self.assertEqual(l, ['3', '4'])
122 def testNewIssue(self):
123 self.doNewIssue()
125 def testNewIssueNosy(self):
126 self.instance.config.ADD_AUTHOR_TO_NOSY = 'yes'
127 message = cStringIO.StringIO('''Content-Type: text/plain;
128 charset="iso-8859-1"
129 From: Chef <chef@bork.bork.bork>
130 To: issue_tracker@your.tracker.email.domain.example
131 Cc: richard@test
132 Message-Id: <dummy_test_message_id>
133 Subject: [issue] Testing...
135 This is a test submission of a new issue.
136 ''')
137 handler = self.instance.MailGW(self.instance, self.db)
138 handler.trapExceptions = 0
139 nodeid = handler.main(message)
140 if os.path.exists(os.environ['SENDMAILDEBUG']):
141 error = open(os.environ['SENDMAILDEBUG']).read()
142 self.assertEqual('no error', error)
143 l = self.db.issue.get(nodeid, 'nosy')
144 l.sort()
145 self.assertEqual(l, ['3', '4'])
147 def testAlternateAddress(self):
148 message = cStringIO.StringIO('''Content-Type: text/plain;
149 charset="iso-8859-1"
150 From: John Doe <john.doe@test>
151 To: issue_tracker@your.tracker.email.domain.example
152 Message-Id: <dummy_test_message_id>
153 Subject: [issue] Testing...
155 This is a test submission of a new issue.
156 ''')
157 userlist = self.db.user.list()
158 handler = self.instance.MailGW(self.instance, self.db)
159 handler.trapExceptions = 0
160 handler.main(message)
161 if os.path.exists(os.environ['SENDMAILDEBUG']):
162 error = open(os.environ['SENDMAILDEBUG']).read()
163 self.assertEqual('no error', error)
164 self.assertEqual(userlist, self.db.user.list(),
165 "user created when it shouldn't have been")
167 def testNewIssueNoClass(self):
168 message = cStringIO.StringIO('''Content-Type: text/plain;
169 charset="iso-8859-1"
170 From: Chef <chef@bork.bork.bork>
171 To: issue_tracker@your.tracker.email.domain.example
172 Cc: richard@test
173 Message-Id: <dummy_test_message_id>
174 Subject: Testing...
176 This is a test submission of a new issue.
177 ''')
178 handler = self.instance.MailGW(self.instance, self.db)
179 handler.trapExceptions = 0
180 handler.main(message)
181 if os.path.exists(os.environ['SENDMAILDEBUG']):
182 error = open(os.environ['SENDMAILDEBUG']).read()
183 self.assertEqual('no error', error)
185 def testNewIssueAuthMsg(self):
186 message = cStringIO.StringIO('''Content-Type: text/plain;
187 charset="iso-8859-1"
188 From: Chef <chef@bork.bork.bork>
189 To: issue_tracker@your.tracker.email.domain.example
190 Message-Id: <dummy_test_message_id>
191 Subject: [issue] Testing... [nosy=mary; assignedto=richard]
193 This is a test submission of a new issue.
194 ''')
195 handler = self.instance.MailGW(self.instance, self.db)
196 handler.trapExceptions = 0
197 # TODO: fix the damn config - this is apalling
198 self.db.config.MESSAGES_TO_AUTHOR = 'yes'
199 handler.main(message)
201 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
202 '''FROM: roundup-admin@your.tracker.email.domain.example
203 TO: chef@bork.bork.bork, mary@test, richard@test
204 Content-Type: text/plain
205 Subject: [issue1] Testing...
206 To: chef@bork.bork.bork, mary@test, richard@test
207 From: "Chef" <issue_tracker@your.tracker.email.domain.example>
208 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
209 MIME-Version: 1.0
210 Message-Id: <dummy_test_message_id>
211 X-Roundup-Name: Roundup issue tracker
212 Content-Transfer-Encoding: quoted-printable
215 New submission from Chef <chef@bork.bork.bork>:
217 This is a test submission of a new issue.
220 ----------
221 assignedto: richard
222 messages: 1
223 nosy: Chef, mary, richard
224 status: unread
225 title: Testing...
226 _________________________________________________________________________
227 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
228 http://your.tracker.url.example/issue1
229 _________________________________________________________________________
230 ''')
232 # BUG
233 # def testMultipart(self):
234 # '''With more than one part'''
235 # see MultipartEnc tests: but if there is more than one part
236 # we return a multipart/mixed and the boundary contains
237 # the ip address of the test machine.
239 # BUG should test some binary attamchent too.
241 def testSimpleFollowup(self):
242 self.doNewIssue()
243 message = cStringIO.StringIO('''Content-Type: text/plain;
244 charset="iso-8859-1"
245 From: mary <mary@test>
246 To: issue_tracker@your.tracker.email.domain.example
247 Message-Id: <followup_dummy_id>
248 In-Reply-To: <dummy_test_message_id>
249 Subject: [issue1] Testing...
251 This is a second followup
252 ''')
253 handler = self.instance.MailGW(self.instance, self.db)
254 handler.trapExceptions = 0
255 handler.main(message)
256 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
257 '''FROM: roundup-admin@your.tracker.email.domain.example
258 TO: chef@bork.bork.bork, richard@test
259 Content-Type: text/plain
260 Subject: [issue1] Testing...
261 To: chef@bork.bork.bork, richard@test
262 From: "mary" <issue_tracker@your.tracker.email.domain.example>
263 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
264 MIME-Version: 1.0
265 Message-Id: <followup_dummy_id>
266 In-Reply-To: <dummy_test_message_id>
267 X-Roundup-Name: Roundup issue tracker
268 Content-Transfer-Encoding: quoted-printable
271 mary <mary@test> added the comment:
273 This is a second followup
276 ----------
277 status: unread -> chatting
278 _________________________________________________________________________
279 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
280 http://your.tracker.url.example/issue1
281 _________________________________________________________________________
282 ''')
284 def testFollowup(self):
285 self.doNewIssue()
287 message = cStringIO.StringIO('''Content-Type: text/plain;
288 charset="iso-8859-1"
289 From: richard <richard@test>
290 To: issue_tracker@your.tracker.email.domain.example
291 Message-Id: <followup_dummy_id>
292 In-Reply-To: <dummy_test_message_id>
293 Subject: [issue1] Testing... [assignedto=mary; nosy=+john]
295 This is a followup
296 ''')
297 handler = self.instance.MailGW(self.instance, self.db)
298 handler.trapExceptions = 0
299 handler.main(message)
300 l = self.db.issue.get('1', 'nosy')
301 l.sort()
302 self.assertEqual(l, ['3', '4', '5', '6'])
304 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
305 '''FROM: roundup-admin@your.tracker.email.domain.example
306 TO: chef@bork.bork.bork, john@test, mary@test
307 Content-Type: text/plain
308 Subject: [issue1] Testing...
309 To: chef@bork.bork.bork, john@test, mary@test
310 From: "richard" <issue_tracker@your.tracker.email.domain.example>
311 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
312 MIME-Version: 1.0
313 Message-Id: <followup_dummy_id>
314 In-Reply-To: <dummy_test_message_id>
315 X-Roundup-Name: Roundup issue tracker
316 Content-Transfer-Encoding: quoted-printable
319 richard <richard@test> added the comment:
321 This is a followup
324 ----------
325 assignedto: -> mary
326 nosy: +john, mary
327 status: unread -> chatting
328 _________________________________________________________________________
329 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
330 http://your.tracker.url.example/issue1
331 _________________________________________________________________________
332 ''')
334 def testFollowupTitleMatch(self):
335 self.doNewIssue()
336 message = cStringIO.StringIO('''Content-Type: text/plain;
337 charset="iso-8859-1"
338 From: richard <richard@test>
339 To: issue_tracker@your.tracker.email.domain.example
340 Message-Id: <followup_dummy_id>
341 In-Reply-To: <dummy_test_message_id>
342 Subject: Re: Testing... [assignedto=mary; nosy=+john]
344 This is a followup
345 ''')
346 handler = self.instance.MailGW(self.instance, self.db)
347 handler.trapExceptions = 0
348 handler.main(message)
350 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
351 '''FROM: roundup-admin@your.tracker.email.domain.example
352 TO: chef@bork.bork.bork, john@test, mary@test
353 Content-Type: text/plain
354 Subject: [issue1] Testing...
355 To: chef@bork.bork.bork, john@test, mary@test
356 From: "richard" <issue_tracker@your.tracker.email.domain.example>
357 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
358 MIME-Version: 1.0
359 Message-Id: <followup_dummy_id>
360 In-Reply-To: <dummy_test_message_id>
361 X-Roundup-Name: Roundup issue tracker
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://your.tracker.url.example/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
401 Subject: [issue1] Testing...
402 To: chef@bork.bork.bork, richard@test
403 From: "john" <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 Content-Transfer-Encoding: quoted-printable
412 john <john@test> added the comment:
414 This is a followup
417 ----------
418 nosy: +john
419 status: unread -> chatting
420 _________________________________________________________________________
421 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
422 http://your.tracker.url.example/issue1
423 _________________________________________________________________________
425 ''')
427 def testFollowupNosyRecipients(self):
428 self.doNewIssue()
429 self.db.config.ADD_RECIPIENTS_TO_NOSY = 'yes'
430 message = cStringIO.StringIO('''Content-Type: text/plain;
431 charset="iso-8859-1"
432 From: richard@test
433 To: issue_tracker@your.tracker.email.domain.example
434 Cc: john@test
435 Message-Id: <followup_dummy_id>
436 In-Reply-To: <dummy_test_message_id>
437 Subject: [issue1] Testing...
439 This is a followup
440 ''')
441 handler = self.instance.MailGW(self.instance, self.db)
442 handler.trapExceptions = 0
443 handler.main(message)
445 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
446 '''FROM: roundup-admin@your.tracker.email.domain.example
447 TO: chef@bork.bork.bork
448 Content-Type: text/plain
449 Subject: [issue1] Testing...
450 To: chef@bork.bork.bork
451 From: "richard" <issue_tracker@your.tracker.email.domain.example>
452 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
453 MIME-Version: 1.0
454 Message-Id: <followup_dummy_id>
455 In-Reply-To: <dummy_test_message_id>
456 X-Roundup-Name: Roundup issue tracker
457 Content-Transfer-Encoding: quoted-printable
460 richard <richard@test> added the comment:
462 This is a followup
465 ----------
466 nosy: +john
467 status: unread -> chatting
468 _________________________________________________________________________
469 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
470 http://your.tracker.url.example/issue1
471 _________________________________________________________________________
473 ''')
475 def testFollowupNosyAuthorAndCopy(self):
476 self.doNewIssue()
477 self.db.config.ADD_AUTHOR_TO_NOSY = 'yes'
478 self.db.config.MESSAGES_TO_AUTHOR = 'yes'
479 message = cStringIO.StringIO('''Content-Type: text/plain;
480 charset="iso-8859-1"
481 From: john@test
482 To: issue_tracker@your.tracker.email.domain.example
483 Message-Id: <followup_dummy_id>
484 In-Reply-To: <dummy_test_message_id>
485 Subject: [issue1] Testing...
487 This is a followup
488 ''')
489 handler = self.instance.MailGW(self.instance, self.db)
490 handler.trapExceptions = 0
491 handler.main(message)
493 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
494 '''FROM: roundup-admin@your.tracker.email.domain.example
495 TO: chef@bork.bork.bork, john@test, richard@test
496 Content-Type: text/plain
497 Subject: [issue1] Testing...
498 To: chef@bork.bork.bork, john@test, richard@test
499 From: "john" <issue_tracker@your.tracker.email.domain.example>
500 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
501 MIME-Version: 1.0
502 Message-Id: <followup_dummy_id>
503 In-Reply-To: <dummy_test_message_id>
504 X-Roundup-Name: Roundup issue tracker
505 Content-Transfer-Encoding: quoted-printable
508 john <john@test> added the comment:
510 This is a followup
513 ----------
514 nosy: +john
515 status: unread -> chatting
516 _________________________________________________________________________
517 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
518 http://your.tracker.url.example/issue1
519 _________________________________________________________________________
521 ''')
523 def testFollowupNoNosyAuthor(self):
524 self.doNewIssue()
525 self.instance.config.ADD_AUTHOR_TO_NOSY = 'no'
526 message = cStringIO.StringIO('''Content-Type: text/plain;
527 charset="iso-8859-1"
528 From: john@test
529 To: issue_tracker@your.tracker.email.domain.example
530 Message-Id: <followup_dummy_id>
531 In-Reply-To: <dummy_test_message_id>
532 Subject: [issue1] Testing...
534 This is a followup
535 ''')
536 handler = self.instance.MailGW(self.instance, self.db)
537 handler.trapExceptions = 0
538 handler.main(message)
540 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
541 '''FROM: roundup-admin@your.tracker.email.domain.example
542 TO: chef@bork.bork.bork, richard@test
543 Content-Type: text/plain
544 Subject: [issue1] Testing...
545 To: chef@bork.bork.bork, richard@test
546 From: "john" <issue_tracker@your.tracker.email.domain.example>
547 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
548 MIME-Version: 1.0
549 Message-Id: <followup_dummy_id>
550 In-Reply-To: <dummy_test_message_id>
551 X-Roundup-Name: Roundup issue tracker
552 Content-Transfer-Encoding: quoted-printable
555 john <john@test> added the comment:
557 This is a followup
560 ----------
561 status: unread -> chatting
562 _________________________________________________________________________
563 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
564 http://your.tracker.url.example/issue1
565 _________________________________________________________________________
567 ''')
569 def testFollowupNoNosyRecipients(self):
570 self.doNewIssue()
571 self.instance.config.ADD_RECIPIENTS_TO_NOSY = 'no'
572 message = cStringIO.StringIO('''Content-Type: text/plain;
573 charset="iso-8859-1"
574 From: richard@test
575 To: issue_tracker@your.tracker.email.domain.example
576 Cc: john@test
577 Message-Id: <followup_dummy_id>
578 In-Reply-To: <dummy_test_message_id>
579 Subject: [issue1] Testing...
581 This is a followup
582 ''')
583 handler = self.instance.MailGW(self.instance, self.db)
584 handler.trapExceptions = 0
585 handler.main(message)
587 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
588 '''FROM: roundup-admin@your.tracker.email.domain.example
589 TO: chef@bork.bork.bork
590 Content-Type: text/plain
591 Subject: [issue1] Testing...
592 To: chef@bork.bork.bork
593 From: "richard" <issue_tracker@your.tracker.email.domain.example>
594 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
595 MIME-Version: 1.0
596 Message-Id: <followup_dummy_id>
597 In-Reply-To: <dummy_test_message_id>
598 X-Roundup-Name: Roundup issue tracker
599 Content-Transfer-Encoding: quoted-printable
602 richard <richard@test> added the comment:
604 This is a followup
607 ----------
608 status: unread -> chatting
609 _________________________________________________________________________
610 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
611 http://your.tracker.url.example/issue1
612 _________________________________________________________________________
614 ''')
616 def testNosyRemove(self):
617 self.doNewIssue()
619 message = cStringIO.StringIO('''Content-Type: text/plain;
620 charset="iso-8859-1"
621 From: richard <richard@test>
622 To: issue_tracker@your.tracker.email.domain.example
623 Message-Id: <followup_dummy_id>
624 In-Reply-To: <dummy_test_message_id>
625 Subject: [issue1] Testing... [nosy=-richard]
627 ''')
628 handler = self.instance.MailGW(self.instance, self.db)
629 handler.trapExceptions = 0
630 handler.main(message)
631 l = self.db.issue.get('1', 'nosy')
632 l.sort()
633 self.assertEqual(l, ['3'])
635 # NO NOSY MESSAGE SHOULD BE SENT!
636 self.assert_(not os.path.exists(os.environ['SENDMAILDEBUG']))
638 def testNewUserAuthor(self):
639 # first without the permission
640 # heh... just ignore the API for a second ;)
641 self.db.security.role['Anonymous'].permissions=[]
642 anonid = self.db.user.lookup('anonymous')
643 self.db.user.set(anonid, roles='Anonymous')
645 self.db.security.hasPermission('Email Registration', anonid)
646 l = self.db.user.list()
647 l.sort()
648 s = '''Content-Type: text/plain;
649 charset="iso-8859-1"
650 From: fubar <fubar@bork.bork.bork>
651 To: issue_tracker@your.tracker.email.domain.example
652 Message-Id: <dummy_test_message_id>
653 Subject: [issue] Testing...
655 This is a test submission of a new issue.
656 '''
657 message = cStringIO.StringIO(s)
658 handler = self.instance.MailGW(self.instance, self.db)
659 handler.trapExceptions = 0
660 self.assertRaises(Unauthorized, handler.main, message)
661 m = self.db.user.list()
662 m.sort()
663 self.assertEqual(l, m)
665 # now with the permission
666 p = self.db.security.getPermission('Email Registration')
667 self.db.security.role['Anonymous'].permissions=[p]
668 handler = self.instance.MailGW(self.instance, self.db)
669 handler.trapExceptions = 0
670 message = cStringIO.StringIO(s)
671 handler.main(message)
672 m = self.db.user.list()
673 m.sort()
674 self.assertNotEqual(l, m)
676 def testEnc01(self):
677 self.doNewIssue()
678 message = cStringIO.StringIO('''Content-Type: text/plain;
679 charset="iso-8859-1"
680 From: mary <mary@test>
681 To: issue_tracker@your.tracker.email.domain.example
682 Message-Id: <followup_dummy_id>
683 In-Reply-To: <dummy_test_message_id>
684 Subject: [issue1] Testing...
685 Content-Type: text/plain;
686 charset="iso-8859-1"
687 Content-Transfer-Encoding: quoted-printable
689 A message with encoding (encoded oe =F6)
691 ''')
692 handler = self.instance.MailGW(self.instance, self.db)
693 handler.trapExceptions = 0
694 handler.main(message)
695 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
696 '''FROM: roundup-admin@your.tracker.email.domain.example
697 TO: chef@bork.bork.bork, richard@test
698 Content-Type: text/plain
699 Subject: [issue1] Testing...
700 To: chef@bork.bork.bork, richard@test
701 From: "mary" <issue_tracker@your.tracker.email.domain.example>
702 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
703 MIME-Version: 1.0
704 Message-Id: <followup_dummy_id>
705 In-Reply-To: <dummy_test_message_id>
706 X-Roundup-Name: Roundup issue tracker
707 Content-Transfer-Encoding: quoted-printable
710 mary <mary@test> added the comment:
712 A message with encoding (encoded oe =F6)
714 ----------
715 status: unread -> chatting
716 _________________________________________________________________________
717 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
718 http://your.tracker.url.example/issue1
719 _________________________________________________________________________
720 ''')
723 def testMultipartEnc01(self):
724 self.doNewIssue()
725 message = cStringIO.StringIO('''Content-Type: text/plain;
726 charset="iso-8859-1"
727 From: mary <mary@test>
728 To: issue_tracker@your.tracker.email.domain.example
729 Message-Id: <followup_dummy_id>
730 In-Reply-To: <dummy_test_message_id>
731 Subject: [issue1] Testing...
732 Content-Type: multipart/mixed;
733 boundary="----_=_NextPart_000_01"
735 This message is in MIME format. Since your mail reader does not understand
736 this format, some or all of this message may not be legible.
738 ------_=_NextPart_000_01
739 Content-Type: text/plain;
740 charset="iso-8859-1"
741 Content-Transfer-Encoding: quoted-printable
743 A message with first part encoded (encoded oe =F6)
745 ''')
746 handler = self.instance.MailGW(self.instance, self.db)
747 handler.trapExceptions = 0
748 handler.main(message)
749 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
750 '''FROM: roundup-admin@your.tracker.email.domain.example
751 TO: chef@bork.bork.bork, richard@test
752 Content-Type: text/plain
753 Subject: [issue1] Testing...
754 To: chef@bork.bork.bork, richard@test
755 From: "mary" <issue_tracker@your.tracker.email.domain.example>
756 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
757 MIME-Version: 1.0
758 Message-Id: <followup_dummy_id>
759 In-Reply-To: <dummy_test_message_id>
760 X-Roundup-Name: Roundup issue tracker
761 Content-Transfer-Encoding: quoted-printable
764 mary <mary@test> added the comment:
766 A message with first part encoded (encoded oe =F6)
768 ----------
769 status: unread -> chatting
770 _________________________________________________________________________
771 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
772 http://your.tracker.url.example/issue1
773 _________________________________________________________________________
774 ''')
776 def testFollowupStupidQuoting(self):
777 self.doNewIssue()
779 message = cStringIO.StringIO('''Content-Type: text/plain;
780 charset="iso-8859-1"
781 From: richard <richard@test>
782 To: issue_tracker@your.tracker.email.domain.example
783 Message-Id: <followup_dummy_id>
784 In-Reply-To: <dummy_test_message_id>
785 Subject: Re: "[issue1] Testing... "
787 This is a followup
788 ''')
789 handler = self.instance.MailGW(self.instance, self.db)
790 handler.trapExceptions = 0
791 handler.main(message)
793 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
794 '''FROM: roundup-admin@your.tracker.email.domain.example
795 TO: chef@bork.bork.bork
796 Content-Type: text/plain
797 Subject: [issue1] Testing...
798 To: chef@bork.bork.bork
799 From: "richard" <issue_tracker@your.tracker.email.domain.example>
800 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
801 MIME-Version: 1.0
802 Message-Id: <followup_dummy_id>
803 In-Reply-To: <dummy_test_message_id>
804 X-Roundup-Name: Roundup issue tracker
805 Content-Transfer-Encoding: quoted-printable
808 richard <richard@test> added the comment:
810 This is a followup
813 ----------
814 status: unread -> chatting
815 _________________________________________________________________________
816 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
817 http://your.tracker.url.example/issue1
818 _________________________________________________________________________
819 ''')
821 def suite():
822 l = [unittest.makeSuite(MailgwTestCase),
823 ]
824 return unittest.TestSuite(l)
827 # vim: set filetype=python ts=4 sw=4 et si