e1a750858d01bd863cfe125a2c59c8abc4053db4
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.10 2002-02-12 08:08:55 grubert 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>
91 New submission from Chef <chef@bork.bork.bork>:
93 This is a test submission of a new issue.
96 ----------
97 assignedto: richard
98 messages: 1
99 nosy: mary, Chef, richard
100 status: unread
101 title: Testing...
102 ___________________________________________________
103 "Roundup issue tracker" <issue_tracker@fill.me.in.>
104 http://some.useful.url/issue1
105 ___________________________________________________
106 ''')
108 # BUG
109 # def testMultipart(self):
110 # '''With more than one part'''
111 # see MultipartEnc tests: but if there is more than one part
112 # we return a multipart/mixed and the boundary contains
113 # the ip address of the test machine.
115 # BUG should test some binary attamchent too.
117 def testFollowup(self):
118 self.testNewIssue()
119 message = cStringIO.StringIO('''Content-Type: text/plain;
120 charset="iso-8859-1"
121 From: richard <richard@test>
122 To: issue_tracker@fill.me.in.
123 Message-Id: <followup_dummy_id>
124 In-Reply-To: <dummy_test_message_id>
125 Subject: [issue1] Testing... [assignedto=mary; nosy=john]
127 This is a followup
128 ''')
129 handler = self.instance.MailGW(self.instance, self.db)
130 handler.main(message)
132 self.assertEqual(open(os.environ['SENDMAILDEBUG']).read(),
133 '''FROM: roundup-admin@fill.me.in.
134 TO: chef@bork.bork.bork, mary@test, john@test
135 Content-Type: text/plain
136 Subject: [issue1] Testing...
137 To: chef@bork.bork.bork, mary@test, john@test
138 From: richard <issue_tracker@fill.me.in.>
139 Reply-To: Roundup issue tracker <issue_tracker@fill.me.in.>
140 MIME-Version: 1.0
141 Message-Id: <followup_dummy_id>
142 In-Reply-To: <dummy_test_message_id>
145 richard <richard@test> added the comment:
147 This is a followup
150 ----------
151 assignedto: -> mary
152 nosy: +mary, john
153 status: unread -> chatting
154 ___________________________________________________
155 "Roundup issue tracker" <issue_tracker@fill.me.in.>
156 http://some.useful.url/issue1
157 ___________________________________________________
158 ''', 'Generated message not correct')
160 def testFollowup2(self):
161 self.testNewIssue()
162 message = cStringIO.StringIO('''Content-Type: text/plain;
163 charset="iso-8859-1"
164 From: mary <mary@test>
165 To: issue_tracker@fill.me.in.
166 Message-Id: <followup_dummy_id>
167 In-Reply-To: <dummy_test_message_id>
168 Subject: [issue1] Testing...
170 This is a second followup
171 ''')
172 handler = self.instance.MailGW(self.instance, self.db)
173 handler.main(message)
174 self.assertEqual(open(os.environ['SENDMAILDEBUG']).read(),
175 '''FROM: roundup-admin@fill.me.in.
176 TO: chef@bork.bork.bork, richard@test
177 Content-Type: text/plain
178 Subject: [issue1] Testing...
179 To: chef@bork.bork.bork, richard@test
180 From: mary <issue_tracker@fill.me.in.>
181 Reply-To: Roundup issue tracker <issue_tracker@fill.me.in.>
182 MIME-Version: 1.0
183 Message-Id: <followup_dummy_id>
184 In-Reply-To: <dummy_test_message_id>
187 mary <mary@test> added the comment:
189 This is a second followup
192 ----------
193 status: unread -> chatting
194 ___________________________________________________
195 "Roundup issue tracker" <issue_tracker@fill.me.in.>
196 http://some.useful.url/issue1
197 ___________________________________________________
198 ''', 'Generated message not correct')
200 def testEnc01(self):
201 self.testNewIssue()
202 message = cStringIO.StringIO('''Content-Type: text/plain;
203 charset="iso-8859-1"
204 From: mary <mary@test>
205 To: issue_tracker@fill.me.in.
206 Message-Id: <followup_dummy_id>
207 In-Reply-To: <dummy_test_message_id>
208 Subject: [issue1] Testing...
209 Content-Type: text/plain;
210 charset="iso-8859-1"
211 Content-Transfer-Encoding: quoted-printable
213 A message with encoding (encoded oe =F6)
215 ''')
216 handler = self.instance.MailGW(self.instance, self.db)
217 handler.main(message)
218 message_data = open(os.environ['SENDMAILDEBUG']).read()
219 self.assertEqual(message_data,
220 '''FROM: roundup-admin@fill.me.in.
221 TO: chef@bork.bork.bork, richard@test
222 Content-Type: text/plain
223 Subject: [issue1] Testing...
224 To: chef@bork.bork.bork, richard@test
225 From: mary <issue_tracker@fill.me.in.>
226 Reply-To: Roundup issue tracker <issue_tracker@fill.me.in.>
227 MIME-Version: 1.0
228 Message-Id: <followup_dummy_id>
229 In-Reply-To: <dummy_test_message_id>
232 mary <mary@test> added the comment:
234 A message with encoding (encoded oe ö)
236 ----------
237 status: unread -> chatting
238 ___________________________________________________
239 "Roundup issue tracker" <issue_tracker@fill.me.in.>
240 http://some.useful.url/issue1
241 ___________________________________________________
242 ''', 'Generated message not correct')
245 def testMultipartEnc01(self):
246 self.testNewIssue()
247 message = cStringIO.StringIO('''Content-Type: text/plain;
248 charset="iso-8859-1"
249 From: mary <mary@test>
250 To: issue_tracker@fill.me.in.
251 Message-Id: <followup_dummy_id>
252 In-Reply-To: <dummy_test_message_id>
253 Subject: [issue1] Testing...
254 Content-Type: multipart/mixed;
255 boundary="----_=_NextPart_000_01"
257 This message is in MIME format. Since your mail reader does not understand
258 this format, some or all of this message may not be legible.
260 ------_=_NextPart_000_01
261 Content-Type: text/plain;
262 charset="iso-8859-1"
263 Content-Transfer-Encoding: quoted-printable
265 A message with first part encoded (encoded oe =F6)
267 ''')
268 handler = self.instance.MailGW(self.instance, self.db)
269 handler.main(message)
270 message_data = open(os.environ['SENDMAILDEBUG']).read()
271 self.assertEqual(message_data,
272 '''FROM: roundup-admin@fill.me.in.
273 TO: chef@bork.bork.bork, richard@test
274 Content-Type: text/plain
275 Subject: [issue1] Testing...
276 To: chef@bork.bork.bork, richard@test
277 From: mary <issue_tracker@fill.me.in.>
278 Reply-To: Roundup issue tracker <issue_tracker@fill.me.in.>
279 MIME-Version: 1.0
280 Message-Id: <followup_dummy_id>
281 In-Reply-To: <dummy_test_message_id>
284 mary <mary@test> added the comment:
286 A message with first part encoded (encoded oe ö)
288 ----------
289 status: unread -> chatting
290 ___________________________________________________
291 "Roundup issue tracker" <issue_tracker@fill.me.in.>
292 http://some.useful.url/issue1
293 ___________________________________________________
294 ''', 'Generated message not correct')
296 class ExtMailgwTestCase(MailgwTestCase):
297 schema = 'extended'
299 def suite():
300 l = [unittest.makeSuite(MailgwTestCase, 'test'),
301 unittest.makeSuite(ExtMailgwTestCase, 'test')
302 ]
303 return unittest.TestSuite(l)
306 #
307 # $Log: not supported by cvs2svn $
308 # Revision 1.9 2002/02/05 14:15:29 grubert
309 # . respect encodings in non multipart messages.
310 #
311 # Revision 1.8 2002/02/04 09:40:21 grubert
312 # . add test for multipart messages with first part being encoded.
313 #
314 # Revision 1.7 2002/01/22 11:54:45 rochecompaan
315 # Fixed status change in mail gateway.
316 #
317 # Revision 1.6 2002/01/21 10:05:48 rochecompaan
318 # Feature:
319 # . the mail gateway now responds with an error message when invalid
320 # values for arguments are specified for link or multilink properties
321 # . modified unit test to check nosy and assignedto when specified as
322 # arguments
323 #
324 # Fixed:
325 # . fixed setting nosy as argument in subject line
326 #
327 # Revision 1.5 2002/01/15 00:12:40 richard
328 # #503340 ] creating issue with [asignedto=p.ohly]
329 #
330 # Revision 1.4 2002/01/14 07:12:15 richard
331 # removed file writing from tests...
332 #
333 # Revision 1.3 2002/01/14 02:20:15 richard
334 # . changed all config accesses so they access either the instance or the
335 # config attriubute on the db. This means that all config is obtained from
336 # instance_config instead of the mish-mash of classes. This will make
337 # switching to a ConfigParser setup easier too, I hope.
338 #
339 # At a minimum, this makes migration a _little_ easier (a lot easier in the
340 # 0.5.0 switch, I hope!)
341 #
342 # Revision 1.2 2002/01/11 23:22:29 richard
343 # . #502437 ] rogue reactor and unittest
344 # in short, the nosy reactor was modifying the nosy list. That code had
345 # been there for a long time, and I suspsect it was there because we
346 # weren't generating the nosy list correctly in other places of the code.
347 # We're now doing that, so the nosy-modifying code can go away from the
348 # nosy reactor.
349 #
350 # Revision 1.1 2002/01/02 02:31:38 richard
351 # Sorry for the huge checkin message - I was only intending to implement #496356
352 # but I found a number of places where things had been broken by transactions:
353 # . modified ROUNDUPDBSENDMAILDEBUG to be SENDMAILDEBUG and hold a filename
354 # for _all_ roundup-generated smtp messages to be sent to.
355 # . the transaction cache had broken the roundupdb.Class set() reactors
356 # . newly-created author users in the mailgw weren't being committed to the db
357 #
358 # Stuff that made it into CHANGES.txt (ie. the stuff I was actually working
359 # on when I found that stuff :):
360 # . #496356 ] Use threading in messages
361 # . detectors were being registered multiple times
362 # . added tests for mailgw
363 # . much better attaching of erroneous messages in the mail gateway
364 #
365 #
366 #
367 #
368 # vim: set filetype=python ts=4 sw=4 et si