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.25 2002-07-29 00:56:06 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 self.db.user.create(username='richard', address='richard@test')
85 self.db.user.create(username='mary', address='mary@test')
86 self.db.user.create(username='john', address='john@test',
87 alternate_addresses='jondoe@test\njohn.doe@test')
89 def tearDown(self):
90 if os.path.exists(os.environ['SENDMAILDEBUG']):
91 os.remove(os.environ['SENDMAILDEBUG'])
92 try:
93 shutil.rmtree(self.dirname)
94 except OSError, error:
95 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
97 def doNewIssue(self):
98 message = cStringIO.StringIO('''Content-Type: text/plain;
99 charset="iso-8859-1"
100 From: Chef <chef@bork.bork.bork>
101 To: issue_tracker@your.tracker.email.domain.example
102 Cc: richard@test
103 Message-Id: <dummy_test_message_id>
104 Subject: [issue] Testing...
106 This is a test submission of a new issue.
107 ''')
108 handler = self.instance.MailGW(self.instance, self.db)
109 handler.trapExceptions = 0
110 nodeid = handler.main(message)
111 if os.path.exists(os.environ['SENDMAILDEBUG']):
112 error = open(os.environ['SENDMAILDEBUG']).read()
113 self.assertEqual('no error', error)
114 l = self.db.issue.get(nodeid, 'nosy')
115 l.sort()
116 self.assertEqual(l, ['3', '4'])
118 def testNewIssue(self):
119 self.doNewIssue()
121 def testNewIssueNosy(self):
122 self.instance.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
201 Subject: [issue1] Testing...
202 To: chef@bork.bork.bork, mary@test, richard@test
203 From: "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 Content-Transfer-Encoding: quoted-printable
211 New submission from Chef <chef@bork.bork.bork>:
213 This is a test submission of a new issue.
216 ----------
217 assignedto: richard
218 messages: 1
219 nosy: Chef, mary, richard
220 status: unread
221 title: Testing...
222 _________________________________________________________________________
223 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
224 http://your.tracker.url.example/issue1
225 _________________________________________________________________________
226 ''')
228 # BUG
229 # def testMultipart(self):
230 # '''With more than one part'''
231 # see MultipartEnc tests: but if there is more than one part
232 # we return a multipart/mixed and the boundary contains
233 # the ip address of the test machine.
235 # BUG should test some binary attamchent too.
237 def testSimpleFollowup(self):
238 self.doNewIssue()
239 message = cStringIO.StringIO('''Content-Type: text/plain;
240 charset="iso-8859-1"
241 From: mary <mary@test>
242 To: issue_tracker@your.tracker.email.domain.example
243 Message-Id: <followup_dummy_id>
244 In-Reply-To: <dummy_test_message_id>
245 Subject: [issue1] Testing...
247 This is a second followup
248 ''')
249 handler = self.instance.MailGW(self.instance, self.db)
250 handler.trapExceptions = 0
251 handler.main(message)
252 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
253 '''FROM: roundup-admin@your.tracker.email.domain.example
254 TO: chef@bork.bork.bork, richard@test
255 Content-Type: text/plain
256 Subject: [issue1] Testing...
257 To: chef@bork.bork.bork, richard@test
258 From: "mary" <issue_tracker@your.tracker.email.domain.example>
259 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
260 MIME-Version: 1.0
261 Message-Id: <followup_dummy_id>
262 In-Reply-To: <dummy_test_message_id>
263 X-Roundup-Name: Roundup issue tracker
264 Content-Transfer-Encoding: quoted-printable
267 mary <mary@test> added the comment:
269 This is a second followup
272 ----------
273 status: unread -> chatting
274 _________________________________________________________________________
275 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
276 http://your.tracker.url.example/issue1
277 _________________________________________________________________________
278 ''')
280 def testFollowup(self):
281 self.doNewIssue()
283 message = cStringIO.StringIO('''Content-Type: text/plain;
284 charset="iso-8859-1"
285 From: richard <richard@test>
286 To: issue_tracker@your.tracker.email.domain.example
287 Message-Id: <followup_dummy_id>
288 In-Reply-To: <dummy_test_message_id>
289 Subject: [issue1] Testing... [assignedto=mary; nosy=+john]
291 This is a followup
292 ''')
293 handler = self.instance.MailGW(self.instance, self.db)
294 handler.trapExceptions = 0
295 handler.main(message)
296 l = self.db.issue.get('1', 'nosy')
297 l.sort()
298 self.assertEqual(l, ['3', '4', '5', '6'])
300 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
301 '''FROM: roundup-admin@your.tracker.email.domain.example
302 TO: chef@bork.bork.bork, john@test, mary@test
303 Content-Type: text/plain
304 Subject: [issue1] Testing...
305 To: chef@bork.bork.bork, john@test, mary@test
306 From: "richard" <issue_tracker@your.tracker.email.domain.example>
307 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
308 MIME-Version: 1.0
309 Message-Id: <followup_dummy_id>
310 In-Reply-To: <dummy_test_message_id>
311 X-Roundup-Name: Roundup issue tracker
312 Content-Transfer-Encoding: quoted-printable
315 richard <richard@test> added the comment:
317 This is a followup
320 ----------
321 assignedto: -> mary
322 nosy: +mary, john
323 status: unread -> chatting
324 _________________________________________________________________________
325 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
326 http://your.tracker.url.example/issue1
327 _________________________________________________________________________
328 ''')
330 def testFollowupTitleMatch(self):
331 self.doNewIssue()
332 message = cStringIO.StringIO('''Content-Type: text/plain;
333 charset="iso-8859-1"
334 From: richard <richard@test>
335 To: issue_tracker@your.tracker.email.domain.example
336 Message-Id: <followup_dummy_id>
337 In-Reply-To: <dummy_test_message_id>
338 Subject: Re: Testing... [assignedto=mary; nosy=+john]
340 This is a followup
341 ''')
342 handler = self.instance.MailGW(self.instance, self.db)
343 handler.trapExceptions = 0
344 handler.main(message)
346 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
347 '''FROM: roundup-admin@your.tracker.email.domain.example
348 TO: chef@bork.bork.bork, john@test, mary@test
349 Content-Type: text/plain
350 Subject: [issue1] Testing...
351 To: chef@bork.bork.bork, john@test, mary@test
352 From: "richard" <issue_tracker@your.tracker.email.domain.example>
353 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
354 MIME-Version: 1.0
355 Message-Id: <followup_dummy_id>
356 In-Reply-To: <dummy_test_message_id>
357 X-Roundup-Name: Roundup issue tracker
358 Content-Transfer-Encoding: quoted-printable
361 richard <richard@test> added the comment:
363 This is a followup
366 ----------
367 assignedto: -> mary
368 nosy: +mary, john
369 status: unread -> chatting
370 _________________________________________________________________________
371 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
372 http://your.tracker.url.example/issue1
373 _________________________________________________________________________
374 ''')
376 def testFollowupNosyAuthor(self):
377 self.doNewIssue()
378 self.db.config.ADD_AUTHOR_TO_NOSY = self.instance.ADD_AUTHOR_TO_NOSY = 'yes'
379 message = cStringIO.StringIO('''Content-Type: text/plain;
380 charset="iso-8859-1"
381 From: john@test
382 To: issue_tracker@your.tracker.email.domain.example
383 Message-Id: <followup_dummy_id>
384 In-Reply-To: <dummy_test_message_id>
385 Subject: [issue1] Testing...
387 This is a followup
388 ''')
389 handler = self.instance.MailGW(self.instance, self.db)
390 handler.trapExceptions = 0
391 handler.main(message)
393 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
394 '''FROM: roundup-admin@your.tracker.email.domain.example
395 TO: chef@bork.bork.bork, richard@test
396 Content-Type: text/plain
397 Subject: [issue1] Testing...
398 To: chef@bork.bork.bork, richard@test
399 From: "john" <issue_tracker@your.tracker.email.domain.example>
400 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
401 MIME-Version: 1.0
402 Message-Id: <followup_dummy_id>
403 In-Reply-To: <dummy_test_message_id>
404 X-Roundup-Name: Roundup issue tracker
405 Content-Transfer-Encoding: quoted-printable
408 john <john@test> added the comment:
410 This is a followup
413 ----------
414 nosy: +john
415 status: unread -> chatting
416 _________________________________________________________________________
417 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
418 http://your.tracker.url.example/issue1
419 _________________________________________________________________________
421 ''')
423 def testFollowupNosyRecipients(self):
424 self.doNewIssue()
425 self.db.config.ADD_RECIPIENTS_TO_NOSY = self.instance.ADD_RECIPIENTS_TO_NOSY = 'yes'
426 message = cStringIO.StringIO('''Content-Type: text/plain;
427 charset="iso-8859-1"
428 From: richard@test
429 To: issue_tracker@your.tracker.email.domain.example
430 Cc: john@test
431 Message-Id: <followup_dummy_id>
432 In-Reply-To: <dummy_test_message_id>
433 Subject: [issue1] Testing...
435 This is a followup
436 ''')
437 handler = self.instance.MailGW(self.instance, self.db)
438 handler.trapExceptions = 0
439 handler.main(message)
441 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
442 '''FROM: roundup-admin@your.tracker.email.domain.example
443 TO: chef@bork.bork.bork
444 Content-Type: text/plain
445 Subject: [issue1] Testing...
446 To: chef@bork.bork.bork
447 From: "richard" <issue_tracker@your.tracker.email.domain.example>
448 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
449 MIME-Version: 1.0
450 Message-Id: <followup_dummy_id>
451 In-Reply-To: <dummy_test_message_id>
452 X-Roundup-Name: Roundup issue tracker
453 Content-Transfer-Encoding: quoted-printable
456 richard <richard@test> added the comment:
458 This is a followup
461 ----------
462 nosy: +john
463 status: unread -> chatting
464 _________________________________________________________________________
465 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
466 http://your.tracker.url.example/issue1
467 _________________________________________________________________________
469 ''')
471 def testFollowupNosyAuthorAndCopy(self):
472 self.doNewIssue()
473 self.db.config.ADD_AUTHOR_TO_NOSY = self.instance.ADD_AUTHOR_TO_NOSY = 'yes'
474 self.db.config.MESSAGES_TO_AUTHOR = 'yes'
475 message = cStringIO.StringIO('''Content-Type: text/plain;
476 charset="iso-8859-1"
477 From: john@test
478 To: issue_tracker@your.tracker.email.domain.example
479 Message-Id: <followup_dummy_id>
480 In-Reply-To: <dummy_test_message_id>
481 Subject: [issue1] Testing...
483 This is a followup
484 ''')
485 handler = self.instance.MailGW(self.instance, self.db)
486 handler.trapExceptions = 0
487 handler.main(message)
489 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
490 '''FROM: roundup-admin@your.tracker.email.domain.example
491 TO: chef@bork.bork.bork, john@test, richard@test
492 Content-Type: text/plain
493 Subject: [issue1] Testing...
494 To: chef@bork.bork.bork, john@test, richard@test
495 From: "john" <issue_tracker@your.tracker.email.domain.example>
496 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
497 MIME-Version: 1.0
498 Message-Id: <followup_dummy_id>
499 In-Reply-To: <dummy_test_message_id>
500 X-Roundup-Name: Roundup issue tracker
501 Content-Transfer-Encoding: quoted-printable
504 john <john@test> added the comment:
506 This is a followup
509 ----------
510 nosy: +john
511 status: unread -> chatting
512 _________________________________________________________________________
513 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
514 http://your.tracker.url.example/issue1
515 _________________________________________________________________________
517 ''')
519 def testFollowupNoNosyAuthor(self):
520 self.doNewIssue()
521 self.instance.ADD_AUTHOR_TO_NOSY = 'no'
522 message = cStringIO.StringIO('''Content-Type: text/plain;
523 charset="iso-8859-1"
524 From: john@test
525 To: issue_tracker@your.tracker.email.domain.example
526 Message-Id: <followup_dummy_id>
527 In-Reply-To: <dummy_test_message_id>
528 Subject: [issue1] Testing...
530 This is a followup
531 ''')
532 handler = self.instance.MailGW(self.instance, self.db)
533 handler.trapExceptions = 0
534 handler.main(message)
536 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
537 '''FROM: roundup-admin@your.tracker.email.domain.example
538 TO: chef@bork.bork.bork, richard@test
539 Content-Type: text/plain
540 Subject: [issue1] Testing...
541 To: chef@bork.bork.bork, richard@test
542 From: "john" <issue_tracker@your.tracker.email.domain.example>
543 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
544 MIME-Version: 1.0
545 Message-Id: <followup_dummy_id>
546 In-Reply-To: <dummy_test_message_id>
547 X-Roundup-Name: Roundup issue tracker
548 Content-Transfer-Encoding: quoted-printable
551 john <john@test> added the comment:
553 This is a followup
556 ----------
557 status: unread -> chatting
558 _________________________________________________________________________
559 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
560 http://your.tracker.url.example/issue1
561 _________________________________________________________________________
563 ''')
565 def testFollowupNoNosyRecipients(self):
566 self.doNewIssue()
567 self.instance.ADD_RECIPIENTS_TO_NOSY = 'no'
568 message = cStringIO.StringIO('''Content-Type: text/plain;
569 charset="iso-8859-1"
570 From: richard@test
571 To: issue_tracker@your.tracker.email.domain.example
572 Cc: john@test
573 Message-Id: <followup_dummy_id>
574 In-Reply-To: <dummy_test_message_id>
575 Subject: [issue1] Testing...
577 This is a followup
578 ''')
579 handler = self.instance.MailGW(self.instance, self.db)
580 handler.trapExceptions = 0
581 handler.main(message)
583 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
584 '''FROM: roundup-admin@your.tracker.email.domain.example
585 TO: chef@bork.bork.bork
586 Content-Type: text/plain
587 Subject: [issue1] Testing...
588 To: chef@bork.bork.bork
589 From: "richard" <issue_tracker@your.tracker.email.domain.example>
590 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
591 MIME-Version: 1.0
592 Message-Id: <followup_dummy_id>
593 In-Reply-To: <dummy_test_message_id>
594 X-Roundup-Name: Roundup issue tracker
595 Content-Transfer-Encoding: quoted-printable
598 richard <richard@test> added the comment:
600 This is a followup
603 ----------
604 status: unread -> chatting
605 _________________________________________________________________________
606 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
607 http://your.tracker.url.example/issue1
608 _________________________________________________________________________
610 ''')
612 def testNosyRemove(self):
613 self.doNewIssue()
615 message = cStringIO.StringIO('''Content-Type: text/plain;
616 charset="iso-8859-1"
617 From: richard <richard@test>
618 To: issue_tracker@your.tracker.email.domain.example
619 Message-Id: <followup_dummy_id>
620 In-Reply-To: <dummy_test_message_id>
621 Subject: [issue1] Testing... [nosy=-richard]
623 ''')
624 handler = self.instance.MailGW(self.instance, self.db)
625 handler.trapExceptions = 0
626 handler.main(message)
627 l = self.db.issue.get('1', 'nosy')
628 l.sort()
629 self.assertEqual(l, ['3'])
631 # NO NOSY MESSAGE SHOULD BE SENT!
632 self.assert_(not os.path.exists(os.environ['SENDMAILDEBUG']))
634 def testNewUserAuthor(self):
635 # first without the permission
636 # heh... just ignore the API for a second ;)
637 self.db.security.role['Anonymous'].permissions=[]
638 anonid = self.db.user.lookup('anonymous')
639 self.db.user.set(anonid, roles='Anonymous')
641 self.db.security.hasPermission('Email Registration', anonid)
642 l = self.db.user.list()
643 l.sort()
644 s = '''Content-Type: text/plain;
645 charset="iso-8859-1"
646 From: fubar <fubar@bork.bork.bork>
647 To: issue_tracker@your.tracker.email.domain.example
648 Message-Id: <dummy_test_message_id>
649 Subject: [issue] Testing...
651 This is a test submission of a new issue.
652 '''
653 message = cStringIO.StringIO(s)
654 handler = self.instance.MailGW(self.instance, self.db)
655 handler.trapExceptions = 0
656 self.assertRaises(Unauthorized, handler.main, message)
657 m = self.db.user.list()
658 m.sort()
659 self.assertEqual(l, m)
661 # now with the permission
662 p = self.db.security.getPermission('Email Registration')
663 self.db.security.role['Anonymous'].permissions=[p]
664 handler = self.instance.MailGW(self.instance, self.db)
665 handler.trapExceptions = 0
666 message = cStringIO.StringIO(s)
667 handler.main(message)
668 m = self.db.user.list()
669 m.sort()
670 self.assertNotEqual(l, m)
672 def testEnc01(self):
673 self.doNewIssue()
674 message = cStringIO.StringIO('''Content-Type: text/plain;
675 charset="iso-8859-1"
676 From: mary <mary@test>
677 To: issue_tracker@your.tracker.email.domain.example
678 Message-Id: <followup_dummy_id>
679 In-Reply-To: <dummy_test_message_id>
680 Subject: [issue1] Testing...
681 Content-Type: text/plain;
682 charset="iso-8859-1"
683 Content-Transfer-Encoding: quoted-printable
685 A message with encoding (encoded oe =F6)
687 ''')
688 handler = self.instance.MailGW(self.instance, self.db)
689 handler.trapExceptions = 0
690 handler.main(message)
691 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
692 '''FROM: roundup-admin@your.tracker.email.domain.example
693 TO: chef@bork.bork.bork, richard@test
694 Content-Type: text/plain
695 Subject: [issue1] Testing...
696 To: chef@bork.bork.bork, richard@test
697 From: "mary" <issue_tracker@your.tracker.email.domain.example>
698 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
699 MIME-Version: 1.0
700 Message-Id: <followup_dummy_id>
701 In-Reply-To: <dummy_test_message_id>
702 X-Roundup-Name: Roundup issue tracker
703 Content-Transfer-Encoding: quoted-printable
706 mary <mary@test> added the comment:
708 A message with encoding (encoded oe =F6)
710 ----------
711 status: unread -> chatting
712 _________________________________________________________________________
713 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
714 http://your.tracker.url.example/issue1
715 _________________________________________________________________________
716 ''')
719 def testMultipartEnc01(self):
720 self.doNewIssue()
721 message = cStringIO.StringIO('''Content-Type: text/plain;
722 charset="iso-8859-1"
723 From: mary <mary@test>
724 To: issue_tracker@your.tracker.email.domain.example
725 Message-Id: <followup_dummy_id>
726 In-Reply-To: <dummy_test_message_id>
727 Subject: [issue1] Testing...
728 Content-Type: multipart/mixed;
729 boundary="----_=_NextPart_000_01"
731 This message is in MIME format. Since your mail reader does not understand
732 this format, some or all of this message may not be legible.
734 ------_=_NextPart_000_01
735 Content-Type: text/plain;
736 charset="iso-8859-1"
737 Content-Transfer-Encoding: quoted-printable
739 A message with first part encoded (encoded oe =F6)
741 ''')
742 handler = self.instance.MailGW(self.instance, self.db)
743 handler.trapExceptions = 0
744 handler.main(message)
745 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
746 '''FROM: roundup-admin@your.tracker.email.domain.example
747 TO: chef@bork.bork.bork, richard@test
748 Content-Type: text/plain
749 Subject: [issue1] Testing...
750 To: chef@bork.bork.bork, richard@test
751 From: "mary" <issue_tracker@your.tracker.email.domain.example>
752 Reply-To: "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
753 MIME-Version: 1.0
754 Message-Id: <followup_dummy_id>
755 In-Reply-To: <dummy_test_message_id>
756 X-Roundup-Name: Roundup issue tracker
757 Content-Transfer-Encoding: quoted-printable
760 mary <mary@test> added the comment:
762 A message with first part encoded (encoded oe =F6)
764 ----------
765 status: unread -> chatting
766 _________________________________________________________________________
767 "Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
768 http://your.tracker.url.example/issue1
769 _________________________________________________________________________
770 ''')
772 class ExtMailgwTestCase(MailgwTestCase):
773 schema = 'extended'
775 def suite():
776 l = [unittest.makeSuite(MailgwTestCase),
777 unittest.makeSuite(ExtMailgwTestCase, 'test')
778 ]
779 return unittest.TestSuite(l)
782 #
783 # $Log: not supported by cvs2svn $
784 # Revision 1.24 2002/07/26 08:27:00 richard
785 # Very close now. The cgi and mailgw now use the new security API. The two
786 # templates have been migrated to that setup. Lots of unit tests. Still some
787 # issue in the web form for editing Roles assigned to users.
788 #
789 # Revision 1.23 2002/07/14 02:02:43 richard
790 # Fixed the unit tests for the new multilist controls in the mailgw
791 #
792 # Revision 1.22 2002/07/09 01:21:24 richard
793 # Added ability for unit tests to turn off exception handling in mailgw so
794 # that exceptions are reported earlier (and hence make sense).
795 #
796 # Revision 1.21 2002/06/18 03:59:59 dman13
797 # Updated message strings to match the RFC822 address quoting performed
798 # by the 'email' and 'rfc822' modules. The verification really should
799 # use a RFC2822 message parser rather than literal string comparisions
800 # to allow for legal variations in messages.
801 #
802 # Revision 1.20 2002/05/29 01:16:17 richard
803 # Sorry about this huge checkin! It's fixing a lot of related stuff in one go
804 # though.
805 #
806 # . #541941 ] changing multilink properties by mail
807 # . #526730 ] search for messages capability
808 # . #505180 ] split MailGW.handle_Message
809 # - also changed cgi client since it was duplicating the functionality
810 # . build htmlbase if tests are run using CVS checkout (removed note from
811 # installation.txt)
812 # . don't create an empty message on email issue creation if the email is empty
813 #
814 # Revision 1.19 2002/05/23 04:26:05 richard
815 # 'I must run unit tests before committing\n' * 100
816 #
817 # Revision 1.18 2002/05/15 03:27:16 richard
818 # . fixed SCRIPT_NAME in ZRoundup for instances not at top level of Zope
819 # (thanks dman)
820 # . fixed some sorting issues that were breaking some unit tests under py2.2
821 # . mailgw test output dir was confusing the init test (but only on 2.2 *shrug*)
822 #
823 # fixed bug in the init unit test that meant only the bsddb test ran if it
824 # could (it clobbered the anydbm test)
825 #
826 # Revision 1.17 2002/05/02 07:56:34 richard
827 # . added option to automatically add the authors and recipients of messages
828 # to the nosy lists with the options ADD_AUTHOR_TO_NOSY (default 'new') and
829 # ADD_RECIPIENTS_TO_NOSY (default 'new'). These settings emulate the current
830 # behaviour. Setting them to 'yes' will add the author/recipients to the nosy
831 # on messages that create issues and followup messages.
832 # . added missing documentation for a few of the config option values
833 #
834 # Revision 1.16 2002/03/19 21:58:11 grubert
835 # . for python2.1 test_mailgw compareString allows an extra trailing empty line (for quopri.
836 #
837 # Revision 1.15 2002/03/19 06:37:00 richard
838 # Made the email checking spit out a diff - much easier to spot the problem!
839 #
840 # Revision 1.14 2002/03/18 18:32:00 rochecompaan
841 # All messages sent to the nosy list are now encoded as quoted-printable.
842 #
843 # Revision 1.13 2002/02/15 07:08:45 richard
844 # . Alternate email addresses are now available for users. See the MIGRATION
845 # file for info on how to activate the feature.
846 #
847 # Revision 1.12 2002/02/15 00:13:38 richard
848 # . #503204 ] mailgw needs a default class
849 # - partially done - the setting of additional properties can wait for a
850 # better configuration system.
851 #
852 # Revision 1.11 2002/02/14 23:38:12 richard
853 # Fixed the unit tests for the mailgw re: the x-roundup-name header.
854 # Also made the test runner more user-friendly:
855 # ./run_tests - detect all tests in test/test_<name>.py and run them
856 # ./run_tests <name> - run only test/test_<name>.py
857 # eg ./run_tests mailgw - run the mailgw test from test/test_mailgw.py
858 #
859 # Revision 1.10 2002/02/12 08:08:55 grubert
860 # . Clean up mail handling, multipart handling.
861 #
862 # Revision 1.9 2002/02/05 14:15:29 grubert
863 # . respect encodings in non multipart messages.
864 #
865 # Revision 1.8 2002/02/04 09:40:21 grubert
866 # . add test for multipart messages with first part being encoded.
867 #
868 # Revision 1.7 2002/01/22 11:54:45 rochecompaan
869 # Fixed status change in mail gateway.
870 #
871 # Revision 1.6 2002/01/21 10:05:48 rochecompaan
872 # Feature:
873 # . the mail gateway now responds with an error message when invalid
874 # values for arguments are specified for link or multilink properties
875 # . modified unit test to check nosy and assignedto when specified as
876 # arguments
877 #
878 # Fixed:
879 # . fixed setting nosy as argument in subject line
880 #
881 # Revision 1.5 2002/01/15 00:12:40 richard
882 # #503340 ] creating issue with [asignedto=p.ohly]
883 #
884 # Revision 1.4 2002/01/14 07:12:15 richard
885 # removed file writing from tests...
886 #
887 # Revision 1.3 2002/01/14 02:20:15 richard
888 # . changed all config accesses so they access either the instance or the
889 # config attriubute on the db. This means that all config is obtained from
890 # instance_config instead of the mish-mash of classes. This will make
891 # switching to a ConfigParser setup easier too, I hope.
892 #
893 # At a minimum, this makes migration a _little_ easier (a lot easier in the
894 # 0.5.0 switch, I hope!)
895 #
896 # Revision 1.2 2002/01/11 23:22:29 richard
897 # . #502437 ] rogue reactor and unittest
898 # in short, the nosy reactor was modifying the nosy list. That code had
899 # been there for a long time, and I suspsect it was there because we
900 # weren't generating the nosy list correctly in other places of the code.
901 # We're now doing that, so the nosy-modifying code can go away from the
902 # nosy reactor.
903 #
904 # Revision 1.1 2002/01/02 02:31:38 richard
905 # Sorry for the huge checkin message - I was only intending to implement #496356
906 # but I found a number of places where things had been broken by transactions:
907 # . modified ROUNDUPDBSENDMAILDEBUG to be SENDMAILDEBUG and hold a filename
908 # for _all_ roundup-generated smtp messages to be sent to.
909 # . the transaction cache had broken the roundupdb.Class set() reactors
910 # . newly-created author users in the mailgw weren't being committed to the db
911 #
912 # Stuff that made it into CHANGES.txt (ie. the stuff I was actually working
913 # on when I found that stuff :):
914 # . #496356 ] Use threading in messages
915 # . detectors were being registered multiple times
916 # . added tests for mailgw
917 # . much better attaching of erroneous messages in the mail gateway
918 #
919 #
920 #
921 #
922 # vim: set filetype=python ts=4 sw=4 et si