Code

Lots of little fixes in this update:
[roundup.git] / test / test_mailgw.py
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.34 2002-12-10 00:11:16 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
44         
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 Content-Transfer-Encoding: quoted-printable
217 New submission from Bork, Chef <chef@bork.bork.bork>:
219 This is a test submission of a new issue.
222 ----------
223 assignedto: richard
224 messages: 1
225 nosy: Chef, mary, richard
226 status: unread
227 title: Testing...
228 _______________________________________________________________________
229 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
230 http://your.tracker.url.example/issue1
231 _______________________________________________________________________
232 ''')
234     # BUG
235     # def testMultipart(self):
236     #         '''With more than one part'''
237     #        see MultipartEnc tests: but if there is more than one part
238     #        we return a multipart/mixed and the boundary contains
239     #        the ip address of the test machine. 
241     # BUG should test some binary attamchent too.
243     def testSimpleFollowup(self):
244         self.doNewIssue()
245         message = cStringIO.StringIO('''Content-Type: text/plain;
246   charset="iso-8859-1"
247 From: mary <mary@test>
248 To: issue_tracker@your.tracker.email.domain.example
249 Message-Id: <followup_dummy_id>
250 In-Reply-To: <dummy_test_message_id>
251 Subject: [issue1] Testing...
253 This is a second followup
254 ''')
255         handler = self.instance.MailGW(self.instance, self.db)
256         handler.trapExceptions = 0
257         handler.main(message)
258         self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
259 '''FROM: roundup-admin@your.tracker.email.domain.example
260 TO: chef@bork.bork.bork, richard@test
261 Content-Type: text/plain
262 Subject: [issue1] Testing...
263 To: chef@bork.bork.bork, richard@test
264 From: "Contrary, Mary" <issue_tracker@your.tracker.email.domain.example>
265 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
266 MIME-Version: 1.0
267 Message-Id: <followup_dummy_id>
268 In-Reply-To: <dummy_test_message_id>
269 X-Roundup-Name: Roundup issue tracker
270 Content-Transfer-Encoding: quoted-printable
273 Contrary, Mary <mary@test> added the comment:
275 This is a second followup
278 ----------
279 status: unread -> chatting
280 _______________________________________________________________________
281 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
282 http://your.tracker.url.example/issue1
283 _______________________________________________________________________
284 ''')
286     def testFollowup(self):
287         self.doNewIssue()
289         message = cStringIO.StringIO('''Content-Type: text/plain;
290   charset="iso-8859-1"
291 From: richard <richard@test>
292 To: issue_tracker@your.tracker.email.domain.example
293 Message-Id: <followup_dummy_id>
294 In-Reply-To: <dummy_test_message_id>
295 Subject: [issue1] Testing... [assignedto=mary; nosy=+john]
297 This is a followup
298 ''')
299         handler = self.instance.MailGW(self.instance, self.db)
300         handler.trapExceptions = 0
301         handler.main(message)
302         l = self.db.issue.get('1', 'nosy')
303         l.sort()
304         self.assertEqual(l, ['3', '4', '5', '6'])
306         self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
307 '''FROM: roundup-admin@your.tracker.email.domain.example
308 TO: chef@bork.bork.bork, john@test, mary@test
309 Content-Type: text/plain
310 Subject: [issue1] Testing...
311 To: chef@bork.bork.bork, john@test, mary@test
312 From: richard <issue_tracker@your.tracker.email.domain.example>
313 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
314 MIME-Version: 1.0
315 Message-Id: <followup_dummy_id>
316 In-Reply-To: <dummy_test_message_id>
317 X-Roundup-Name: Roundup issue tracker
318 Content-Transfer-Encoding: quoted-printable
321 richard <richard@test> added the comment:
323 This is a followup
326 ----------
327 assignedto:  -> mary
328 nosy: +john, mary
329 status: unread -> chatting
330 _______________________________________________________________________
331 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
332 http://your.tracker.url.example/issue1
333 _______________________________________________________________________
334 ''')
336     def testFollowupTitleMatch(self):
337         self.doNewIssue()
338         message = cStringIO.StringIO('''Content-Type: text/plain;
339   charset="iso-8859-1"
340 From: richard <richard@test>
341 To: issue_tracker@your.tracker.email.domain.example
342 Message-Id: <followup_dummy_id>
343 In-Reply-To: <dummy_test_message_id>
344 Subject: Re: Testing... [assignedto=mary; nosy=+john]
346 This is a followup
347 ''')
348         handler = self.instance.MailGW(self.instance, self.db)
349         handler.trapExceptions = 0
350         handler.main(message)
352         self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
353 '''FROM: roundup-admin@your.tracker.email.domain.example
354 TO: chef@bork.bork.bork, john@test, mary@test
355 Content-Type: text/plain
356 Subject: [issue1] Testing...
357 To: chef@bork.bork.bork, john@test, mary@test
358 From: richard <issue_tracker@your.tracker.email.domain.example>
359 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
360 MIME-Version: 1.0
361 Message-Id: <followup_dummy_id>
362 In-Reply-To: <dummy_test_message_id>
363 X-Roundup-Name: Roundup issue tracker
364 Content-Transfer-Encoding: quoted-printable
367 richard <richard@test> added the comment:
369 This is a followup
372 ----------
373 assignedto:  -> mary
374 nosy: +john, mary
375 status: unread -> chatting
376 _______________________________________________________________________
377 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
378 http://your.tracker.url.example/issue1
379 _______________________________________________________________________
380 ''')
382     def testFollowupNosyAuthor(self):
383         self.doNewIssue()
384         self.db.config.ADD_AUTHOR_TO_NOSY = 'yes'
385         message = cStringIO.StringIO('''Content-Type: text/plain;
386   charset="iso-8859-1"
387 From: john@test
388 To: issue_tracker@your.tracker.email.domain.example
389 Message-Id: <followup_dummy_id>
390 In-Reply-To: <dummy_test_message_id>
391 Subject: [issue1] Testing...
393 This is a followup
394 ''')
395         handler = self.instance.MailGW(self.instance, self.db)
396         handler.trapExceptions = 0
397         handler.main(message)
399         self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
400 '''FROM: roundup-admin@your.tracker.email.domain.example
401 TO: chef@bork.bork.bork, richard@test
402 Content-Type: text/plain
403 Subject: [issue1] Testing...
404 To: chef@bork.bork.bork, richard@test
405 From: John Doe <issue_tracker@your.tracker.email.domain.example>
406 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
407 MIME-Version: 1.0
408 Message-Id: <followup_dummy_id>
409 In-Reply-To: <dummy_test_message_id>
410 X-Roundup-Name: Roundup issue tracker
411 Content-Transfer-Encoding: quoted-printable
414 John Doe <john@test> added the comment:
416 This is a followup
419 ----------
420 nosy: +john
421 status: unread -> chatting
422 _______________________________________________________________________
423 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
424 http://your.tracker.url.example/issue1
425 _______________________________________________________________________
427 ''')
429     def testFollowupNosyRecipients(self):
430         self.doNewIssue()
431         self.db.config.ADD_RECIPIENTS_TO_NOSY = 'yes'
432         message = cStringIO.StringIO('''Content-Type: text/plain;
433   charset="iso-8859-1"
434 From: richard@test
435 To: issue_tracker@your.tracker.email.domain.example
436 Cc: john@test
437 Message-Id: <followup_dummy_id>
438 In-Reply-To: <dummy_test_message_id>
439 Subject: [issue1] Testing...
441 This is a followup
442 ''')
443         handler = self.instance.MailGW(self.instance, self.db)
444         handler.trapExceptions = 0
445         handler.main(message)
447         self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
448 '''FROM: roundup-admin@your.tracker.email.domain.example
449 TO: chef@bork.bork.bork
450 Content-Type: text/plain
451 Subject: [issue1] Testing...
452 To: chef@bork.bork.bork
453 From: richard <issue_tracker@your.tracker.email.domain.example>
454 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
455 MIME-Version: 1.0
456 Message-Id: <followup_dummy_id>
457 In-Reply-To: <dummy_test_message_id>
458 X-Roundup-Name: Roundup issue tracker
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://your.tracker.url.example/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
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 Content-Transfer-Encoding: quoted-printable
510 John Doe <john@test> added the comment:
512 This is a followup
515 ----------
516 nosy: +john
517 status: unread -> chatting
518 _______________________________________________________________________
519 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
520 http://your.tracker.url.example/issue1
521 _______________________________________________________________________
523 ''')
525     def testFollowupNoNosyAuthor(self):
526         self.doNewIssue()
527         self.instance.config.ADD_AUTHOR_TO_NOSY = 'no'
528         message = cStringIO.StringIO('''Content-Type: text/plain;
529   charset="iso-8859-1"
530 From: john@test
531 To: issue_tracker@your.tracker.email.domain.example
532 Message-Id: <followup_dummy_id>
533 In-Reply-To: <dummy_test_message_id>
534 Subject: [issue1] Testing...
536 This is a followup
537 ''')
538         handler = self.instance.MailGW(self.instance, self.db)
539         handler.trapExceptions = 0
540         handler.main(message)
542         self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
543 '''FROM: roundup-admin@your.tracker.email.domain.example
544 TO: chef@bork.bork.bork, richard@test
545 Content-Type: text/plain
546 Subject: [issue1] Testing...
547 To: chef@bork.bork.bork, richard@test
548 From: John Doe <issue_tracker@your.tracker.email.domain.example>
549 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
550 MIME-Version: 1.0
551 Message-Id: <followup_dummy_id>
552 In-Reply-To: <dummy_test_message_id>
553 X-Roundup-Name: Roundup issue tracker
554 Content-Transfer-Encoding: quoted-printable
557 John Doe <john@test> added the comment:
559 This is a followup
562 ----------
563 status: unread -> chatting
564 _______________________________________________________________________
565 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
566 http://your.tracker.url.example/issue1
567 _______________________________________________________________________
569 ''')
571     def testFollowupNoNosyRecipients(self):
572         self.doNewIssue()
573         self.instance.config.ADD_RECIPIENTS_TO_NOSY = 'no'
574         message = cStringIO.StringIO('''Content-Type: text/plain;
575   charset="iso-8859-1"
576 From: richard@test
577 To: issue_tracker@your.tracker.email.domain.example
578 Cc: john@test
579 Message-Id: <followup_dummy_id>
580 In-Reply-To: <dummy_test_message_id>
581 Subject: [issue1] Testing...
583 This is a followup
584 ''')
585         handler = self.instance.MailGW(self.instance, self.db)
586         handler.trapExceptions = 0
587         handler.main(message)
589         self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
590 '''FROM: roundup-admin@your.tracker.email.domain.example
591 TO: chef@bork.bork.bork
592 Content-Type: text/plain
593 Subject: [issue1] Testing...
594 To: chef@bork.bork.bork
595 From: richard <issue_tracker@your.tracker.email.domain.example>
596 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
597 MIME-Version: 1.0
598 Message-Id: <followup_dummy_id>
599 In-Reply-To: <dummy_test_message_id>
600 X-Roundup-Name: Roundup issue tracker
601 Content-Transfer-Encoding: quoted-printable
604 richard <richard@test> added the comment:
606 This is a followup
609 ----------
610 status: unread -> chatting
611 _______________________________________________________________________
612 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
613 http://your.tracker.url.example/issue1
614 _______________________________________________________________________
616 ''')
618     def testNosyRemove(self):
619         self.doNewIssue()
621         message = cStringIO.StringIO('''Content-Type: text/plain;
622   charset="iso-8859-1"
623 From: richard <richard@test>
624 To: issue_tracker@your.tracker.email.domain.example
625 Message-Id: <followup_dummy_id>
626 In-Reply-To: <dummy_test_message_id>
627 Subject: [issue1] Testing... [nosy=-richard]
629 ''')
630         handler = self.instance.MailGW(self.instance, self.db)
631         handler.trapExceptions = 0
632         handler.main(message)
633         l = self.db.issue.get('1', 'nosy')
634         l.sort()
635         self.assertEqual(l, ['3'])
637         # NO NOSY MESSAGE SHOULD BE SENT!
638         self.assert_(not os.path.exists(os.environ['SENDMAILDEBUG']))
640     def testNewUserAuthor(self):
641         # first without the permission
642         # heh... just ignore the API for a second ;)
643         self.db.security.role['Anonymous'].permissions=[]
644         anonid = self.db.user.lookup('anonymous')
645         self.db.user.set(anonid, roles='Anonymous')
647         self.db.security.hasPermission('Email Registration', anonid)
648         l = self.db.user.list()
649         l.sort()
650         s = '''Content-Type: text/plain;
651   charset="iso-8859-1"
652 From: fubar <fubar@bork.bork.bork>
653 To: issue_tracker@your.tracker.email.domain.example
654 Message-Id: <dummy_test_message_id>
655 Subject: [issue] Testing...
657 This is a test submission of a new issue.
658 '''
659         message = cStringIO.StringIO(s)
660         handler = self.instance.MailGW(self.instance, self.db)
661         handler.trapExceptions = 0
662         self.assertRaises(Unauthorized, handler.main, message)
663         m = self.db.user.list()
664         m.sort()
665         self.assertEqual(l, m)
667         # now with the permission
668         p = self.db.security.getPermission('Email Registration')
669         self.db.security.role['Anonymous'].permissions=[p]
670         handler = self.instance.MailGW(self.instance, self.db)
671         handler.trapExceptions = 0
672         message = cStringIO.StringIO(s)
673         handler.main(message)
674         m = self.db.user.list()
675         m.sort()
676         self.assertNotEqual(l, m)
678     def testEnc01(self):
679         self.doNewIssue()
680         message = cStringIO.StringIO('''Content-Type: text/plain;
681   charset="iso-8859-1"
682 From: mary <mary@test>
683 To: issue_tracker@your.tracker.email.domain.example
684 Message-Id: <followup_dummy_id>
685 In-Reply-To: <dummy_test_message_id>
686 Subject: [issue1] Testing...
687 Content-Type: text/plain;
688         charset="iso-8859-1"
689 Content-Transfer-Encoding: quoted-printable
691 A message with encoding (encoded oe =F6)
693 ''')
694         handler = self.instance.MailGW(self.instance, self.db)
695         handler.trapExceptions = 0
696         handler.main(message)
697         self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
698 '''FROM: roundup-admin@your.tracker.email.domain.example
699 TO: chef@bork.bork.bork, richard@test
700 Content-Type: text/plain
701 Subject: [issue1] Testing...
702 To: chef@bork.bork.bork, richard@test
703 From: "Contrary, Mary" <issue_tracker@your.tracker.email.domain.example>
704 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
705 MIME-Version: 1.0
706 Message-Id: <followup_dummy_id>
707 In-Reply-To: <dummy_test_message_id>
708 X-Roundup-Name: Roundup issue tracker
709 Content-Transfer-Encoding: quoted-printable
712 Contrary, Mary <mary@test> added the comment:
714 A message with encoding (encoded oe =F6)
716 ----------
717 status: unread -> chatting
718 _______________________________________________________________________
719 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
720 http://your.tracker.url.example/issue1
721 _______________________________________________________________________
722 ''')
725     def testMultipartEnc01(self):
726         self.doNewIssue()
727         message = cStringIO.StringIO('''Content-Type: text/plain;
728   charset="iso-8859-1"
729 From: mary <mary@test>
730 To: issue_tracker@your.tracker.email.domain.example
731 Message-Id: <followup_dummy_id>
732 In-Reply-To: <dummy_test_message_id>
733 Subject: [issue1] Testing...
734 Content-Type: multipart/mixed;
735         boundary="----_=_NextPart_000_01"
737 This message is in MIME format. Since your mail reader does not understand
738 this format, some or all of this message may not be legible.
740 ------_=_NextPart_000_01
741 Content-Type: text/plain;
742         charset="iso-8859-1"
743 Content-Transfer-Encoding: quoted-printable
745 A message with first part encoded (encoded oe =F6)
747 ''')
748         handler = self.instance.MailGW(self.instance, self.db)
749         handler.trapExceptions = 0
750         handler.main(message)
751         self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
752 '''FROM: roundup-admin@your.tracker.email.domain.example
753 TO: chef@bork.bork.bork, richard@test
754 Content-Type: text/plain
755 Subject: [issue1] Testing...
756 To: chef@bork.bork.bork, richard@test
757 From: "Contrary, Mary" <issue_tracker@your.tracker.email.domain.example>
758 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
759 MIME-Version: 1.0
760 Message-Id: <followup_dummy_id>
761 In-Reply-To: <dummy_test_message_id>
762 X-Roundup-Name: Roundup issue tracker
763 Content-Transfer-Encoding: quoted-printable
766 Contrary, Mary <mary@test> added the comment:
768 A message with first part encoded (encoded oe =F6)
770 ----------
771 status: unread -> chatting
772 _______________________________________________________________________
773 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
774 http://your.tracker.url.example/issue1
775 _______________________________________________________________________
776 ''')
778     def testFollowupStupidQuoting(self):
779         self.doNewIssue()
781         message = cStringIO.StringIO('''Content-Type: text/plain;
782   charset="iso-8859-1"
783 From: richard <richard@test>
784 To: issue_tracker@your.tracker.email.domain.example
785 Message-Id: <followup_dummy_id>
786 In-Reply-To: <dummy_test_message_id>
787 Subject: Re: "[issue1] Testing... "
789 This is a followup
790 ''')
791         handler = self.instance.MailGW(self.instance, self.db)
792         handler.trapExceptions = 0
793         handler.main(message)
795         self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
796 '''FROM: roundup-admin@your.tracker.email.domain.example
797 TO: chef@bork.bork.bork
798 Content-Type: text/plain
799 Subject: [issue1] Testing...
800 To: chef@bork.bork.bork
801 From: richard <issue_tracker@your.tracker.email.domain.example>
802 Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
803 MIME-Version: 1.0
804 Message-Id: <followup_dummy_id>
805 In-Reply-To: <dummy_test_message_id>
806 X-Roundup-Name: Roundup issue tracker
807 Content-Transfer-Encoding: quoted-printable
810 richard <richard@test> added the comment:
812 This is a followup
815 ----------
816 status: unread -> chatting
817 _______________________________________________________________________
818 Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
819 http://your.tracker.url.example/issue1
820 _______________________________________________________________________
821 ''')
823     def testEmailQuoting(self):
824         self.instance.config.EMAIL_KEEP_QUOTED_TEXT = 'no'
825         self.innerTestQuoting('''This is a followup
826 ''')
828     def testEmailQuotingRemove(self):
829         self.instance.config.EMAIL_KEEP_QUOTED_TEXT = 'yes'
830         self.innerTestQuoting('''Blah blah wrote:
831 > Blah bklaskdfj sdf asdf jlaskdf skj sdkfjl asdf
832 >  skdjlkjsdfalsdkfjasdlfkj dlfksdfalksd fj
835 This is a followup
836 ''')
838     def innerTestQuoting(self, expect):
839         nodeid = self.doNewIssue()
841         messages = self.db.issue.get(nodeid, 'messages')
843         message = cStringIO.StringIO('''Content-Type: text/plain;
844   charset="iso-8859-1"
845 From: richard <richard@test>
846 To: issue_tracker@your.tracker.email.domain.example
847 Message-Id: <followup_dummy_id>
848 In-Reply-To: <dummy_test_message_id>
849 Subject: Re: [issue1] Testing...
851 Blah blah wrote:
852 > Blah bklaskdfj sdf asdf jlaskdf skj sdkfjl asdf
853 >  skdjlkjsdfalsdkfjasdlfkj dlfksdfalksd fj
856 This is a followup
857 ''')
858         handler = self.instance.MailGW(self.instance, self.db)
859         handler.trapExceptions = 0
860         handler.main(message)
862         # figure the new message id
863         newmessages = self.db.issue.get(nodeid, 'messages')
864         for msg in messages:
865             newmessages.remove(msg)
866         messageid = newmessages[0]
868         self.compareStrings(self.db.msg.get(messageid, 'content'), expect)
870 def suite():
871     l = [unittest.makeSuite(MailgwTestCase),
872     ]
873     return unittest.TestSuite(l)
876 # vim: set filetype=python ts=4 sw=4 et si