comparison test/test_mailgw.py @ 4468:502a1a8620e6

Tests and fixes. - Factor MailGW message parsing into a separate class, thanks to John Kristensen who did the major work in issue2550576 -- I wouldn't have attempted it without this. Fixes issue2550576. (Ralf) - Now if the -C option to roundup-mailgw specifies "issue" this refers to an issue-like class. The real class is determined from the configured default class, or the -c option to the mailgw, or the class resulting from mail subject parsing. We also accept multiple -S options for the same class now. (Ralf) - Add regression test for message-id generation if message id is missing in a message - Add regression tests for Option parsing (-S and -C options)
author Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
date Thu, 23 Dec 2010 15:42:30 +0000
parents f1affb6b7a08
children e7dcec8c40e9
comparison
equal deleted inserted replaced
4467:e46b15b0bc25 4468:502a1a8620e6
147 roundupdb._ = mailgw._ = self.old_translate_ 147 roundupdb._ = mailgw._ = self.old_translate_
148 if os.path.exists(SENDMAILDEBUG): 148 if os.path.exists(SENDMAILDEBUG):
149 os.remove(SENDMAILDEBUG) 149 os.remove(SENDMAILDEBUG)
150 self.db.close() 150 self.db.close()
151 151
152 def _create_mailgw(self, message): 152 def _create_mailgw(self, message, args=()):
153 class MailGW(self.instance.MailGW): 153 class MailGW(self.instance.MailGW):
154 def handle_message(self, message): 154 def handle_message(self, message):
155 return self._handle_message(message) 155 return self._handle_message(message)
156 handler = MailGW(self.instance) 156 handler = MailGW(self.instance, args)
157 handler.db = self.db 157 handler.db = self.db
158 return handler 158 return handler
159 159
160 def _handle_mail(self, message): 160 def _handle_mail(self, message, args=()):
161 handler = self._create_mailgw(message) 161 handler = self._create_mailgw(message, args)
162 handler.trapExceptions = 0 162 handler.trapExceptions = 0
163 return handler.main(StringIO(message)) 163 return handler.main(StringIO(message))
164 164
165 def _get_mail(self): 165 def _get_mail(self):
166 f = open(SENDMAILDEBUG) 166 f = open(SENDMAILDEBUG)
196 From here to there! 196 From here to there!
197 ''') 197 ''')
198 assert not os.path.exists(SENDMAILDEBUG) 198 assert not os.path.exists(SENDMAILDEBUG)
199 msgid = self.db.issue.get(nodeid, 'messages')[0] 199 msgid = self.db.issue.get(nodeid, 'messages')[0]
200 self.assertEqual(self.db.msg.get(msgid, 'content'), 'From here to there!') 200 self.assertEqual(self.db.msg.get(msgid, 'content'), 'From here to there!')
201
202 def testNoMessageId(self):
203 self.instance.config['MAIL_DOMAIN'] = 'example.com'
204 nodeid = self._handle_mail('''Content-Type: text/plain;
205 charset="iso-8859-1"
206 From: Chef <chef@bork.bork.bork>
207 To: issue_tracker@your.tracker.email.domain.example
208 Cc: richard@test.test
209 Reply-To: chef@bork.bork.bork
210 Subject: [issue] Testing...
211
212 Hi there!
213 ''')
214 assert not os.path.exists(SENDMAILDEBUG)
215 msgid = self.db.issue.get(nodeid, 'messages')[0]
216 messageid = self.db.msg.get(msgid, 'messageid')
217 x1, x2 = messageid.split('@')
218 self.assertEqual(x2, 'example.com>')
219 x = x1.split('.')[-1]
220 self.assertEqual(x, 'issueNone')
221 nodeid = self._handle_mail('''Content-Type: text/plain;
222 charset="iso-8859-1"
223 From: Chef <chef@bork.bork.bork>
224 To: issue_tracker@your.tracker.email.domain.example
225 Subject: [issue%(nodeid)s] Testing...
226
227 Just a test reply
228 '''%locals())
229 msgid = self.db.issue.get(nodeid, 'messages')[-1]
230 messageid = self.db.msg.get(msgid, 'messageid')
231 x1, x2 = messageid.split('@')
232 self.assertEqual(x2, 'example.com>')
233 x = x1.split('.')[-1]
234 self.assertEqual(x, "issue%s"%nodeid)
235
236 def testOptions(self):
237 nodeid = self._handle_mail('''Content-Type: text/plain;
238 charset="iso-8859-1"
239 From: Chef <chef@bork.bork.bork>
240 To: issue_tracker@your.tracker.email.domain.example
241 Message-Id: <dummy_test_message_id>
242 Reply-To: chef@bork.bork.bork
243 Subject: [issue] Testing...
244
245 Hi there!
246 ''', (('-C', 'issue'), ('-S', 'status=chatting;priority=critical')))
247 self.assertEqual(self.db.issue.get(nodeid, 'status'), '3')
248 self.assertEqual(self.db.issue.get(nodeid, 'priority'), '1')
249
250 def testOptionsMulti(self):
251 nodeid = self._handle_mail('''Content-Type: text/plain;
252 charset="iso-8859-1"
253 From: Chef <chef@bork.bork.bork>
254 To: issue_tracker@your.tracker.email.domain.example
255 Message-Id: <dummy_test_message_id>
256 Reply-To: chef@bork.bork.bork
257 Subject: [issue] Testing...
258
259 Hi there!
260 ''', (('-C', 'issue'), ('-S', 'status=chatting'), ('-S', 'priority=critical')))
261 self.assertEqual(self.db.issue.get(nodeid, 'status'), '3')
262 self.assertEqual(self.db.issue.get(nodeid, 'priority'), '1')
201 263
202 def doNewIssue(self): 264 def doNewIssue(self):
203 nodeid = self._handle_mail('''Content-Type: text/plain; 265 nodeid = self._handle_mail('''Content-Type: text/plain;
204 charset="iso-8859-1" 266 charset="iso-8859-1"
205 From: Chef <chef@bork.bork.bork> 267 From: Chef <chef@bork.bork.bork>

Roundup Issue Tracker: http://roundup-tracker.org/