Code

Fixed the unit tests for the mailgw re: the x-roundup-name header.
[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.11 2002-02-14 23:38:12 richard Exp $
13 import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys
15 from roundup.mailgw import MailGW
16 from roundup import init, instance
18 class MailgwTestCase(unittest.TestCase):
19     count = 0
20     schema = 'classic'
21     def setUp(self):
22         MailgwTestCase.count = MailgwTestCase.count + 1
23         self.dirname = '_test_%s'%self.count
24         try:
25             shutil.rmtree(self.dirname)
26         except OSError, error:
27             if error.errno not in (errno.ENOENT, errno.ESRCH): raise
28         # create the instance
29         init.init(self.dirname, self.schema, 'anydbm', 'sekrit')
30         # check we can load the package
31         self.instance = instance.open(self.dirname)
32         # and open the database
33         self.db = self.instance.open('sekrit')
34         self.db.user.create(username='Chef', address='chef@bork.bork.bork')
35         self.db.user.create(username='richard', address='richard@test')
36         self.db.user.create(username='mary', address='mary@test')
37         self.db.user.create(username='john', address='john@test')
39     def tearDown(self):
40         if os.path.exists(os.environ['SENDMAILDEBUG']):
41             os.remove(os.environ['SENDMAILDEBUG'])
42         try:
43             shutil.rmtree(self.dirname)
44         except OSError, error:
45             if error.errno not in (errno.ENOENT, errno.ESRCH): raise
47     def testNewIssue(self):
48         message = cStringIO.StringIO('''Content-Type: text/plain;
49   charset="iso-8859-1"
50 From: Chef <chef@bork.bork.bork
51 To: issue_tracker@fill.me.in.
52 Cc: richard@test
53 Message-Id: <dummy_test_message_id>
54 Subject: [issue] Testing...
56 This is a test submission of a new issue.
57 ''')
58         handler = self.instance.MailGW(self.instance, self.db)
59         handler.main(message)
60         if os.path.exists(os.environ['SENDMAILDEBUG']):
61             error = open(os.environ['SENDMAILDEBUG']).read()
62             self.assertEqual('no error', error)
64     def testNewIssueAuthMsg(self):
65         message = cStringIO.StringIO('''Content-Type: text/plain;
66   charset="iso-8859-1"
67 From: Chef <chef@bork.bork.bork
68 To: issue_tracker@fill.me.in.
69 Message-Id: <dummy_test_message_id>
70 Subject: [issue] Testing... [nosy=mary; assignedto=richard]
72 This is a test submission of a new issue.
73 ''')
74         handler = self.instance.MailGW(self.instance, self.db)
75         # TODO: fix the damn config - this is apalling
76         self.db.config.MESSAGES_TO_AUTHOR = 'yes'
77         handler.main(message)
79         self.assertEqual(open(os.environ['SENDMAILDEBUG']).read(),
80 '''FROM: roundup-admin@fill.me.in.
81 TO: chef@bork.bork.bork, mary@test, richard@test
82 Content-Type: text/plain
83 Subject: [issue1] Testing...
84 To: chef@bork.bork.bork, mary@test, richard@test
85 From: Chef <issue_tracker@fill.me.in.>
86 Reply-To: Roundup issue tracker <issue_tracker@fill.me.in.>
87 MIME-Version: 1.0
88 Message-Id: <dummy_test_message_id>
89 X-Roundup-Name: Roundup issue tracker
92 New submission from Chef <chef@bork.bork.bork>:
94 This is a test submission of a new issue.
97 ----------
98 assignedto: richard
99 messages: 1
100 nosy: mary, Chef, richard
101 status: unread
102 title: Testing...
103 ___________________________________________________
104 "Roundup issue tracker" <issue_tracker@fill.me.in.>
105 http://some.useful.url/issue1
106 ___________________________________________________
107 ''')
109     # BUG
110     # def testMultipart(self):
111     #   '''With more than one part'''
112     #   see MultipartEnc tests: but if there is more than one part
113     #   we return a multipart/mixed and the boundary contains
114     #   the ip address of the test machine. 
116     # BUG should test some binary attamchent too.
118     def testFollowup(self):
119         self.testNewIssue()
120         message = cStringIO.StringIO('''Content-Type: text/plain;
121   charset="iso-8859-1"
122 From: richard <richard@test>
123 To: issue_tracker@fill.me.in.
124 Message-Id: <followup_dummy_id>
125 In-Reply-To: <dummy_test_message_id>
126 Subject: [issue1] Testing... [assignedto=mary; nosy=john]
128 This is a followup
129 ''')
130         handler = self.instance.MailGW(self.instance, self.db)
131         handler.main(message)
133         self.assertEqual(open(os.environ['SENDMAILDEBUG']).read(),
134 '''FROM: roundup-admin@fill.me.in.
135 TO: chef@bork.bork.bork, mary@test, john@test
136 Content-Type: text/plain
137 Subject: [issue1] Testing...
138 To: chef@bork.bork.bork, mary@test, john@test
139 From: richard <issue_tracker@fill.me.in.>
140 Reply-To: Roundup issue tracker <issue_tracker@fill.me.in.>
141 MIME-Version: 1.0
142 Message-Id: <followup_dummy_id>
143 In-Reply-To: <dummy_test_message_id>
144 X-Roundup-Name: Roundup issue tracker
147 richard <richard@test> added the comment:
149 This is a followup
152 ----------
153 assignedto:  -> mary
154 nosy: +mary, john
155 status: unread -> chatting
156 ___________________________________________________
157 "Roundup issue tracker" <issue_tracker@fill.me.in.>
158 http://some.useful.url/issue1
159 ___________________________________________________
160 ''', 'Generated message not correct')
162     def testFollowup2(self):
163         self.testNewIssue()
164         message = cStringIO.StringIO('''Content-Type: text/plain;
165   charset="iso-8859-1"
166 From: mary <mary@test>
167 To: issue_tracker@fill.me.in.
168 Message-Id: <followup_dummy_id>
169 In-Reply-To: <dummy_test_message_id>
170 Subject: [issue1] Testing...
172 This is a second followup
173 ''')
174         handler = self.instance.MailGW(self.instance, self.db)
175         handler.main(message)
176         self.assertEqual(open(os.environ['SENDMAILDEBUG']).read(),
177 '''FROM: roundup-admin@fill.me.in.
178 TO: chef@bork.bork.bork, richard@test
179 Content-Type: text/plain
180 Subject: [issue1] Testing...
181 To: chef@bork.bork.bork, richard@test
182 From: mary <issue_tracker@fill.me.in.>
183 Reply-To: Roundup issue tracker <issue_tracker@fill.me.in.>
184 MIME-Version: 1.0
185 Message-Id: <followup_dummy_id>
186 In-Reply-To: <dummy_test_message_id>
187 X-Roundup-Name: Roundup issue tracker
190 mary <mary@test> added the comment:
192 This is a second followup
195 ----------
196 status: unread -> chatting
197 ___________________________________________________
198 "Roundup issue tracker" <issue_tracker@fill.me.in.>
199 http://some.useful.url/issue1
200 ___________________________________________________
201 ''', 'Generated message not correct')
203     def testEnc01(self):
204         self.testNewIssue()
205         message = cStringIO.StringIO('''Content-Type: text/plain;
206   charset="iso-8859-1"
207 From: mary <mary@test>
208 To: issue_tracker@fill.me.in.
209 Message-Id: <followup_dummy_id>
210 In-Reply-To: <dummy_test_message_id>
211 Subject: [issue1] Testing...
212 Content-Type: text/plain;
213         charset="iso-8859-1"
214 Content-Transfer-Encoding: quoted-printable
216 A message with encoding (encoded oe =F6)
218 ''')
219         handler = self.instance.MailGW(self.instance, self.db)
220         handler.main(message)
221         message_data = open(os.environ['SENDMAILDEBUG']).read()
222         self.assertEqual(message_data,
223 '''FROM: roundup-admin@fill.me.in.
224 TO: chef@bork.bork.bork, richard@test
225 Content-Type: text/plain
226 Subject: [issue1] Testing...
227 To: chef@bork.bork.bork, richard@test
228 From: mary <issue_tracker@fill.me.in.>
229 Reply-To: Roundup issue tracker <issue_tracker@fill.me.in.>
230 MIME-Version: 1.0
231 Message-Id: <followup_dummy_id>
232 In-Reply-To: <dummy_test_message_id>
233 X-Roundup-Name: Roundup issue tracker
236 mary <mary@test> added the comment:
238 A message with encoding (encoded oe ö)
240 ----------
241 status: unread -> chatting
242 ___________________________________________________
243 "Roundup issue tracker" <issue_tracker@fill.me.in.>
244 http://some.useful.url/issue1
245 ___________________________________________________
246 ''', 'Generated message not correct')
249     def testMultipartEnc01(self):
250         self.testNewIssue()
251         message = cStringIO.StringIO('''Content-Type: text/plain;
252   charset="iso-8859-1"
253 From: mary <mary@test>
254 To: issue_tracker@fill.me.in.
255 Message-Id: <followup_dummy_id>
256 In-Reply-To: <dummy_test_message_id>
257 Subject: [issue1] Testing...
258 Content-Type: multipart/mixed;
259         boundary="----_=_NextPart_000_01"
261 This message is in MIME format. Since your mail reader does not understand
262 this format, some or all of this message may not be legible.
264 ------_=_NextPart_000_01
265 Content-Type: text/plain;
266         charset="iso-8859-1"
267 Content-Transfer-Encoding: quoted-printable
269 A message with first part encoded (encoded oe =F6)
271 ''')
272         handler = self.instance.MailGW(self.instance, self.db)
273         handler.main(message)
274         message_data = open(os.environ['SENDMAILDEBUG']).read()
275         self.assertEqual(message_data,
276 '''FROM: roundup-admin@fill.me.in.
277 TO: chef@bork.bork.bork, richard@test
278 Content-Type: text/plain
279 Subject: [issue1] Testing...
280 To: chef@bork.bork.bork, richard@test
281 From: mary <issue_tracker@fill.me.in.>
282 Reply-To: Roundup issue tracker <issue_tracker@fill.me.in.>
283 MIME-Version: 1.0
284 Message-Id: <followup_dummy_id>
285 In-Reply-To: <dummy_test_message_id>
286 X-Roundup-Name: Roundup issue tracker
289 mary <mary@test> added the comment:
291 A message with first part encoded (encoded oe ö)
293 ----------
294 status: unread -> chatting
295 ___________________________________________________
296 "Roundup issue tracker" <issue_tracker@fill.me.in.>
297 http://some.useful.url/issue1
298 ___________________________________________________
299 ''', 'Generated message not correct')
301 class ExtMailgwTestCase(MailgwTestCase):
302     schema = 'extended'
304 def suite():
305     l = [unittest.makeSuite(MailgwTestCase, 'test'),
306         unittest.makeSuite(ExtMailgwTestCase, 'test')
307     ]
308     return unittest.TestSuite(l)
312 # $Log: not supported by cvs2svn $
313 # Revision 1.10  2002/02/12 08:08:55  grubert
314 #  . Clean up mail handling, multipart handling.
316 # Revision 1.9  2002/02/05 14:15:29  grubert
317 #  . respect encodings in non multipart messages.
319 # Revision 1.8  2002/02/04 09:40:21  grubert
320 #  . add test for multipart messages with first part being encoded.
322 # Revision 1.7  2002/01/22 11:54:45  rochecompaan
323 # Fixed status change in mail gateway.
325 # Revision 1.6  2002/01/21 10:05:48  rochecompaan
326 # Feature:
327 #  . the mail gateway now responds with an error message when invalid
328 #    values for arguments are specified for link or multilink properties
329 #  . modified unit test to check nosy and assignedto when specified as
330 #    arguments
332 # Fixed:
333 #  . fixed setting nosy as argument in subject line
335 # Revision 1.5  2002/01/15 00:12:40  richard
336 # #503340 ] creating issue with [asignedto=p.ohly]
338 # Revision 1.4  2002/01/14 07:12:15  richard
339 # removed file writing from tests...
341 # Revision 1.3  2002/01/14 02:20:15  richard
342 #  . changed all config accesses so they access either the instance or the
343 #    config attriubute on the db. This means that all config is obtained from
344 #    instance_config instead of the mish-mash of classes. This will make
345 #    switching to a ConfigParser setup easier too, I hope.
347 # At a minimum, this makes migration a _little_ easier (a lot easier in the
348 # 0.5.0 switch, I hope!)
350 # Revision 1.2  2002/01/11 23:22:29  richard
351 #  . #502437 ] rogue reactor and unittest
352 #    in short, the nosy reactor was modifying the nosy list. That code had
353 #    been there for a long time, and I suspsect it was there because we
354 #    weren't generating the nosy list correctly in other places of the code.
355 #    We're now doing that, so the nosy-modifying code can go away from the
356 #    nosy reactor.
358 # Revision 1.1  2002/01/02 02:31:38  richard
359 # Sorry for the huge checkin message - I was only intending to implement #496356
360 # but I found a number of places where things had been broken by transactions:
361 #  . modified ROUNDUPDBSENDMAILDEBUG to be SENDMAILDEBUG and hold a filename
362 #    for _all_ roundup-generated smtp messages to be sent to.
363 #  . the transaction cache had broken the roundupdb.Class set() reactors
364 #  . newly-created author users in the mailgw weren't being committed to the db
366 # Stuff that made it into CHANGES.txt (ie. the stuff I was actually working
367 # on when I found that stuff :):
368 #  . #496356 ] Use threading in messages
369 #  . detectors were being registered multiple times
370 #  . added tests for mailgw
371 #  . much better attaching of erroneous messages in the mail gateway
376 # vim: set filetype=python ts=4 sw=4 et si