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.29 2002-09-10 02:37:28 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('sekrit')
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 try:
96 shutil.rmtree(self.dirname)
97 except OSError, error:
98 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
100 def doNewIssue(self):
101 message = cStringIO.StringIO('''Content-Type: text/plain;
102 charset="iso-8859-1"
103 From: Chef <chef@bork.bork.bork>
104 To: issue_tracker@your.tracker.email.domain.example
105 Cc: richard@test
106 Message-Id: <dummy_test_message_id>
107 Subject: [issue] Testing...
109 This is a test submission of a new issue.
110 ''')
111 handler = self.instance.MailGW(self.instance, self.db)
112 handler.trapExceptions = 0
113 nodeid = handler.main(message)
114 if os.path.exists(os.environ['SENDMAILDEBUG']):
115 error = open(os.environ['SENDMAILDEBUG']).read()
116 self.assertEqual('no error', error)
117 l = self.db.issue.get(nodeid, 'nosy')
118 l.sort()
119 self.assertEqual(l, ['3', '4'])
121 def testNewIssue(self):
122 self.doNewIssue()
124 def testNewIssueNosy(self):
125 self.instance.config.ADD_AUTHOR_TO_NOSY = 'yes'
126 message = cStringIO.StringIO('''Content-Type: text/plain;
127 charset="iso-8859-1"
128 From: Chef <chef@bork.bork.bork>
129 To: issue_tracker@your.tracker.email.domain.example
130 Cc: richard@test
131 Message-Id: <dummy_test_message_id>
132 Subject: [issue] Testing...
134 This is a test submission of a new issue.
135 ''')
136 handler = self.instance.MailGW(self.instance, self.db)
137 handler.trapExceptions = 0
138 nodeid = handler.main(message)
139 if os.path.exists(os.environ['SENDMAILDEBUG']):
140 error = open(os.environ['SENDMAILDEBUG']).read()
141 self.assertEqual('no error', error)
142 l = self.db.issue.get(nodeid, 'nosy')
143 l.sort()
144 self.assertEqual(l, ['3', '4'])
146 def testAlternateAddress(self):
147 message = cStringIO.StringIO('''Content-Type: text/plain;
148 charset="iso-8859-1"
149 From: John Doe <john.doe@test>
150 To: issue_tracker@your.tracker.email.domain.example
151 Message-Id: <dummy_test_message_id>
152 Subject: [issue] Testing...
154 This is a test submission of a new issue.
155 ''')
156 userlist = self.db.user.list()
157 handler = self.instance.MailGW(self.instance, self.db)
158 handler.trapExceptions = 0
159 handler.main(message)
160 if os.path.exists(os.environ['SENDMAILDEBUG']):
161 error = open(os.environ['SENDMAILDEBUG']).read()
162 self.assertEqual('no error', error)
163 self.assertEqual(userlist, self.db.user.list(),
164 "user created when it shouldn't have been")
166 def testNewIssueNoClass(self):
167 message = cStringIO.StringIO('''Content-Type: text/plain;
168 charset="iso-8859-1"
169 From: Chef <chef@bork.bork.bork>
170 To: issue_tracker@your.tracker.email.domain.example
171 Cc: richard@test
172 Message-Id: <dummy_test_message_id>
173 Subject: Testing...
175 This is a test submission of a new issue.
176 ''')
177 handler = self.instance.MailGW(self.instance, self.db)
178 handler.trapExceptions = 0
179 handler.main(message)
180 if os.path.exists(os.environ['SENDMAILDEBUG']):
181 error = open(os.environ['SENDMAILDEBUG']).read()
182 self.assertEqual('no error', error)
184 def testNewIssueAuthMsg(self):
185 message = cStringIO.StringIO('''Content-Type: text/plain;
186 charset="iso-8859-1"
187 From: Chef <chef@bork.bork.bork>
188 To: issue_tracker@your.tracker.email.domain.example
189 Message-Id: <dummy_test_message_id>
190 Subject: [issue] Testing... [nosy=mary; assignedto=richard]
192 This is a test submission of a new issue.
193 ''')
194 handler = self.instance.MailGW(self.instance, self.db)
195 handler.trapExceptions = 0
196 # TODO: fix the damn config - this is apalling
197 self.db.config.MESSAGES_TO_AUTHOR = 'yes'
198 handler.main(message)
200 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
201 '''FROM: roundup-admin@your.tracker.email.domain.example
202 TO: chef@bork.bork.bork, mary@test, richard@test
203 Content-Type: text/plain
204 Subject: [issue1] Testing...
205 To: chef@bork.bork.bork, mary@test, richard@test
206 From: "Chef" <issue_tracker@your.tracker.email.domain.example>
207 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
208 MIME-Version: 1.0
209 Message-Id: <dummy_test_message_id>
210 X-Roundup-Name: Roundup issue tracker
211 Content-Transfer-Encoding: quoted-printable
214 New submission from Chef <chef@bork.bork.bork>:
216 This is a test submission of a new issue.
219 ----------
220 assignedto: richard
221 messages: 1
222 nosy: Chef, mary, richard
223 status: unread
224 title: Testing...
225 _________________________________________________________________________
226 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
227 http://your.tracker.url.example/issue1
228 _________________________________________________________________________
229 ''')
231 # BUG
232 # def testMultipart(self):
233 # '''With more than one part'''
234 # see MultipartEnc tests: but if there is more than one part
235 # we return a multipart/mixed and the boundary contains
236 # the ip address of the test machine.
238 # BUG should test some binary attamchent too.
240 def testSimpleFollowup(self):
241 self.doNewIssue()
242 message = cStringIO.StringIO('''Content-Type: text/plain;
243 charset="iso-8859-1"
244 From: mary <mary@test>
245 To: issue_tracker@your.tracker.email.domain.example
246 Message-Id: <followup_dummy_id>
247 In-Reply-To: <dummy_test_message_id>
248 Subject: [issue1] Testing...
250 This is a second followup
251 ''')
252 handler = self.instance.MailGW(self.instance, self.db)
253 handler.trapExceptions = 0
254 handler.main(message)
255 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
256 '''FROM: roundup-admin@your.tracker.email.domain.example
257 TO: chef@bork.bork.bork, richard@test
258 Content-Type: text/plain
259 Subject: [issue1] Testing...
260 To: chef@bork.bork.bork, richard@test
261 From: "mary" <issue_tracker@your.tracker.email.domain.example>
262 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
263 MIME-Version: 1.0
264 Message-Id: <followup_dummy_id>
265 In-Reply-To: <dummy_test_message_id>
266 X-Roundup-Name: Roundup issue tracker
267 Content-Transfer-Encoding: quoted-printable
270 mary <mary@test> added the comment:
272 This is a second followup
275 ----------
276 status: unread -> chatting
277 _________________________________________________________________________
278 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
279 http://your.tracker.url.example/issue1
280 _________________________________________________________________________
281 ''')
283 def testFollowup(self):
284 self.doNewIssue()
286 message = cStringIO.StringIO('''Content-Type: text/plain;
287 charset="iso-8859-1"
288 From: richard <richard@test>
289 To: issue_tracker@your.tracker.email.domain.example
290 Message-Id: <followup_dummy_id>
291 In-Reply-To: <dummy_test_message_id>
292 Subject: [issue1] Testing... [assignedto=mary; nosy=+john]
294 This is a followup
295 ''')
296 handler = self.instance.MailGW(self.instance, self.db)
297 handler.trapExceptions = 0
298 handler.main(message)
299 l = self.db.issue.get('1', 'nosy')
300 l.sort()
301 self.assertEqual(l, ['3', '4', '5', '6'])
303 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
304 '''FROM: roundup-admin@your.tracker.email.domain.example
305 TO: chef@bork.bork.bork, john@test, mary@test
306 Content-Type: text/plain
307 Subject: [issue1] Testing...
308 To: chef@bork.bork.bork, john@test, mary@test
309 From: "richard" <issue_tracker@your.tracker.email.domain.example>
310 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
311 MIME-Version: 1.0
312 Message-Id: <followup_dummy_id>
313 In-Reply-To: <dummy_test_message_id>
314 X-Roundup-Name: Roundup issue tracker
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://your.tracker.url.example/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
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 Content-Transfer-Encoding: quoted-printable
364 richard <richard@test> added the comment:
366 This is a followup
369 ----------
370 assignedto: -> mary
371 nosy: +john, mary
372 status: unread -> chatting
373 _________________________________________________________________________
374 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
375 http://your.tracker.url.example/issue1
376 _________________________________________________________________________
377 ''')
379 def testFollowupNosyAuthor(self):
380 self.doNewIssue()
381 self.db.config.ADD_AUTHOR_TO_NOSY = 'yes'
382 message = cStringIO.StringIO('''Content-Type: text/plain;
383 charset="iso-8859-1"
384 From: john@test
385 To: issue_tracker@your.tracker.email.domain.example
386 Message-Id: <followup_dummy_id>
387 In-Reply-To: <dummy_test_message_id>
388 Subject: [issue1] Testing...
390 This is a followup
391 ''')
392 handler = self.instance.MailGW(self.instance, self.db)
393 handler.trapExceptions = 0
394 handler.main(message)
396 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
397 '''FROM: roundup-admin@your.tracker.email.domain.example
398 TO: chef@bork.bork.bork, richard@test
399 Content-Type: text/plain
400 Subject: [issue1] Testing...
401 To: chef@bork.bork.bork, richard@test
402 From: "john" <issue_tracker@your.tracker.email.domain.example>
403 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
404 MIME-Version: 1.0
405 Message-Id: <followup_dummy_id>
406 In-Reply-To: <dummy_test_message_id>
407 X-Roundup-Name: Roundup issue tracker
408 Content-Transfer-Encoding: quoted-printable
411 john <john@test> added the comment:
413 This is a followup
416 ----------
417 nosy: +john
418 status: unread -> chatting
419 _________________________________________________________________________
420 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
421 http://your.tracker.url.example/issue1
422 _________________________________________________________________________
424 ''')
426 def testFollowupNosyRecipients(self):
427 self.doNewIssue()
428 self.db.config.ADD_RECIPIENTS_TO_NOSY = 'yes'
429 message = cStringIO.StringIO('''Content-Type: text/plain;
430 charset="iso-8859-1"
431 From: richard@test
432 To: issue_tracker@your.tracker.email.domain.example
433 Cc: john@test
434 Message-Id: <followup_dummy_id>
435 In-Reply-To: <dummy_test_message_id>
436 Subject: [issue1] Testing...
438 This is a followup
439 ''')
440 handler = self.instance.MailGW(self.instance, self.db)
441 handler.trapExceptions = 0
442 handler.main(message)
444 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
445 '''FROM: roundup-admin@your.tracker.email.domain.example
446 TO: chef@bork.bork.bork
447 Content-Type: text/plain
448 Subject: [issue1] Testing...
449 To: chef@bork.bork.bork
450 From: "richard" <issue_tracker@your.tracker.email.domain.example>
451 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
452 MIME-Version: 1.0
453 Message-Id: <followup_dummy_id>
454 In-Reply-To: <dummy_test_message_id>
455 X-Roundup-Name: Roundup issue tracker
456 Content-Transfer-Encoding: quoted-printable
459 richard <richard@test> added the comment:
461 This is a followup
464 ----------
465 nosy: +john
466 status: unread -> chatting
467 _________________________________________________________________________
468 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
469 http://your.tracker.url.example/issue1
470 _________________________________________________________________________
472 ''')
474 def testFollowupNosyAuthorAndCopy(self):
475 self.doNewIssue()
476 self.db.config.ADD_AUTHOR_TO_NOSY = 'yes'
477 self.db.config.MESSAGES_TO_AUTHOR = 'yes'
478 message = cStringIO.StringIO('''Content-Type: text/plain;
479 charset="iso-8859-1"
480 From: john@test
481 To: issue_tracker@your.tracker.email.domain.example
482 Message-Id: <followup_dummy_id>
483 In-Reply-To: <dummy_test_message_id>
484 Subject: [issue1] Testing...
486 This is a followup
487 ''')
488 handler = self.instance.MailGW(self.instance, self.db)
489 handler.trapExceptions = 0
490 handler.main(message)
492 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
493 '''FROM: roundup-admin@your.tracker.email.domain.example
494 TO: chef@bork.bork.bork, john@test, richard@test
495 Content-Type: text/plain
496 Subject: [issue1] Testing...
497 To: chef@bork.bork.bork, john@test, richard@test
498 From: "john" <issue_tracker@your.tracker.email.domain.example>
499 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
500 MIME-Version: 1.0
501 Message-Id: <followup_dummy_id>
502 In-Reply-To: <dummy_test_message_id>
503 X-Roundup-Name: Roundup issue tracker
504 Content-Transfer-Encoding: quoted-printable
507 john <john@test> added the comment:
509 This is a followup
512 ----------
513 nosy: +john
514 status: unread -> chatting
515 _________________________________________________________________________
516 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
517 http://your.tracker.url.example/issue1
518 _________________________________________________________________________
520 ''')
522 def testFollowupNoNosyAuthor(self):
523 self.doNewIssue()
524 self.instance.config.ADD_AUTHOR_TO_NOSY = 'no'
525 message = cStringIO.StringIO('''Content-Type: text/plain;
526 charset="iso-8859-1"
527 From: john@test
528 To: issue_tracker@your.tracker.email.domain.example
529 Message-Id: <followup_dummy_id>
530 In-Reply-To: <dummy_test_message_id>
531 Subject: [issue1] Testing...
533 This is a followup
534 ''')
535 handler = self.instance.MailGW(self.instance, self.db)
536 handler.trapExceptions = 0
537 handler.main(message)
539 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
540 '''FROM: roundup-admin@your.tracker.email.domain.example
541 TO: chef@bork.bork.bork, richard@test
542 Content-Type: text/plain
543 Subject: [issue1] Testing...
544 To: chef@bork.bork.bork, richard@test
545 From: "john" <issue_tracker@your.tracker.email.domain.example>
546 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
547 MIME-Version: 1.0
548 Message-Id: <followup_dummy_id>
549 In-Reply-To: <dummy_test_message_id>
550 X-Roundup-Name: Roundup issue tracker
551 Content-Transfer-Encoding: quoted-printable
554 john <john@test> added the comment:
556 This is a followup
559 ----------
560 status: unread -> chatting
561 _________________________________________________________________________
562 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
563 http://your.tracker.url.example/issue1
564 _________________________________________________________________________
566 ''')
568 def testFollowupNoNosyRecipients(self):
569 self.doNewIssue()
570 self.instance.config.ADD_RECIPIENTS_TO_NOSY = 'no'
571 message = cStringIO.StringIO('''Content-Type: text/plain;
572 charset="iso-8859-1"
573 From: richard@test
574 To: issue_tracker@your.tracker.email.domain.example
575 Cc: john@test
576 Message-Id: <followup_dummy_id>
577 In-Reply-To: <dummy_test_message_id>
578 Subject: [issue1] Testing...
580 This is a followup
581 ''')
582 handler = self.instance.MailGW(self.instance, self.db)
583 handler.trapExceptions = 0
584 handler.main(message)
586 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
587 '''FROM: roundup-admin@your.tracker.email.domain.example
588 TO: chef@bork.bork.bork
589 Content-Type: text/plain
590 Subject: [issue1] Testing...
591 To: chef@bork.bork.bork
592 From: "richard" <issue_tracker@your.tracker.email.domain.example>
593 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
594 MIME-Version: 1.0
595 Message-Id: <followup_dummy_id>
596 In-Reply-To: <dummy_test_message_id>
597 X-Roundup-Name: Roundup issue tracker
598 Content-Transfer-Encoding: quoted-printable
601 richard <richard@test> added the comment:
603 This is a followup
606 ----------
607 status: unread -> chatting
608 _________________________________________________________________________
609 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
610 http://your.tracker.url.example/issue1
611 _________________________________________________________________________
613 ''')
615 def testNosyRemove(self):
616 self.doNewIssue()
618 message = cStringIO.StringIO('''Content-Type: text/plain;
619 charset="iso-8859-1"
620 From: richard <richard@test>
621 To: issue_tracker@your.tracker.email.domain.example
622 Message-Id: <followup_dummy_id>
623 In-Reply-To: <dummy_test_message_id>
624 Subject: [issue1] Testing... [nosy=-richard]
626 ''')
627 handler = self.instance.MailGW(self.instance, self.db)
628 handler.trapExceptions = 0
629 handler.main(message)
630 l = self.db.issue.get('1', 'nosy')
631 l.sort()
632 self.assertEqual(l, ['3'])
634 # NO NOSY MESSAGE SHOULD BE SENT!
635 self.assert_(not os.path.exists(os.environ['SENDMAILDEBUG']))
637 def testNewUserAuthor(self):
638 # first without the permission
639 # heh... just ignore the API for a second ;)
640 self.db.security.role['Anonymous'].permissions=[]
641 anonid = self.db.user.lookup('anonymous')
642 self.db.user.set(anonid, roles='Anonymous')
644 self.db.security.hasPermission('Email Registration', anonid)
645 l = self.db.user.list()
646 l.sort()
647 s = '''Content-Type: text/plain;
648 charset="iso-8859-1"
649 From: fubar <fubar@bork.bork.bork>
650 To: issue_tracker@your.tracker.email.domain.example
651 Message-Id: <dummy_test_message_id>
652 Subject: [issue] Testing...
654 This is a test submission of a new issue.
655 '''
656 message = cStringIO.StringIO(s)
657 handler = self.instance.MailGW(self.instance, self.db)
658 handler.trapExceptions = 0
659 self.assertRaises(Unauthorized, handler.main, message)
660 m = self.db.user.list()
661 m.sort()
662 self.assertEqual(l, m)
664 # now with the permission
665 p = self.db.security.getPermission('Email Registration')
666 self.db.security.role['Anonymous'].permissions=[p]
667 handler = self.instance.MailGW(self.instance, self.db)
668 handler.trapExceptions = 0
669 message = cStringIO.StringIO(s)
670 handler.main(message)
671 m = self.db.user.list()
672 m.sort()
673 self.assertNotEqual(l, m)
675 def testEnc01(self):
676 self.doNewIssue()
677 message = cStringIO.StringIO('''Content-Type: text/plain;
678 charset="iso-8859-1"
679 From: mary <mary@test>
680 To: issue_tracker@your.tracker.email.domain.example
681 Message-Id: <followup_dummy_id>
682 In-Reply-To: <dummy_test_message_id>
683 Subject: [issue1] Testing...
684 Content-Type: text/plain;
685 charset="iso-8859-1"
686 Content-Transfer-Encoding: quoted-printable
688 A message with encoding (encoded oe =F6)
690 ''')
691 handler = self.instance.MailGW(self.instance, self.db)
692 handler.trapExceptions = 0
693 handler.main(message)
694 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
695 '''FROM: roundup-admin@your.tracker.email.domain.example
696 TO: chef@bork.bork.bork, richard@test
697 Content-Type: text/plain
698 Subject: [issue1] Testing...
699 To: chef@bork.bork.bork, richard@test
700 From: "mary" <issue_tracker@your.tracker.email.domain.example>
701 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
702 MIME-Version: 1.0
703 Message-Id: <followup_dummy_id>
704 In-Reply-To: <dummy_test_message_id>
705 X-Roundup-Name: Roundup issue tracker
706 Content-Transfer-Encoding: quoted-printable
709 mary <mary@test> added the comment:
711 A message with encoding (encoded oe =F6)
713 ----------
714 status: unread -> chatting
715 _________________________________________________________________________
716 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
717 http://your.tracker.url.example/issue1
718 _________________________________________________________________________
719 ''')
722 def testMultipartEnc01(self):
723 self.doNewIssue()
724 message = cStringIO.StringIO('''Content-Type: text/plain;
725 charset="iso-8859-1"
726 From: mary <mary@test>
727 To: issue_tracker@your.tracker.email.domain.example
728 Message-Id: <followup_dummy_id>
729 In-Reply-To: <dummy_test_message_id>
730 Subject: [issue1] Testing...
731 Content-Type: multipart/mixed;
732 boundary="----_=_NextPart_000_01"
734 This message is in MIME format. Since your mail reader does not understand
735 this format, some or all of this message may not be legible.
737 ------_=_NextPart_000_01
738 Content-Type: text/plain;
739 charset="iso-8859-1"
740 Content-Transfer-Encoding: quoted-printable
742 A message with first part encoded (encoded oe =F6)
744 ''')
745 handler = self.instance.MailGW(self.instance, self.db)
746 handler.trapExceptions = 0
747 handler.main(message)
748 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
749 '''FROM: roundup-admin@your.tracker.email.domain.example
750 TO: chef@bork.bork.bork, richard@test
751 Content-Type: text/plain
752 Subject: [issue1] Testing...
753 To: chef@bork.bork.bork, richard@test
754 From: "mary" <issue_tracker@your.tracker.email.domain.example>
755 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
756 MIME-Version: 1.0
757 Message-Id: <followup_dummy_id>
758 In-Reply-To: <dummy_test_message_id>
759 X-Roundup-Name: Roundup issue tracker
760 Content-Transfer-Encoding: quoted-printable
763 mary <mary@test> added the comment:
765 A message with first part encoded (encoded oe =F6)
767 ----------
768 status: unread -> chatting
769 _________________________________________________________________________
770 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
771 http://your.tracker.url.example/issue1
772 _________________________________________________________________________
773 ''')
775 def suite():
776 l = [unittest.makeSuite(MailgwTestCase),
777 ]
778 return unittest.TestSuite(l)
781 # vim: set filetype=python ts=4 sw=4 et si