summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0231088)
raw | patch | inline | side by side (parent: 0231088)
author | jlgijsbers <jlgijsbers@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Sun, 7 Sep 2003 13:08:08 +0000 (13:08 +0000) | ||
committer | jlgijsbers <jlgijsbers@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Sun, 7 Sep 2003 13:08:08 +0000 (13:08 +0000) |
comparison. The header order changed while refactoring email sending, but this
way we won't have to worry about that affecting the tests anymore.
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1862 57a73879-2fb5-44c3-a270-3262357dd7e2
way we won't have to worry about that affecting the tests anymore.
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1862 57a73879-2fb5-44c3-a270-3262357dd7e2
test/test_mailgw.py | patch | blob | history |
diff --git a/test/test_mailgw.py b/test/test_mailgw.py
index be8a77483e9a5aa59ebbae8f826f31e29e46f0ce..43d9fa772fc4243d08462f566c229acb77cf423d 100644 (file)
--- a/test/test_mailgw.py
+++ b/test/test_mailgw.py
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
-# $Id: test_mailgw.py,v 1.48 2003-09-06 10:37:10 jlgijsbers Exp $
+# $Id: test_mailgw.py,v 1.49 2003-09-07 13:08:08 jlgijsbers Exp $
-import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys, difflib
-import rfc822
+import unittest, tempfile, os, shutil, errno, imp, sys, difflib, rfc822
-# Note: Should parse emails according to RFC2822 instead of performing a
-# literal string comparision. Parsing the messages allows the tests to work for
-# any legal serialization of an email.
-#try :
-# import email
-#except ImportError :
-# import rfc822 as email
+from cStringIO import StringIO
from roundup.mailgw import MailGW, Unauthorized, uidFromAddress
from roundup import init, instance, rfc2822
-# TODO: make this output only enough equal lines for context, not all of
-# them
+class Message(rfc822.Message):
+ """String-based Message class with equivalence test."""
+ def __init__(self, s):
+ rfc822.Message.__init__(self, StringIO(s.strip()))
+
+ def __eq__(self, other):
+ del self['date'], other['date']
+
+ self.headers.sort()
+ other.headers.sort()
+
+ self.rewindbody()
+ other.rewindbody()
+
+ return (self.headers == other.headers and
+ self.fp.read() == other.fp.read())
+
+# TODO: Do a semantic diff instead of a straight text diff when a test fails.
class DiffHelper:
+ def compareMessages(self, s2, s1):
+ """Compare messages for semantic equivalence."""
+ if not Message(s2) == Message(s1):
+ self.compareStrings(s2, s1)
+
def compareStrings(self, s2, s1):
'''Note the reversal of s2 and s1 - difflib.SequenceMatcher wants
the first to be the "original" but in the calls in this file,
if error.errno not in (errno.ENOENT, errno.ESRCH): raise
def testEmptyMessage(self):
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: Chef <chef@bork.bork.bork>
To: issue_tracker@your.tracker.email.domain.example
self.assertEqual(self.db.issue.get(nodeid, 'title'), 'Testing...')
def doNewIssue(self):
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: Chef <chef@bork.bork.bork>
To: issue_tracker@your.tracker.email.domain.example
def testNewIssueNosy(self):
self.instance.config.ADD_AUTHOR_TO_NOSY = 'yes'
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: Chef <chef@bork.bork.bork>
To: issue_tracker@your.tracker.email.domain.example
self.assertEqual(l, ['3', '4'])
def testAlternateAddress(self):
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: John Doe <john.doe@test>
To: issue_tracker@your.tracker.email.domain.example
"user created when it shouldn't have been")
def testNewIssueNoClass(self):
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: Chef <chef@bork.bork.bork>
To: issue_tracker@your.tracker.email.domain.example
self.assertEqual('no error', error)
def testNewIssueAuthMsg(self):
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: Chef <chef@bork.bork.bork>
To: issue_tracker@your.tracker.email.domain.example
self.db.config.MESSAGES_TO_AUTHOR = 'yes'
handler.main(message)
- self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+ self.compareMessages(open(os.environ['SENDMAILDEBUG']).read(),
'''FROM: roundup-admin@your.tracker.email.domain.example
TO: chef@bork.bork.bork, mary@test, richard@test
Content-Type: text/plain; charset=utf-8
def testSimpleFollowup(self):
self.doNewIssue()
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: mary <mary@test>
To: issue_tracker@your.tracker.email.domain.example
handler = self.instance.MailGW(self.instance, self.db)
handler.trapExceptions = 0
handler.main(message)
- self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+ self.compareMessages(open(os.environ['SENDMAILDEBUG']).read(),
'''FROM: roundup-admin@your.tracker.email.domain.example
TO: chef@bork.bork.bork, richard@test
Content-Type: text/plain; charset=utf-8
def testFollowup(self):
self.doNewIssue()
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: richard <richard@test>
To: issue_tracker@your.tracker.email.domain.example
l.sort()
self.assertEqual(l, ['3', '4', '5', '6'])
- self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+ self.compareMessages(open(os.environ['SENDMAILDEBUG']).read(),
'''FROM: roundup-admin@your.tracker.email.domain.example
TO: chef@bork.bork.bork, john@test, mary@test
Content-Type: text/plain; charset=utf-8
def testFollowupTitleMatch(self):
self.doNewIssue()
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: richard <richard@test>
To: issue_tracker@your.tracker.email.domain.example
handler.trapExceptions = 0
handler.main(message)
- self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+ self.compareMessages(open(os.environ['SENDMAILDEBUG']).read(),
'''FROM: roundup-admin@your.tracker.email.domain.example
TO: chef@bork.bork.bork, john@test, mary@test
Content-Type: text/plain; charset=utf-8
def testFollowupNosyAuthor(self):
self.doNewIssue()
self.db.config.ADD_AUTHOR_TO_NOSY = 'yes'
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: john@test
To: issue_tracker@your.tracker.email.domain.example
handler.trapExceptions = 0
handler.main(message)
- self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+ self.compareMessages(open(os.environ['SENDMAILDEBUG']).read(),
'''FROM: roundup-admin@your.tracker.email.domain.example
TO: chef@bork.bork.bork, richard@test
Content-Type: text/plain; charset=utf-8
def testFollowupNosyRecipients(self):
self.doNewIssue()
self.db.config.ADD_RECIPIENTS_TO_NOSY = 'yes'
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: richard@test
To: issue_tracker@your.tracker.email.domain.example
handler.trapExceptions = 0
handler.main(message)
- self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+ self.compareMessages(open(os.environ['SENDMAILDEBUG']).read(),
'''FROM: roundup-admin@your.tracker.email.domain.example
TO: chef@bork.bork.bork
Content-Type: text/plain; charset=utf-8
self.doNewIssue()
self.db.config.ADD_AUTHOR_TO_NOSY = 'yes'
self.db.config.MESSAGES_TO_AUTHOR = 'yes'
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: john@test
To: issue_tracker@your.tracker.email.domain.example
handler.trapExceptions = 0
handler.main(message)
- self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+ self.compareMessages(open(os.environ['SENDMAILDEBUG']).read(),
'''FROM: roundup-admin@your.tracker.email.domain.example
TO: chef@bork.bork.bork, john@test, richard@test
Content-Type: text/plain; charset=utf-8
def testFollowupNoNosyAuthor(self):
self.doNewIssue()
self.instance.config.ADD_AUTHOR_TO_NOSY = 'no'
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: john@test
To: issue_tracker@your.tracker.email.domain.example
handler.trapExceptions = 0
handler.main(message)
- self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+ self.compareMessages(open(os.environ['SENDMAILDEBUG']).read(),
'''FROM: roundup-admin@your.tracker.email.domain.example
TO: chef@bork.bork.bork, richard@test
Content-Type: text/plain; charset=utf-8
def testFollowupNoNosyRecipients(self):
self.doNewIssue()
self.instance.config.ADD_RECIPIENTS_TO_NOSY = 'no'
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: richard@test
To: issue_tracker@your.tracker.email.domain.example
handler.trapExceptions = 0
handler.main(message)
- self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+ self.compareMessages(open(os.environ['SENDMAILDEBUG']).read(),
'''FROM: roundup-admin@your.tracker.email.domain.example
TO: chef@bork.bork.bork
Content-Type: text/plain; charset=utf-8
def testFollowupEmptyMessage(self):
self.doNewIssue()
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: richard <richard@test>
To: issue_tracker@your.tracker.email.domain.example
def testNosyRemove(self):
self.doNewIssue()
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: richard <richard@test>
To: issue_tracker@your.tracker.email.domain.example
This is a test submission of a new issue.
'''
- message = cStringIO.StringIO(s)
+ message = StringIO(s)
handler = self.instance.MailGW(self.instance, self.db)
handler.trapExceptions = 0
self.assertRaises(Unauthorized, handler.main, message)
self.db.security.role['anonymous'].permissions=[p]
handler = self.instance.MailGW(self.instance, self.db)
handler.trapExceptions = 0
- message = cStringIO.StringIO(s)
+ message = StringIO(s)
handler.main(message)
m = self.db.user.list()
m.sort()
def testEnc01(self):
self.doNewIssue()
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: mary <mary@test>
To: issue_tracker@your.tracker.email.domain.example
handler = self.instance.MailGW(self.instance, self.db)
handler.trapExceptions = 0
handler.main(message)
- self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+ self.compareMessages(open(os.environ['SENDMAILDEBUG']).read(),
'''FROM: roundup-admin@your.tracker.email.domain.example
TO: chef@bork.bork.bork, richard@test
Content-Type: text/plain; charset=utf-8
def testMultipartEnc01(self):
self.doNewIssue()
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: mary <mary@test>
To: issue_tracker@your.tracker.email.domain.example
handler = self.instance.MailGW(self.instance, self.db)
handler.trapExceptions = 0
handler.main(message)
- self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+ self.compareMessages(open(os.environ['SENDMAILDEBUG']).read(),
'''FROM: roundup-admin@your.tracker.email.domain.example
TO: chef@bork.bork.bork, richard@test
Content-Type: text/plain; charset=utf-8
def testContentDisposition(self):
self.doNewIssue()
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: mary <mary@test>
To: issue_tracker@your.tracker.email.domain.example
def testFollowupStupidQuoting(self):
self.doNewIssue()
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: richard <richard@test>
To: issue_tracker@your.tracker.email.domain.example
handler.trapExceptions = 0
handler.main(message)
- self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+ self.compareMessages(open(os.environ['SENDMAILDEBUG']).read(),
'''FROM: roundup-admin@your.tracker.email.domain.example
TO: chef@bork.bork.bork
Content-Type: text/plain; charset=utf-8
messages = self.db.issue.get(nodeid, 'messages')
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: richard <richard@test>
To: issue_tracker@your.tracker.email.domain.example
newmessages.remove(msg)
messageid = newmessages[0]
- self.compareStrings(self.db.msg.get(messageid, 'content'), expect)
+ self.compareMessages(self.db.msg.get(messageid, 'content'), expect)
def testUserLookup(self):
i = self.db.user.create(username='user1', address='user1@foo.com')
def testRegistrationConfirmation(self):
otk = "Aj4euk4LZSAdwePohj90SME5SpopLETL"
self.db.otks.set(otk, username='johannes', __time='')
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: Chef <chef@bork.bork.bork>
To: issue_tracker@your.tracker.email.domain.example