cbaf7a5852cc8ec59fdfbd36bf35543fb38d7275
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.4 2002-01-14 07:12:15 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...
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
82 Content-Type: text/plain
83 Subject: [issue1] Testing...
84 To: chef@bork.bork.bork
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.
95 ___________________________________________________
96 "Roundup issue tracker" <issue_tracker@fill.me.in.>
97 http://some.useful.url/issue1
98 ___________________________________________________
99 ''', 'Generated message not correct')
101 def testFollowup(self):
102 self.testNewIssue()
103 message = cStringIO.StringIO('''Content-Type: text/plain;
104 charset="iso-8859-1"
105 From: richard <richard@test>
106 To: issue_tracker@fill.me.in.
107 Message-Id: <followup_dummy_id>
108 In-Reply-To: <dummy_test_message_id>
109 Subject: [issue1] Testing...
111 This is a followup
112 ''')
113 handler = self.instance.MailGW(self.instance, self.db)
114 # TODO: fix the damn config - this is apalling
115 handler.main(message)
117 self.assertEqual(open(os.environ['SENDMAILDEBUG']).read(),
118 '''FROM: roundup-admin@fill.me.in.
119 TO: chef@bork.bork.bork
120 Content-Type: text/plain
121 Subject: [issue1] Testing...
122 To: chef@bork.bork.bork
123 From: richard <issue_tracker@fill.me.in.>
124 Reply-To: Roundup issue tracker <issue_tracker@fill.me.in.>
125 MIME-Version: 1.0
126 Message-Id: <followup_dummy_id>
127 In-Reply-To: <dummy_test_message_id>
130 richard <richard@test> added the comment:
132 This is a followup
134 ___________________________________________________
135 "Roundup issue tracker" <issue_tracker@fill.me.in.>
136 http://some.useful.url/issue1
137 ___________________________________________________
138 ''', 'Generated message not correct')
140 def testFollowup2(self):
141 self.testNewIssue()
142 message = cStringIO.StringIO('''Content-Type: text/plain;
143 charset="iso-8859-1"
144 From: mary <mary@test>
145 To: issue_tracker@fill.me.in.
146 Message-Id: <followup_dummy_id>
147 In-Reply-To: <dummy_test_message_id>
148 Subject: [issue1] Testing...
150 This is a second followup
151 ''')
152 handler = self.instance.MailGW(self.instance, self.db)
153 # TODO: fix the damn config - this is apalling
154 handler.main(message)
155 self.assertEqual(open(os.environ['SENDMAILDEBUG']).read(),
156 '''FROM: roundup-admin@fill.me.in.
157 TO: chef@bork.bork.bork, richard@test
158 Content-Type: text/plain
159 Subject: [issue1] Testing...
160 To: chef@bork.bork.bork, richard@test
161 From: mary <issue_tracker@fill.me.in.>
162 Reply-To: Roundup issue tracker <issue_tracker@fill.me.in.>
163 MIME-Version: 1.0
164 Message-Id: <followup_dummy_id>
165 In-Reply-To: <dummy_test_message_id>
168 mary <mary@test> added the comment:
170 This is a second followup
172 ___________________________________________________
173 "Roundup issue tracker" <issue_tracker@fill.me.in.>
174 http://some.useful.url/issue1
175 ___________________________________________________
176 ''', 'Generated message not correct')
178 class ExtMailgwTestCase(MailgwTestCase):
179 schema = 'extended'
181 def suite():
182 l = [unittest.makeSuite(MailgwTestCase, 'test'),
183 unittest.makeSuite(ExtMailgwTestCase, 'test')]
184 return unittest.TestSuite(l)
187 #
188 # $Log: not supported by cvs2svn $
189 # Revision 1.3 2002/01/14 02:20:15 richard
190 # . changed all config accesses so they access either the instance or the
191 # config attriubute on the db. This means that all config is obtained from
192 # instance_config instead of the mish-mash of classes. This will make
193 # switching to a ConfigParser setup easier too, I hope.
194 #
195 # At a minimum, this makes migration a _little_ easier (a lot easier in the
196 # 0.5.0 switch, I hope!)
197 #
198 # Revision 1.2 2002/01/11 23:22:29 richard
199 # . #502437 ] rogue reactor and unittest
200 # in short, the nosy reactor was modifying the nosy list. That code had
201 # been there for a long time, and I suspsect it was there because we
202 # weren't generating the nosy list correctly in other places of the code.
203 # We're now doing that, so the nosy-modifying code can go away from the
204 # nosy reactor.
205 #
206 # Revision 1.1 2002/01/02 02:31:38 richard
207 # Sorry for the huge checkin message - I was only intending to implement #496356
208 # but I found a number of places where things had been broken by transactions:
209 # . modified ROUNDUPDBSENDMAILDEBUG to be SENDMAILDEBUG and hold a filename
210 # for _all_ roundup-generated smtp messages to be sent to.
211 # . the transaction cache had broken the roundupdb.Class set() reactors
212 # . newly-created author users in the mailgw weren't being committed to the db
213 #
214 # Stuff that made it into CHANGES.txt (ie. the stuff I was actually working
215 # on when I found that stuff :):
216 # . #496356 ] Use threading in messages
217 # . detectors were being registered multiple times
218 # . added tests for mailgw
219 # . much better attaching of erroneous messages in the mail gateway
220 #
221 #
222 #
223 #
224 # vim: set filetype=python ts=4 sw=4 et si