Skip to content

Commit 6bdca32

Browse files
author
Richard Jones
committed
*** empty log message ***
1 parent fc6af7c commit 6bdca32

File tree

1 file changed

+43
-35
lines changed

1 file changed

+43
-35
lines changed

test/test_mailgw.py

Lines changed: 43 additions & 35 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.63 2003-12-04 23:34:25 richard Exp $
11+
# $Id: test_mailgw.py,v 1.64 2004-01-20 00:11:51 richard Exp $
1212

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

@@ -20,7 +20,7 @@
2020

2121
from roundup.mailgw import MailGW, Unauthorized, uidFromAddress, \
2222
parseContent, IgnoreLoop, IgnoreBulk
23-
from roundup import init, instance, rfc2822
23+
from roundup import init, instance, rfc2822, __version__
2424

2525

2626
class Message(rfc822.Message):
@@ -39,18 +39,25 @@ def compareMessages(self, new, old):
3939
del new['date'], old['date']
4040

4141
if not new == old:
42-
res = ['Generated message not correct (diff follows):']
42+
res = []
4343

4444
for key in new.keys():
45-
if new[key] != old[key]:
45+
if key.lower() == 'x-roundup-version':
46+
# version changes constantly, so handle it specially
47+
if new[key] != __version__:
48+
res.append(' %s: %s != %s' % (key, __version__,
49+
new[key]))
50+
elif new[key] != old[key]:
4651
res.append(' %s: %s != %s' % (key, old[key], new[key]))
47-
52+
4853
body_diff = self.compareStrings(new.fp.read(), old.fp.read())
4954
if body_diff:
5055
res.append('')
5156
res.extend(body_diff)
5257

53-
raise AssertionError, '\n'.join(res)
58+
if res:
59+
res.insert(0, 'Generated message not correct (diff follows):')
60+
raise AssertionError, '\n'.join(res)
5461

5562
def compareStrings(self, s2, s1):
5663
'''Note the reversal of s2 and s1 - difflib.SequenceMatcher wants
@@ -119,7 +126,7 @@ def tearDown(self):
119126
except OSError, error:
120127
if error.errno not in (errno.ENOENT, errno.ESRCH): raise
121128

122-
def _send_mail(self, message):
129+
def _handle_mail(self, message):
123130
handler = self.instance.MailGW(self.instance, self.db)
124131
handler.trapExceptions = 0
125132
return handler.main(StringIO(message))
@@ -132,11 +139,12 @@ def _get_mail(self):
132139
f.close()
133140

134141
def testEmptyMessage(self):
135-
nodeid = self._send_mail('''Content-Type: text/plain;
142+
nodeid = self._handle_mail('''Content-Type: text/plain;
136143
charset="iso-8859-1"
137144
From: Chef <[email protected]>
138145
139146
Cc: richard@test
147+
140148
Message-Id: <dummy_test_message_id>
141149
Subject: [issue] Testing...
142150
@@ -145,7 +153,7 @@ def testEmptyMessage(self):
145153
self.assertEqual(self.db.issue.get(nodeid, 'title'), 'Testing...')
146154

147155
def doNewIssue(self):
148-
nodeid = self._send_mail('''Content-Type: text/plain;
156+
nodeid = self._handle_mail('''Content-Type: text/plain;
149157
charset="iso-8859-1"
150158
From: Chef <[email protected]>
151159
@@ -166,7 +174,7 @@ def testNewIssue(self):
166174

167175
def testNewIssueNosy(self):
168176
self.instance.config.ADD_AUTHOR_TO_NOSY = 'yes'
169-
nodeid = self._send_mail('''Content-Type: text/plain;
177+
nodeid = self._handle_mail('''Content-Type: text/plain;
170178
charset="iso-8859-1"
171179
From: Chef <[email protected]>
172180
@@ -182,7 +190,7 @@ def testNewIssueNosy(self):
182190
self.assertEqual(l, [self.chef_id, self.richard_id])
183191

184192
def testAlternateAddress(self):
185-
self._send_mail('''Content-Type: text/plain;
193+
self._handle_mail('''Content-Type: text/plain;
186194
charset="iso-8859-1"
187195
From: John Doe <john.doe@test>
188196
@@ -197,7 +205,7 @@ def testAlternateAddress(self):
197205
"user created when it shouldn't have been")
198206

199207
def testNewIssueNoClass(self):
200-
self._send_mail('''Content-Type: text/plain;
208+
self._handle_mail('''Content-Type: text/plain;
201209
charset="iso-8859-1"
202210
From: Chef <[email protected]>
203211
@@ -212,7 +220,7 @@ def testNewIssueNoClass(self):
212220
def testNewIssueAuthMsg(self):
213221
# TODO: fix the damn config - this is apalling
214222
self.db.config.MESSAGES_TO_AUTHOR = 'yes'
215-
self._send_mail('''Content-Type: text/plain;
223+
self._handle_mail('''Content-Type: text/plain;
216224
charset="iso-8859-1"
217225
From: Chef <[email protected]>
218226
@@ -263,7 +271,7 @@ def testNewIssueAuthMsg(self):
263271

264272
def testSimpleFollowup(self):
265273
self.doNewIssue()
266-
self._send_mail('''Content-Type: text/plain;
274+
self._handle_mail('''Content-Type: text/plain;
267275
charset="iso-8859-1"
268276
From: mary <mary@test>
269277
@@ -304,7 +312,7 @@ def testSimpleFollowup(self):
304312
def testFollowup(self):
305313
self.doNewIssue()
306314

307-
self._send_mail('''Content-Type: text/plain;
315+
self._handle_mail('''Content-Type: text/plain;
308316
charset="iso-8859-1"
309317
From: richard <richard@test>
310318
@@ -351,7 +359,7 @@ def testFollowup(self):
351359

352360
def testFollowupTitleMatch(self):
353361
self.doNewIssue()
354-
self._send_mail('''Content-Type: text/plain;
362+
self._handle_mail('''Content-Type: text/plain;
355363
charset="iso-8859-1"
356364
From: richard <richard@test>
357365
@@ -394,7 +402,7 @@ def testFollowupTitleMatch(self):
394402
def testFollowupNosyAuthor(self):
395403
self.doNewIssue()
396404
self.db.config.ADD_AUTHOR_TO_NOSY = 'yes'
397-
self._send_mail('''Content-Type: text/plain;
405+
self._handle_mail('''Content-Type: text/plain;
398406
charset="iso-8859-1"
399407
From: john@test
400408
@@ -438,7 +446,7 @@ def testFollowupNosyAuthor(self):
438446
def testFollowupNosyRecipients(self):
439447
self.doNewIssue()
440448
self.db.config.ADD_RECIPIENTS_TO_NOSY = 'yes'
441-
self._send_mail('''Content-Type: text/plain;
449+
self._handle_mail('''Content-Type: text/plain;
442450
charset="iso-8859-1"
443451
From: richard@test
444452
@@ -483,7 +491,7 @@ def testFollowupNosyAuthorAndCopy(self):
483491
self.doNewIssue()
484492
self.db.config.ADD_AUTHOR_TO_NOSY = 'yes'
485493
self.db.config.MESSAGES_TO_AUTHOR = 'yes'
486-
self._send_mail('''Content-Type: text/plain;
494+
self._handle_mail('''Content-Type: text/plain;
487495
charset="iso-8859-1"
488496
From: john@test
489497
@@ -526,7 +534,7 @@ def testFollowupNosyAuthorAndCopy(self):
526534
def testFollowupNoNosyAuthor(self):
527535
self.doNewIssue()
528536
self.instance.config.ADD_AUTHOR_TO_NOSY = 'no'
529-
self._send_mail('''Content-Type: text/plain;
537+
self._handle_mail('''Content-Type: text/plain;
530538
charset="iso-8859-1"
531539
From: john@test
532540
@@ -568,7 +576,7 @@ def testFollowupNoNosyAuthor(self):
568576
def testFollowupNoNosyRecipients(self):
569577
self.doNewIssue()
570578
self.instance.config.ADD_RECIPIENTS_TO_NOSY = 'no'
571-
self._send_mail('''Content-Type: text/plain;
579+
self._handle_mail('''Content-Type: text/plain;
572580
charset="iso-8859-1"
573581
From: richard@test
574582
@@ -611,7 +619,7 @@ def testFollowupNoNosyRecipients(self):
611619
def testFollowupEmptyMessage(self):
612620
self.doNewIssue()
613621

614-
self._send_mail('''Content-Type: text/plain;
622+
self._handle_mail('''Content-Type: text/plain;
615623
charset="iso-8859-1"
616624
From: richard <richard@test>
617625
@@ -631,7 +639,7 @@ def testFollowupEmptyMessage(self):
631639
def testNosyRemove(self):
632640
self.doNewIssue()
633641

634-
self._send_mail('''Content-Type: text/plain;
642+
self._handle_mail('''Content-Type: text/plain;
635643
charset="iso-8859-1"
636644
From: richard <richard@test>
637645
@@ -666,22 +674,22 @@ def testNewUserAuthor(self):
666674
667675
This is a test submission of a new issue.
668676
'''
669-
self.assertRaises(Unauthorized, self._send_mail, message)
677+
self.assertRaises(Unauthorized, self._handle_mail, message)
670678
m = self.db.user.list()
671679
m.sort()
672680
self.assertEqual(l, m)
673681

674682
# now with the permission
675683
p = self.db.security.getPermission('Email Registration')
676684
self.db.security.role['anonymous'].permissions=[p]
677-
self._send_mail(message)
685+
self._handle_mail(message)
678686
m = self.db.user.list()
679687
m.sort()
680688
self.assertNotEqual(l, m)
681689

682690
def testEnc01(self):
683691
self.doNewIssue()
684-
self._send_mail('''Content-Type: text/plain;
692+
self._handle_mail('''Content-Type: text/plain;
685693
charset="iso-8859-1"
686694
From: mary <mary@test>
687695
@@ -726,7 +734,7 @@ def testEnc01(self):
726734

727735
def testMultipartEnc01(self):
728736
self.doNewIssue()
729-
self._send_mail('''Content-Type: text/plain;
737+
self._handle_mail('''Content-Type: text/plain;
730738
charset="iso-8859-1"
731739
From: mary <mary@test>
732740
@@ -777,7 +785,7 @@ def testMultipartEnc01(self):
777785

778786
def testContentDisposition(self):
779787
self.doNewIssue()
780-
self._send_mail('''Content-Type: text/plain;
788+
self._handle_mail('''Content-Type: text/plain;
781789
charset="iso-8859-1"
782790
From: mary <mary@test>
783791
@@ -810,7 +818,7 @@ def testContentDisposition(self):
810818
def testFollowupStupidQuoting(self):
811819
self.doNewIssue()
812820

813-
self._send_mail('''Content-Type: text/plain;
821+
self._handle_mail('''Content-Type: text/plain;
814822
charset="iso-8859-1"
815823
From: richard <richard@test>
816824
@@ -868,7 +876,7 @@ def innerTestQuoting(self, expect):
868876

869877
messages = self.db.issue.get(nodeid, 'messages')
870878

871-
self._send_mail('''Content-Type: text/plain;
879+
self._handle_mail('''Content-Type: text/plain;
872880
charset="iso-8859-1"
873881
From: richard <richard@test>
874882
@@ -919,7 +927,7 @@ def testRFC2822(self):
919927
def testRegistrationConfirmation(self):
920928
otk = "Aj4euk4LZSAdwePohj90SME5SpopLETL"
921929
self.db.otks.set(otk, username='johannes', __time='')
922-
self._send_mail('''Content-Type: text/plain;
930+
self._handle_mail('''Content-Type: text/plain;
923931
charset="iso-8859-1"
924932
From: Chef <[email protected]>
925933
@@ -934,7 +942,7 @@ def testRegistrationConfirmation(self):
934942

935943
def testFollowupOnNonIssue(self):
936944
self.db.keyword.create(name='Foo')
937-
self._send_mail('''Content-Type: text/plain;
945+
self._handle_mail('''Content-Type: text/plain;
938946
charset="iso-8859-1"
939947
From: richard <richard@test>
940948
@@ -946,7 +954,7 @@ def testFollowupOnNonIssue(self):
946954
self.assertEqual(self.db.keyword.get('1', 'name'), 'Bar')
947955

948956
def testResentFrom(self):
949-
nodeid = self._send_mail('''Content-Type: text/plain;
957+
nodeid = self._handle_mail('''Content-Type: text/plain;
950958
charset="iso-8859-1"
951959
From: Chef <[email protected]>
952960
Resent-From: mary <mary@test>
@@ -965,7 +973,7 @@ def testResentFrom(self):
965973

966974

967975
def testDejaVu(self):
968-
self.assertRaises(IgnoreLoop, self._send_mail,
976+
self.assertRaises(IgnoreLoop, self._handle_mail,
969977
'''Content-Type: text/plain;
970978
charset="iso-8859-1"
971979
From: Chef <[email protected]>
@@ -979,7 +987,7 @@ def testDejaVu(self):
979987
''')
980988

981989
def testItsBulkStupid(self):
982-
self.assertRaises(IgnoreBulk, self._send_mail,
990+
self.assertRaises(IgnoreBulk, self._handle_mail,
983991
'''Content-Type: text/plain;
984992
charset="iso-8859-1"
985993
From: Chef <[email protected]>

0 commit comments

Comments
 (0)