Skip to content

Commit c60540b

Browse files
author
Richard Jones
committed
Added ability for unit tests to turn off exception handling in mailgw so
that exceptions are reported earlier (and hence make sense).
1 parent ef47f5f commit c60540b

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

roundup/mailgw.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class node. Any parts of other types are each stored in separate files
7373
an exception, the original message is bounced back to the sender with the
7474
explanatory message given in the exception.
7575
76-
$Id: mailgw.py,v 1.74 2002-05-29 01:16:17 richard Exp $
76+
$Id: mailgw.py,v 1.75 2002-07-09 01:21:24 richard Exp $
7777
'''
7878

7979

@@ -128,6 +128,10 @@ def __init__(self, instance, db):
128128
self.instance = instance
129129
self.db = db
130130

131+
# should we trap exceptions (normal usage) or pass them through
132+
# (for testing)
133+
self.trapExceptions = 1
134+
131135
def main(self, fp):
132136
''' fp - the file from which to read the Message.
133137
'''
@@ -146,6 +150,8 @@ def handle_Message(self, message):
146150
# its way into here... try to handle it gracefully
147151
sendto = message.getaddrlist('from')
148152
if sendto:
153+
if not self.trapExceptions:
154+
return self.handle_message(message)
149155
try:
150156
return self.handle_message(message)
151157
except MailUsageHelp:
@@ -765,6 +771,18 @@ def parseContent(content, keep_citations, keep_body,
765771

766772
#
767773
# $Log: not supported by cvs2svn $
774+
# Revision 1.74 2002/05/29 01:16:17 richard
775+
# Sorry about this huge checkin! It's fixing a lot of related stuff in one go
776+
# though.
777+
#
778+
# . #541941 ] changing multilink properties by mail
779+
# . #526730 ] search for messages capability
780+
# . #505180 ] split MailGW.handle_Message
781+
# - also changed cgi client since it was duplicating the functionality
782+
# . build htmlbase if tests are run using CVS checkout (removed note from
783+
# installation.txt)
784+
# . don't create an empty message on email issue creation if the email is empty
785+
#
768786
# Revision 1.73 2002/05/22 04:12:05 richard
769787
# . applied patch #558876 ] cgi client customization
770788
# ... with significant additions and modifications ;)

test/test_mailgw.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# but WITHOUT ANY WARRANTY; without even the implied warranty of
99
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1010
#
11-
# $Id: test_mailgw.py,v 1.21 2002-06-18 03:59:59 dman13 Exp $
11+
# $Id: test_mailgw.py,v 1.22 2002-07-09 01:21:24 richard Exp $
1212

1313
import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys, difflib
1414

@@ -106,6 +106,7 @@ def doNewIssue(self):
106106
This is a test submission of a new issue.
107107
''')
108108
handler = self.instance.MailGW(self.instance, self.db)
109+
handler.trapExceptions = 0
109110
nodeid = handler.main(message)
110111
if os.path.exists(os.environ['SENDMAILDEBUG']):
111112
error = open(os.environ['SENDMAILDEBUG']).read()
@@ -130,6 +131,7 @@ def testNewIssueNosy(self):
130131
This is a test submission of a new issue.
131132
''')
132133
handler = self.instance.MailGW(self.instance, self.db)
134+
handler.trapExceptions = 0
133135
nodeid = handler.main(message)
134136
if os.path.exists(os.environ['SENDMAILDEBUG']):
135137
error = open(os.environ['SENDMAILDEBUG']).read()
@@ -150,6 +152,7 @@ def testAlternateAddress(self):
150152
''')
151153
userlist = self.db.user.list()
152154
handler = self.instance.MailGW(self.instance, self.db)
155+
handler.trapExceptions = 0
153156
handler.main(message)
154157
if os.path.exists(os.environ['SENDMAILDEBUG']):
155158
error = open(os.environ['SENDMAILDEBUG']).read()
@@ -169,6 +172,7 @@ def testNewIssueNoClass(self):
169172
This is a test submission of a new issue.
170173
''')
171174
handler = self.instance.MailGW(self.instance, self.db)
175+
handler.trapExceptions = 0
172176
handler.main(message)
173177
if os.path.exists(os.environ['SENDMAILDEBUG']):
174178
error = open(os.environ['SENDMAILDEBUG']).read()
@@ -185,6 +189,7 @@ def testNewIssueAuthMsg(self):
185189
This is a test submission of a new issue.
186190
''')
187191
handler = self.instance.MailGW(self.instance, self.db)
192+
handler.trapExceptions = 0
188193
# TODO: fix the damn config - this is apalling
189194
self.db.config.MESSAGES_TO_AUTHOR = 'yes'
190195
handler.main(message)
@@ -242,6 +247,7 @@ def testSimpleFollowup(self):
242247
This is a second followup
243248
''')
244249
handler = self.instance.MailGW(self.instance, self.db)
250+
handler.trapExceptions = 0
245251
handler.main(message)
246252
self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
247253
@@ -285,6 +291,7 @@ def testFollowup(self):
285291
This is a followup
286292
''')
287293
handler = self.instance.MailGW(self.instance, self.db)
294+
handler.trapExceptions = 0
288295
handler.main(message)
289296
l = self.db.issue.get('1', 'nosy')
290297
l.sort()
@@ -333,6 +340,7 @@ def testFollowupTitleMatch(self):
333340
This is a followup
334341
''')
335342
handler = self.instance.MailGW(self.instance, self.db)
343+
handler.trapExceptions = 0
336344
handler.main(message)
337345

338346
self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
@@ -379,6 +387,7 @@ def testFollowupNosyAuthor(self):
379387
This is a followup
380388
''')
381389
handler = self.instance.MailGW(self.instance, self.db)
390+
handler.trapExceptions = 0
382391
handler.main(message)
383392

384393
self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
@@ -426,6 +435,7 @@ def testFollowupNosyRecipients(self):
426435
This is a followup
427436
''')
428437
handler = self.instance.MailGW(self.instance, self.db)
438+
handler.trapExceptions = 0
429439
handler.main(message)
430440

431441
self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
@@ -473,6 +483,7 @@ def testFollowupNosyAuthorAndCopy(self):
473483
This is a followup
474484
''')
475485
handler = self.instance.MailGW(self.instance, self.db)
486+
handler.trapExceptions = 0
476487
handler.main(message)
477488

478489
self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
@@ -519,6 +530,7 @@ def testFollowupNoNosyAuthor(self):
519530
This is a followup
520531
''')
521532
handler = self.instance.MailGW(self.instance, self.db)
533+
handler.trapExceptions = 0
522534
handler.main(message)
523535

524536
self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
@@ -565,6 +577,7 @@ def testFollowupNoNosyRecipients(self):
565577
This is a followup
566578
''')
567579
handler = self.instance.MailGW(self.instance, self.db)
580+
handler.trapExceptions = 0
568581
handler.main(message)
569582

570583
self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
@@ -609,6 +622,7 @@ def testNosyRemove(self):
609622
610623
''')
611624
handler = self.instance.MailGW(self.instance, self.db)
625+
handler.trapExceptions = 0
612626
handler.main(message)
613627
l = self.db.issue.get('1', 'nosy')
614628
l.sort()
@@ -634,6 +648,7 @@ def testEnc01(self):
634648
635649
''')
636650
handler = self.instance.MailGW(self.instance, self.db)
651+
handler.trapExceptions = 0
637652
handler.main(message)
638653
self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
639654
@@ -687,6 +702,7 @@ def testMultipartEnc01(self):
687702
688703
''')
689704
handler = self.instance.MailGW(self.instance, self.db)
705+
handler.trapExceptions = 0
690706
handler.main(message)
691707
self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
692708
@@ -727,6 +743,12 @@ def suite():
727743

728744
#
729745
# $Log: not supported by cvs2svn $
746+
# Revision 1.21 2002/06/18 03:59:59 dman13
747+
# Updated message strings to match the RFC822 address quoting performed
748+
# by the 'email' and 'rfc822' modules. The verification really should
749+
# use a RFC2822 message parser rather than literal string comparisions
750+
# to allow for legal variations in messages.
751+
#
730752
# Revision 1.20 2002/05/29 01:16:17 richard
731753
# Sorry about this huge checkin! It's fixing a lot of related stuff in one go
732754
# though.

0 commit comments

Comments
 (0)