Skip to content

Commit b617d0b

Browse files
author
Richard Jones
committed
make mailgw tests work with other backends
1 parent 84d3478 commit b617d0b

File tree

2 files changed

+51
-70
lines changed

2 files changed

+51
-70
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ are given with the most recent entry first.
44
2004-??-?? 0.6.9
55
Fixed:
66
- paging in classhelp popup was broken
7+
- socket timeout error logging can fail
78

89

910
2004-04-01 0.6.8

test/test_mailgw.py

Lines changed: 50 additions & 70 deletions
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.46.2.1 2004-04-01 00:07:35 richard Exp $
11+
# $Id: test_mailgw.py,v 1.46.2.2 2004-04-09 01:28:58 richard Exp $
1212

1313
import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys, difflib
1414
import rfc822
@@ -95,6 +95,14 @@ def tearDown(self):
9595
except OSError, error:
9696
if error.errno not in (errno.ENOENT, errno.ESRCH): raise
9797

98+
def handleMessage(self, message):
99+
handler = self.instance.MailGW(self.instance, self.db)
100+
handler.trapExceptions = 0
101+
nodeid = handler.main(message)
102+
# handler will probably close & reopen the db
103+
self.db = handler.db
104+
return nodeid
105+
98106
def testEmptyMessage(self):
99107
message = cStringIO.StringIO('''Content-Type: text/plain;
100108
charset="iso-8859-1"
@@ -105,9 +113,7 @@ def testEmptyMessage(self):
105113
Subject: [issue] Testing...
106114
107115
''')
108-
handler = self.instance.MailGW(self.instance, self.db)
109-
handler.trapExceptions = 0
110-
nodeid = handler.main(message)
116+
nodeid = self.handleMessage(message)
111117
if os.path.exists(os.environ['SENDMAILDEBUG']):
112118
error = open(os.environ['SENDMAILDEBUG']).read()
113119
self.assertEqual('no error', error)
@@ -124,9 +130,7 @@ def doNewIssue(self):
124130
125131
This is a test submission of a new issue.
126132
''')
127-
handler = self.instance.MailGW(self.instance, self.db)
128-
handler.trapExceptions = 0
129-
nodeid = handler.main(message)
133+
nodeid = self.handleMessage(message)
130134
if os.path.exists(os.environ['SENDMAILDEBUG']):
131135
error = open(os.environ['SENDMAILDEBUG']).read()
132136
self.assertEqual('no error', error)
@@ -150,16 +154,32 @@ def testNewIssueNosy(self):
150154
151155
This is a test submission of a new issue.
152156
''')
153-
handler = self.instance.MailGW(self.instance, self.db)
154-
handler.trapExceptions = 0
155-
nodeid = handler.main(message)
157+
nodeid = self.handleMessage(message)
156158
if os.path.exists(os.environ['SENDMAILDEBUG']):
157159
error = open(os.environ['SENDMAILDEBUG']).read()
158160
self.assertEqual('no error', error)
159161
l = self.db.issue.get(nodeid, 'nosy')
160162
l.sort()
161163
self.assertEqual(l, ['3', '4'])
162164

165+
def testNewUser(self):
166+
message = cStringIO.StringIO('''Content-Type: text/plain;
167+
charset="iso-8859-1"
168+
From: Frank Fiddle <[email protected]>
169+
170+
Message-Id: <dummy_test_message_id>
171+
Subject: [issue] Testing...
172+
173+
This is a test submission of a new issue.
174+
''')
175+
userlist = self.db.user.list()
176+
nodeid = self.handleMessage(message)
177+
if os.path.exists(os.environ['SENDMAILDEBUG']):
178+
error = open(os.environ['SENDMAILDEBUG']).read()
179+
self.assertEqual('no error', error)
180+
self.assertNotEqual(userlist, self.db.user.list(),
181+
"user not created when it should have been")
182+
163183
def testAlternateAddress(self):
164184
message = cStringIO.StringIO('''Content-Type: text/plain;
165185
charset="iso-8859-1"
@@ -171,9 +191,7 @@ def testAlternateAddress(self):
171191
This is a test submission of a new issue.
172192
''')
173193
userlist = self.db.user.list()
174-
handler = self.instance.MailGW(self.instance, self.db)
175-
handler.trapExceptions = 0
176-
handler.main(message)
194+
nodeid = self.handleMessage(message)
177195
if os.path.exists(os.environ['SENDMAILDEBUG']):
178196
error = open(os.environ['SENDMAILDEBUG']).read()
179197
self.assertEqual('no error', error)
@@ -191,9 +209,7 @@ def testNewIssueNoClass(self):
191209
192210
This is a test submission of a new issue.
193211
''')
194-
handler = self.instance.MailGW(self.instance, self.db)
195-
handler.trapExceptions = 0
196-
handler.main(message)
212+
nodeid = self.handleMessage(message)
197213
if os.path.exists(os.environ['SENDMAILDEBUG']):
198214
error = open(os.environ['SENDMAILDEBUG']).read()
199215
self.assertEqual('no error', error)
@@ -208,11 +224,9 @@ def testNewIssueAuthMsg(self):
208224
209225
This is a test submission of a new issue.
210226
''')
211-
handler = self.instance.MailGW(self.instance, self.db)
212-
handler.trapExceptions = 0
213227
# TODO: fix the damn config - this is apalling
214228
self.db.config.MESSAGES_TO_AUTHOR = 'yes'
215-
handler.main(message)
229+
nodeid = self.handleMessage(message)
216230

217231
self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
218232
@@ -267,9 +281,7 @@ def testSimpleFollowup(self):
267281
268282
This is a second followup
269283
''')
270-
handler = self.instance.MailGW(self.instance, self.db)
271-
handler.trapExceptions = 0
272-
handler.main(message)
284+
self.handleMessage(message)
273285
self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
274286
275287
TO: [email protected], richard@test
@@ -312,9 +324,7 @@ def testFollowup(self):
312324
313325
This is a followup
314326
''')
315-
handler = self.instance.MailGW(self.instance, self.db)
316-
handler.trapExceptions = 0
317-
handler.main(message)
327+
self.handleMessage(message)
318328
l = self.db.issue.get('1', 'nosy')
319329
l.sort()
320330
self.assertEqual(l, ['3', '4', '5', '6'])
@@ -362,9 +372,7 @@ def testFollowupTitleMatch(self):
362372
363373
This is a followup
364374
''')
365-
handler = self.instance.MailGW(self.instance, self.db)
366-
handler.trapExceptions = 0
367-
handler.main(message)
375+
self.handleMessage(message)
368376

369377
self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
370378
@@ -410,9 +418,7 @@ def testFollowupNosyAuthor(self):
410418
411419
This is a followup
412420
''')
413-
handler = self.instance.MailGW(self.instance, self.db)
414-
handler.trapExceptions = 0
415-
handler.main(message)
421+
self.handleMessage(message)
416422

417423
self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
418424
@@ -459,9 +465,7 @@ def testFollowupNosyRecipients(self):
459465
460466
This is a followup
461467
''')
462-
handler = self.instance.MailGW(self.instance, self.db)
463-
handler.trapExceptions = 0
464-
handler.main(message)
468+
self.handleMessage(message)
465469

466470
self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
467471
@@ -508,9 +512,7 @@ def testFollowupNosyAuthorAndCopy(self):
508512
509513
This is a followup
510514
''')
511-
handler = self.instance.MailGW(self.instance, self.db)
512-
handler.trapExceptions = 0
513-
handler.main(message)
515+
self.handleMessage(message)
514516

515517
self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
516518
@@ -556,9 +558,7 @@ def testFollowupNoNosyAuthor(self):
556558
557559
This is a followup
558560
''')
559-
handler = self.instance.MailGW(self.instance, self.db)
560-
handler.trapExceptions = 0
561-
handler.main(message)
561+
self.handleMessage(message)
562562

563563
self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
564564
@@ -604,9 +604,7 @@ def testFollowupNoNosyRecipients(self):
604604
605605
This is a followup
606606
''')
607-
handler = self.instance.MailGW(self.instance, self.db)
608-
handler.trapExceptions = 0
609-
handler.main(message)
607+
self.handleMessage(message)
610608

611609
self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
612610
@@ -650,9 +648,7 @@ def testFollowupEmptyMessage(self):
650648
Subject: [issue1] Testing... [assignedto=mary; nosy=+john]
651649
652650
''')
653-
handler = self.instance.MailGW(self.instance, self.db)
654-
handler.trapExceptions = 0
655-
handler.main(message)
651+
self.handleMessage(message)
656652
l = self.db.issue.get('1', 'nosy')
657653
l.sort()
658654
self.assertEqual(l, ['3', '4', '5', '6'])
@@ -672,9 +668,7 @@ def testNosyRemove(self):
672668
Subject: [issue1] Testing... [nosy=-richard]
673669
674670
''')
675-
handler = self.instance.MailGW(self.instance, self.db)
676-
handler.trapExceptions = 0
677-
handler.main(message)
671+
self.handleMessage(message)
678672
l = self.db.issue.get('1', 'nosy')
679673
l.sort()
680674
self.assertEqual(l, ['3'])
@@ -702,20 +696,16 @@ def testNewUserAuthor(self):
702696
This is a test submission of a new issue.
703697
'''
704698
message = cStringIO.StringIO(s)
705-
handler = self.instance.MailGW(self.instance, self.db)
706-
handler.trapExceptions = 0
707-
self.assertRaises(Unauthorized, handler.main, message)
699+
self.assertRaises(Unauthorized, self.handleMessage, message)
708700
m = self.db.user.list()
709701
m.sort()
710702
self.assertEqual(l, m)
711703

712704
# now with the permission
713705
p = self.db.security.getPermission('Email Registration')
714706
self.db.security.role['anonymous'].permissions=[p]
715-
handler = self.instance.MailGW(self.instance, self.db)
716-
handler.trapExceptions = 0
717707
message = cStringIO.StringIO(s)
718-
handler.main(message)
708+
self.handleMessage(message)
719709
m = self.db.user.list()
720710
m.sort()
721711
self.assertNotEqual(l, m)
@@ -736,9 +726,7 @@ def testEnc01(self):
736726
A message with encoding (encoded oe =F6)
737727
738728
''')
739-
handler = self.instance.MailGW(self.instance, self.db)
740-
handler.trapExceptions = 0
741-
handler.main(message)
729+
self.handleMessage(message)
742730
self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
743731
744732
TO: [email protected], richard@test
@@ -792,9 +780,7 @@ def testMultipartEnc01(self):
792780
A message with first part encoded (encoded oe =F6)
793781
794782
''')
795-
handler = self.instance.MailGW(self.instance, self.db)
796-
handler.trapExceptions = 0
797-
handler.main(message)
783+
self.handleMessage(message)
798784
self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
799785
800786
TO: [email protected], richard@test
@@ -851,9 +837,7 @@ def testContentDisposition(self):
851837
852838
--bCsyhTFzCvuiizWE--
853839
''')
854-
handler = self.instance.MailGW(self.instance, self.db)
855-
handler.trapExceptions = 0
856-
handler.main(message)
840+
self.handleMessage(message)
857841
messages = self.db.issue.get('1', 'messages')
858842
messages.sort()
859843
file = self.db.msg.get(messages[-1], 'files')[0]
@@ -872,9 +856,7 @@ def testFollowupStupidQuoting(self):
872856
873857
This is a followup
874858
''')
875-
handler = self.instance.MailGW(self.instance, self.db)
876-
handler.trapExceptions = 0
877-
handler.main(message)
859+
self.handleMessage(message)
878860

879861
self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
880862
@@ -940,9 +922,7 @@ def innerTestQuoting(self, expect):
940922
941923
This is a followup
942924
''')
943-
handler = self.instance.MailGW(self.instance, self.db)
944-
handler.trapExceptions = 0
945-
handler.main(message)
925+
self.handleMessage(message)
946926

947927
# figure the new message id
948928
newmessages = self.db.issue.get(nodeid, 'messages')

0 commit comments

Comments
 (0)