diff --git a/test/test_mailgw.py b/test/test_mailgw.py
index 5431488765fb7de430c863ecbb43a3d9045a1522..ea5adde2dc93d70213e78737bc0895211c5595fc 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.19 2002-05-23 04:26:05 richard Exp $
+# $Id: test_mailgw.py,v 1.57 2003-10-25 22:53:26 richard Exp $
-import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys, difflib
+import unittest, tempfile, os, shutil, errno, imp, sys, difflib, rfc822
-from roundup.mailgw import MailGW
-from roundup import init, instance
+from cStringIO import StringIO
-# TODO: make this output only enough equal lines for context, not all of
-# them
+if not os.environ.has_key('SENDMAILDEBUG'):
+ os.environ['SENDMAILDEBUG'] = 'mail-test.log'
+SENDMAILDEBUG = os.environ['SENDMAILDEBUG']
+
+from roundup.mailgw import MailGW, Unauthorized, uidFromAddress, parseContent
+from roundup import init, instance, rfc2822
+
+
+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']
+
+ return (self.dict == other.dict 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,
the second arg is the original. Ho hum.
'''
- if s1 == s2:
+ # we have to special-case the Date: header here 'cos we can't test
+ # for it properly
+ l1=s1.strip().split('\n')
+ l2=[x for x in s2.strip().split('\n') if not x.startswith('Date: ')]
+ if l1 == l2:
return
- # under python2.[12] we allow a difference of one trailing empty line.
- if sys.version_info[0:2] == (2,1):
- if s1+'\n' == s2:
- return
- if sys.version_info[0:2] == (2,2):
- if s1 == s2+'\n':
- return
-
- l1=s1.split('\n')
- l2=s2.split('\n')
s = difflib.SequenceMatcher(None, l1, l2)
res = ['Generated message not correct (diff follows):']
for value, s1s, s1e, s2s, s2e in s.get_opcodes():
except OSError, error:
if error.errno not in (errno.ENOENT, errno.ESRCH): raise
# create the instance
- init.install(self.dirname, 'classic', 'anydbm')
+ init.install(self.dirname, 'templates/classic')
+ init.write_select_db(self.dirname, 'anydbm')
init.initialise(self.dirname, 'sekrit')
+
# check we can load the package
self.instance = instance.open(self.dirname)
+
# and open the database
- self.db = self.instance.open('sekrit')
- self.db.user.create(username='Chef', address='chef@bork.bork.bork')
- self.db.user.create(username='richard', address='richard@test')
- self.db.user.create(username='mary', address='mary@test')
+ self.db = self.instance.open('admin')
+ self.db.user.create(username='Chef', address='chef@bork.bork.bork',
+ realname='Bork, Chef', roles='User')
+ self.db.user.create(username='richard', address='richard@test',
+ roles='User')
+ self.db.user.create(username='mary', address='mary@test',
+ roles='User', realname='Contrary, Mary')
self.db.user.create(username='john', address='john@test',
- alternate_addresses='jondoe@test\njohn.doe@test')
+ alternate_addresses='jondoe@test\njohn.doe@test', roles='User',
+ realname='John Doe')
def tearDown(self):
- if os.path.exists(os.environ['SENDMAILDEBUG']):
- os.remove(os.environ['SENDMAILDEBUG'])
+ if os.path.exists(SENDMAILDEBUG):
+ os.remove(SENDMAILDEBUG)
+ self.db.close()
try:
shutil.rmtree(self.dirname)
except OSError, error:
if error.errno not in (errno.ENOENT, errno.ESRCH): raise
- def testNewIssue(self):
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ def _get_mail(self):
+ f = open(SENDMAILDEBUG)
+ try:
+ return f.read()
+ finally:
+ f.close()
+
+ def testEmptyMessage(self):
+ message = StringIO('''Content-Type: text/plain;
+ charset="iso-8859-1"
+From: Chef <chef@bork.bork.bork>
+To: issue_tracker@your.tracker.email.domain.example
+Cc: richard@test
+Message-Id: <dummy_test_message_id>
+Subject: [issue] Testing...
+
+''')
+ handler = self.instance.MailGW(self.instance, self.db)
+ handler.trapExceptions = 0
+ nodeid = handler.main(message)
+ assert not os.path.exists(SENDMAILDEBUG)
+ self.assertEqual(self.db.issue.get(nodeid, 'title'), 'Testing...')
+
+ def doNewIssue(self):
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
-From: Chef <chef@bork.bork.bork
+From: Chef <chef@bork.bork.bork>
To: issue_tracker@your.tracker.email.domain.example
Cc: richard@test
Message-Id: <dummy_test_message_id>
This is a test submission of a new issue.
''')
handler = self.instance.MailGW(self.instance, self.db)
+ handler.trapExceptions = 0
nodeid = handler.main(message)
- if os.path.exists(os.environ['SENDMAILDEBUG']):
- error = open(os.environ['SENDMAILDEBUG']).read()
- self.assertEqual('no error', error)
+ assert not os.path.exists(SENDMAILDEBUG)
l = self.db.issue.get(nodeid, 'nosy')
l.sort()
- self.assertEqual(l, ['2', '3'])
+ self.assertEqual(l, ['3', '4'])
+ return nodeid
+
+ def testNewIssue(self):
+ self.doNewIssue()
def testNewIssueNosy(self):
- self.instance.ADD_AUTHOR_TO_NOSY = 'yes'
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ self.instance.config.ADD_AUTHOR_TO_NOSY = 'yes'
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
-From: Chef <chef@bork.bork.bork
+From: Chef <chef@bork.bork.bork>
To: issue_tracker@your.tracker.email.domain.example
Cc: richard@test
Message-Id: <dummy_test_message_id>
This is a test submission of a new issue.
''')
handler = self.instance.MailGW(self.instance, self.db)
+ handler.trapExceptions = 0
nodeid = handler.main(message)
- if os.path.exists(os.environ['SENDMAILDEBUG']):
- error = open(os.environ['SENDMAILDEBUG']).read()
- self.assertEqual('no error', error)
+ assert not os.path.exists(SENDMAILDEBUG)
l = self.db.issue.get(nodeid, 'nosy')
l.sort()
- self.assertEqual(l, ['2', '3'])
+ 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
''')
userlist = self.db.user.list()
handler = self.instance.MailGW(self.instance, self.db)
+ handler.trapExceptions = 0
handler.main(message)
- if os.path.exists(os.environ['SENDMAILDEBUG']):
- error = open(os.environ['SENDMAILDEBUG']).read()
- self.assertEqual('no error', error)
+ assert not os.path.exists(SENDMAILDEBUG)
self.assertEqual(userlist, self.db.user.list(),
"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
+From: Chef <chef@bork.bork.bork>
To: issue_tracker@your.tracker.email.domain.example
Cc: richard@test
Message-Id: <dummy_test_message_id>
This is a test submission of a new issue.
''')
handler = self.instance.MailGW(self.instance, self.db)
+ handler.trapExceptions = 0
handler.main(message)
- if os.path.exists(os.environ['SENDMAILDEBUG']):
- error = open(os.environ['SENDMAILDEBUG']).read()
- self.assertEqual('no error', error)
+ assert not os.path.exists(SENDMAILDEBUG)
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
+From: Chef <chef@bork.bork.bork>
To: issue_tracker@your.tracker.email.domain.example
Message-Id: <dummy_test_message_id>
Subject: [issue] Testing... [nosy=mary; assignedto=richard]
This is a test submission of a new issue.
''')
handler = self.instance.MailGW(self.instance, self.db)
+ handler.trapExceptions = 0
# TODO: fix the damn config - this is apalling
self.db.config.MESSAGES_TO_AUTHOR = 'yes'
handler.main(message)
- self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+ self.compareMessages(self._get_mail(),
'''FROM: roundup-admin@your.tracker.email.domain.example
TO: chef@bork.bork.bork, mary@test, richard@test
-Content-Type: text/plain
+Content-Type: text/plain; charset=utf-8
Subject: [issue1] Testing...
To: chef@bork.bork.bork, mary@test, richard@test
-From: Chef <issue_tracker@your.tracker.email.domain.example>
+From: "Bork, Chef" <issue_tracker@your.tracker.email.domain.example>
Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
MIME-Version: 1.0
Message-Id: <dummy_test_message_id>
X-Roundup-Name: Roundup issue tracker
+X-Roundup-Loop: hello
Content-Transfer-Encoding: quoted-printable
-New submission from Chef <chef@bork.bork.bork>:
+New submission from Bork, Chef <chef@bork.bork.bork>:
This is a test submission of a new issue.
-
----------
assignedto: richard
messages: 1
nosy: Chef, mary, richard
status: unread
title: Testing...
-_________________________________________________________________________
-"Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
-http://your.tracker.url.example/issue1
-_________________________________________________________________________
+_______________________________________________________________________
+Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
+<http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
+_______________________________________________________________________
''')
# BUG
# BUG should test some binary attamchent too.
- def testFollowup(self):
- self.testNewIssue()
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ def testSimpleFollowup(self):
+ self.doNewIssue()
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
-From: richard <richard@test>
+From: mary <mary@test>
To: issue_tracker@your.tracker.email.domain.example
Message-Id: <followup_dummy_id>
In-Reply-To: <dummy_test_message_id>
-Subject: [issue1] Testing... [assignedto=mary; nosy=john]
+Subject: [issue1] Testing...
-This is a followup
+This is a second followup
''')
handler = self.instance.MailGW(self.instance, self.db)
+ handler.trapExceptions = 0
handler.main(message)
-
- self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+ self.compareMessages(self._get_mail(),
'''FROM: roundup-admin@your.tracker.email.domain.example
-TO: chef@bork.bork.bork, john@test, mary@test
-Content-Type: text/plain
+TO: chef@bork.bork.bork, richard@test
+Content-Type: text/plain; charset=utf-8
Subject: [issue1] Testing...
-To: chef@bork.bork.bork, john@test, mary@test
-From: richard <issue_tracker@your.tracker.email.domain.example>
+To: chef@bork.bork.bork, richard@test
+From: "Contrary, Mary" <issue_tracker@your.tracker.email.domain.example>
Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
MIME-Version: 1.0
Message-Id: <followup_dummy_id>
In-Reply-To: <dummy_test_message_id>
X-Roundup-Name: Roundup issue tracker
+X-Roundup-Loop: hello
Content-Transfer-Encoding: quoted-printable
-richard <richard@test> added the comment:
-
-This is a followup
+Contrary, Mary <mary@test> added the comment:
+This is a second followup
----------
-assignedto: -> mary
-nosy: +mary, john
status: unread -> chatting
-_________________________________________________________________________
-"Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
-http://your.tracker.url.example/issue1
-_________________________________________________________________________
+_______________________________________________________________________
+Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
+<http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
+_______________________________________________________________________
''')
- def testFollowup2(self):
- self.testNewIssue()
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ def testFollowup(self):
+ self.doNewIssue()
+
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
-From: mary <mary@test>
+From: richard <richard@test>
To: issue_tracker@your.tracker.email.domain.example
Message-Id: <followup_dummy_id>
In-Reply-To: <dummy_test_message_id>
-Subject: [issue1] Testing...
+Subject: [issue1] Testing... [assignedto=mary; nosy=+john]
-This is a second followup
+This is a followup
''')
handler = self.instance.MailGW(self.instance, self.db)
+ handler.trapExceptions = 0
handler.main(message)
- self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+ l = self.db.issue.get('1', 'nosy')
+ l.sort()
+ self.assertEqual(l, ['3', '4', '5', '6'])
+
+ self.compareMessages(self._get_mail(),
'''FROM: roundup-admin@your.tracker.email.domain.example
-TO: chef@bork.bork.bork, richard@test
-Content-Type: text/plain
+TO: chef@bork.bork.bork, john@test, mary@test
+Content-Type: text/plain; charset=utf-8
Subject: [issue1] Testing...
-To: chef@bork.bork.bork, richard@test
-From: mary <issue_tracker@your.tracker.email.domain.example>
+To: chef@bork.bork.bork, john@test, mary@test
+From: richard <issue_tracker@your.tracker.email.domain.example>
Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
MIME-Version: 1.0
Message-Id: <followup_dummy_id>
In-Reply-To: <dummy_test_message_id>
X-Roundup-Name: Roundup issue tracker
+X-Roundup-Loop: hello
Content-Transfer-Encoding: quoted-printable
-mary <mary@test> added the comment:
-
-This is a second followup
+richard <richard@test> added the comment:
+This is a followup
----------
+assignedto: -> mary
+nosy: +john, mary
status: unread -> chatting
-_________________________________________________________________________
-"Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
-http://your.tracker.url.example/issue1
-_________________________________________________________________________
+_______________________________________________________________________
+Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
+<http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
+_______________________________________________________________________
''')
def testFollowupTitleMatch(self):
- self.testNewIssue()
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ self.doNewIssue()
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: richard <richard@test>
To: issue_tracker@your.tracker.email.domain.example
Message-Id: <followup_dummy_id>
In-Reply-To: <dummy_test_message_id>
-Subject: Re: Testing... [assignedto=mary; nosy=john]
+Subject: Re: Testing... [assignedto=mary; nosy=+john]
This is a followup
''')
handler = self.instance.MailGW(self.instance, self.db)
+ handler.trapExceptions = 0
handler.main(message)
- self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+ self.compareMessages(self._get_mail(),
'''FROM: roundup-admin@your.tracker.email.domain.example
TO: chef@bork.bork.bork, john@test, mary@test
-Content-Type: text/plain
+Content-Type: text/plain; charset=utf-8
Subject: [issue1] Testing...
To: chef@bork.bork.bork, john@test, mary@test
From: richard <issue_tracker@your.tracker.email.domain.example>
Message-Id: <followup_dummy_id>
In-Reply-To: <dummy_test_message_id>
X-Roundup-Name: Roundup issue tracker
+X-Roundup-Loop: hello
Content-Transfer-Encoding: quoted-printable
This is a followup
-
----------
assignedto: -> mary
-nosy: +mary, john
+nosy: +john, mary
status: unread -> chatting
-_________________________________________________________________________
-"Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
-http://your.tracker.url.example/issue1
-_________________________________________________________________________
+_______________________________________________________________________
+Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
+<http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
+_______________________________________________________________________
''')
def testFollowupNosyAuthor(self):
- self.testNewIssue()
- self.instance.ADD_AUTHOR_TO_NOSY = 'yes'
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ self.doNewIssue()
+ self.db.config.ADD_AUTHOR_TO_NOSY = 'yes'
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: john@test
To: issue_tracker@your.tracker.email.domain.example
This is a followup
''')
handler = self.instance.MailGW(self.instance, self.db)
+ handler.trapExceptions = 0
handler.main(message)
- self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+ self.compareMessages(self._get_mail(),
'''FROM: roundup-admin@your.tracker.email.domain.example
TO: chef@bork.bork.bork, richard@test
-Content-Type: text/plain
+Content-Type: text/plain; charset=utf-8
Subject: [issue1] Testing...
To: chef@bork.bork.bork, richard@test
-From: john <issue_tracker@your.tracker.email.domain.example>
+From: John Doe <issue_tracker@your.tracker.email.domain.example>
Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
MIME-Version: 1.0
Message-Id: <followup_dummy_id>
In-Reply-To: <dummy_test_message_id>
X-Roundup-Name: Roundup issue tracker
+X-Roundup-Loop: hello
Content-Transfer-Encoding: quoted-printable
-john <john@test> added the comment:
+John Doe <john@test> added the comment:
This is a followup
-
----------
nosy: +john
status: unread -> chatting
-_________________________________________________________________________
-"Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
-http://your.tracker.url.example/issue1
-_________________________________________________________________________
+_______________________________________________________________________
+Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
+<http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
+_______________________________________________________________________
''')
def testFollowupNosyRecipients(self):
- self.testNewIssue()
- self.instance.ADD_RECIPIENTS_TO_NOSY = 'yes'
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ self.doNewIssue()
+ self.db.config.ADD_RECIPIENTS_TO_NOSY = 'yes'
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: richard@test
To: issue_tracker@your.tracker.email.domain.example
This is a followup
''')
handler = self.instance.MailGW(self.instance, self.db)
+ handler.trapExceptions = 0
handler.main(message)
- self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+ self.compareMessages(self._get_mail(),
'''FROM: roundup-admin@your.tracker.email.domain.example
TO: chef@bork.bork.bork
-Content-Type: text/plain
+Content-Type: text/plain; charset=utf-8
Subject: [issue1] Testing...
To: chef@bork.bork.bork
From: richard <issue_tracker@your.tracker.email.domain.example>
Message-Id: <followup_dummy_id>
In-Reply-To: <dummy_test_message_id>
X-Roundup-Name: Roundup issue tracker
+X-Roundup-Loop: hello
Content-Transfer-Encoding: quoted-printable
This is a followup
-
----------
nosy: +john
status: unread -> chatting
-_________________________________________________________________________
-"Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
-http://your.tracker.url.example/issue1
-_________________________________________________________________________
+_______________________________________________________________________
+Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
+<http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
+_______________________________________________________________________
''')
def testFollowupNosyAuthorAndCopy(self):
- self.testNewIssue()
- self.instance.ADD_AUTHOR_TO_NOSY = 'yes'
+ 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
This is a followup
''')
handler = self.instance.MailGW(self.instance, self.db)
+ handler.trapExceptions = 0
handler.main(message)
- self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+ self.compareMessages(self._get_mail(),
'''FROM: roundup-admin@your.tracker.email.domain.example
TO: chef@bork.bork.bork, john@test, richard@test
-Content-Type: text/plain
+Content-Type: text/plain; charset=utf-8
Subject: [issue1] Testing...
To: chef@bork.bork.bork, john@test, richard@test
-From: john <issue_tracker@your.tracker.email.domain.example>
+From: John Doe <issue_tracker@your.tracker.email.domain.example>
Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
MIME-Version: 1.0
Message-Id: <followup_dummy_id>
In-Reply-To: <dummy_test_message_id>
X-Roundup-Name: Roundup issue tracker
+X-Roundup-Loop: hello
Content-Transfer-Encoding: quoted-printable
-john <john@test> added the comment:
+John Doe <john@test> added the comment:
This is a followup
-
----------
nosy: +john
status: unread -> chatting
-_________________________________________________________________________
-"Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
-http://your.tracker.url.example/issue1
-_________________________________________________________________________
+_______________________________________________________________________
+Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
+<http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
+_______________________________________________________________________
''')
def testFollowupNoNosyAuthor(self):
- self.testNewIssue()
- self.instance.ADD_AUTHOR_TO_NOSY = 'no'
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ self.doNewIssue()
+ self.instance.config.ADD_AUTHOR_TO_NOSY = 'no'
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: john@test
To: issue_tracker@your.tracker.email.domain.example
This is a followup
''')
handler = self.instance.MailGW(self.instance, self.db)
+ handler.trapExceptions = 0
handler.main(message)
- self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+ self.compareMessages(self._get_mail(),
'''FROM: roundup-admin@your.tracker.email.domain.example
TO: chef@bork.bork.bork, richard@test
-Content-Type: text/plain
+Content-Type: text/plain; charset=utf-8
Subject: [issue1] Testing...
To: chef@bork.bork.bork, richard@test
-From: john <issue_tracker@your.tracker.email.domain.example>
+From: John Doe <issue_tracker@your.tracker.email.domain.example>
Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
MIME-Version: 1.0
Message-Id: <followup_dummy_id>
In-Reply-To: <dummy_test_message_id>
X-Roundup-Name: Roundup issue tracker
+X-Roundup-Loop: hello
Content-Transfer-Encoding: quoted-printable
-john <john@test> added the comment:
+John Doe <john@test> added the comment:
This is a followup
-
----------
status: unread -> chatting
-_________________________________________________________________________
-"Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
-http://your.tracker.url.example/issue1
-_________________________________________________________________________
+_______________________________________________________________________
+Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
+<http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
+_______________________________________________________________________
''')
def testFollowupNoNosyRecipients(self):
- self.testNewIssue()
- self.instance.ADD_RECIPIENTS_TO_NOSY = 'no'
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ self.doNewIssue()
+ self.instance.config.ADD_RECIPIENTS_TO_NOSY = 'no'
+ message = StringIO('''Content-Type: text/plain;
charset="iso-8859-1"
From: richard@test
To: issue_tracker@your.tracker.email.domain.example
This is a followup
''')
handler = self.instance.MailGW(self.instance, self.db)
+ handler.trapExceptions = 0
handler.main(message)
- self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
+ self.compareMessages(self._get_mail(),
'''FROM: roundup-admin@your.tracker.email.domain.example
TO: chef@bork.bork.bork
-Content-Type: text/plain
+Content-Type: text/plain; charset=utf-8
Subject: [issue1] Testing...
To: chef@bork.bork.bork
From: richard <issue_tracker@your.tracker.email.domain.example>
Message-Id: <followup_dummy_id>
In-Reply-To: <dummy_test_message_id>
X-Roundup-Name: Roundup issue tracker
+X-Roundup-Loop: hello
Content-Transfer-Encoding: quoted-printable
This is a followup
-
----------
status: unread -> chatting
-_________________________________________________________________________
-"Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
-http://your.tracker.url.example/issue1
-_________________________________________________________________________
+_______________________________________________________________________
+Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
+<http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
+_______________________________________________________________________
+
+''')
+
+ def testFollowupEmptyMessage(self):
+ self.doNewIssue()
+
+ message = StringIO('''Content-Type: text/plain;
+ charset="iso-8859-1"
+From: richard <richard@test>
+To: issue_tracker@your.tracker.email.domain.example
+Message-Id: <followup_dummy_id>
+In-Reply-To: <dummy_test_message_id>
+Subject: [issue1] Testing... [assignedto=mary; nosy=+john]
+
+''')
+ handler = self.instance.MailGW(self.instance, self.db)
+ handler.trapExceptions = 0
+ handler.main(message)
+ l = self.db.issue.get('1', 'nosy')
+ l.sort()
+ self.assertEqual(l, ['3', '4', '5', '6'])
+
+ # should be no file created (ie. no message)
+ assert not os.path.exists(SENDMAILDEBUG)
+
+ def testNosyRemove(self):
+ self.doNewIssue()
+
+ message = StringIO('''Content-Type: text/plain;
+ charset="iso-8859-1"
+From: richard <richard@test>
+To: issue_tracker@your.tracker.email.domain.example
+Message-Id: <followup_dummy_id>
+In-Reply-To: <dummy_test_message_id>
+Subject: [issue1] Testing... [nosy=-richard]
''')
+ handler = self.instance.MailGW(self.instance, self.db)
+ handler.trapExceptions = 0
+ handler.main(message)
+ l = self.db.issue.get('1', 'nosy')
+ l.sort()
+ self.assertEqual(l, ['3'])
+
+ # NO NOSY MESSAGE SHOULD BE SENT!
+ assert not os.path.exists(SENDMAILDEBUG)
+
+ def testNewUserAuthor(self):
+ # first without the permission
+ # heh... just ignore the API for a second ;)
+ self.db.security.role['anonymous'].permissions=[]
+ anonid = self.db.user.lookup('anonymous')
+ self.db.user.set(anonid, roles='Anonymous')
+
+ self.db.security.hasPermission('Email Registration', anonid)
+ l = self.db.user.list()
+ l.sort()
+ s = '''Content-Type: text/plain;
+ charset="iso-8859-1"
+From: fubar <fubar@bork.bork.bork>
+To: issue_tracker@your.tracker.email.domain.example
+Message-Id: <dummy_test_message_id>
+Subject: [issue] Testing...
+
+This is a test submission of a new issue.
+'''
+ message = StringIO(s)
+ handler = self.instance.MailGW(self.instance, self.db)
+ handler.trapExceptions = 0
+ self.assertRaises(Unauthorized, handler.main, message)
+ m = self.db.user.list()
+ m.sort()
+ self.assertEqual(l, m)
+
+ # now with the permission
+ p = self.db.security.getPermission('Email Registration')
+ self.db.security.role['anonymous'].permissions=[p]
+ handler = self.instance.MailGW(self.instance, self.db)
+ handler.trapExceptions = 0
+ message = StringIO(s)
+ handler.main(message)
+ m = self.db.user.list()
+ m.sort()
+ self.assertNotEqual(l, m)
def testEnc01(self):
- self.testNewIssue()
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ self.doNewIssue()
+ 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(self._get_mail(),
'''FROM: roundup-admin@your.tracker.email.domain.example
TO: chef@bork.bork.bork, richard@test
-Content-Type: text/plain
+Content-Type: text/plain; charset=utf-8
Subject: [issue1] Testing...
To: chef@bork.bork.bork, richard@test
-From: mary <issue_tracker@your.tracker.email.domain.example>
+From: "Contrary, Mary" <issue_tracker@your.tracker.email.domain.example>
Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
MIME-Version: 1.0
Message-Id: <followup_dummy_id>
In-Reply-To: <dummy_test_message_id>
X-Roundup-Name: Roundup issue tracker
+X-Roundup-Loop: hello
Content-Transfer-Encoding: quoted-printable
-mary <mary@test> added the comment:
+Contrary, Mary <mary@test> added the comment:
-A message with encoding (encoded oe =F6)
+A message with encoding (encoded oe =C3=B6)
----------
status: unread -> chatting
-_________________________________________________________________________
-"Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
-http://your.tracker.url.example/issue1
-_________________________________________________________________________
+_______________________________________________________________________
+Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
+<http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
+_______________________________________________________________________
''')
def testMultipartEnc01(self):
- self.testNewIssue()
- message = cStringIO.StringIO('''Content-Type: text/plain;
+ self.doNewIssue()
+ 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(self._get_mail(),
'''FROM: roundup-admin@your.tracker.email.domain.example
TO: chef@bork.bork.bork, richard@test
-Content-Type: text/plain
+Content-Type: text/plain; charset=utf-8
Subject: [issue1] Testing...
To: chef@bork.bork.bork, richard@test
-From: mary <issue_tracker@your.tracker.email.domain.example>
+From: "Contrary, Mary" <issue_tracker@your.tracker.email.domain.example>
Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
MIME-Version: 1.0
Message-Id: <followup_dummy_id>
In-Reply-To: <dummy_test_message_id>
X-Roundup-Name: Roundup issue tracker
+X-Roundup-Loop: hello
Content-Transfer-Encoding: quoted-printable
-mary <mary@test> added the comment:
+Contrary, Mary <mary@test> added the comment:
-A message with first part encoded (encoded oe =F6)
+A message with first part encoded (encoded oe =C3=B6)
----------
status: unread -> chatting
-_________________________________________________________________________
-"Roundup issue tracker" <issue_tracker@your.tracker.email.domain.example>
-http://your.tracker.url.example/issue1
-_________________________________________________________________________
+_______________________________________________________________________
+Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
+<http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
+_______________________________________________________________________
''')
-class ExtMailgwTestCase(MailgwTestCase):
- schema = 'extended'
+ def testContentDisposition(self):
+ self.doNewIssue()
+ message = StringIO('''Content-Type: text/plain;
+ charset="iso-8859-1"
+From: mary <mary@test>
+To: issue_tracker@your.tracker.email.domain.example
+Message-Id: <followup_dummy_id>
+In-Reply-To: <dummy_test_message_id>
+Subject: [issue1] Testing...
+Content-Type: multipart/mixed; boundary="bCsyhTFzCvuiizWE"
+Content-Disposition: inline
+
+
+--bCsyhTFzCvuiizWE
+Content-Type: text/plain; charset=us-ascii
+Content-Disposition: inline
-def suite():
- l = [unittest.makeSuite(MailgwTestCase),
- unittest.makeSuite(ExtMailgwTestCase, 'test')
- ]
- return unittest.TestSuite(l)
+test attachment binary
+--bCsyhTFzCvuiizWE
+Content-Type: application/octet-stream
+Content-Disposition: attachment; filename="main.dvi"
+
+xxxxxx
+
+--bCsyhTFzCvuiizWE--
+''')
+ handler = self.instance.MailGW(self.instance, self.db)
+ handler.trapExceptions = 0
+ handler.main(message)
+ messages = self.db.issue.get('1', 'messages')
+ messages.sort()
+ file = self.db.msg.get(messages[-1], 'files')[0]
+ self.assertEqual(self.db.file.get(file, 'name'), 'main.dvi')
+
+ def testFollowupStupidQuoting(self):
+ self.doNewIssue()
+
+ message = StringIO('''Content-Type: text/plain;
+ charset="iso-8859-1"
+From: richard <richard@test>
+To: issue_tracker@your.tracker.email.domain.example
+Message-Id: <followup_dummy_id>
+In-Reply-To: <dummy_test_message_id>
+Subject: Re: "[issue1] Testing... "
+
+This is a followup
+''')
+ handler = self.instance.MailGW(self.instance, self.db)
+ handler.trapExceptions = 0
+ handler.main(message)
+
+ self.compareMessages(self._get_mail(),
+'''FROM: roundup-admin@your.tracker.email.domain.example
+TO: chef@bork.bork.bork
+Content-Type: text/plain; charset=utf-8
+Subject: [issue1] Testing...
+To: chef@bork.bork.bork
+From: richard <issue_tracker@your.tracker.email.domain.example>
+Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
+MIME-Version: 1.0
+Message-Id: <followup_dummy_id>
+In-Reply-To: <dummy_test_message_id>
+X-Roundup-Name: Roundup issue tracker
+X-Roundup-Loop: hello
+Content-Transfer-Encoding: quoted-printable
+
+
+richard <richard@test> added the comment:
+
+This is a followup
+
+----------
+status: unread -> chatting
+_______________________________________________________________________
+Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
+<http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1>
+_______________________________________________________________________
+''')
+
+ def testEmailQuoting(self):
+ self.instance.config.EMAIL_KEEP_QUOTED_TEXT = 'no'
+ self.innerTestQuoting('''This is a followup
+''')
+
+ def testEmailQuotingRemove(self):
+ self.instance.config.EMAIL_KEEP_QUOTED_TEXT = 'yes'
+ self.innerTestQuoting('''Blah blah wrote:
+> Blah bklaskdfj sdf asdf jlaskdf skj sdkfjl asdf
+> skdjlkjsdfalsdkfjasdlfkj dlfksdfalksd fj
+>
+
+This is a followup
+''')
+
+ def innerTestQuoting(self, expect):
+ nodeid = self.doNewIssue()
+
+ messages = self.db.issue.get(nodeid, 'messages')
+
+ message = StringIO('''Content-Type: text/plain;
+ charset="iso-8859-1"
+From: richard <richard@test>
+To: issue_tracker@your.tracker.email.domain.example
+Message-Id: <followup_dummy_id>
+In-Reply-To: <dummy_test_message_id>
+Subject: Re: [issue1] Testing...
+
+Blah blah wrote:
+> Blah bklaskdfj sdf asdf jlaskdf skj sdkfjl asdf
+> skdjlkjsdfalsdkfjasdlfkj dlfksdfalksd fj
+>
+
+This is a followup
+''')
+ handler = self.instance.MailGW(self.instance, self.db)
+ handler.trapExceptions = 0
+ handler.main(message)
+
+ # figure the new message id
+ newmessages = self.db.issue.get(nodeid, 'messages')
+ for msg in messages:
+ newmessages.remove(msg)
+ messageid = newmessages[0]
+
+ self.compareMessages(self.db.msg.get(messageid, 'content'), expect)
+
+ def testUserLookup(self):
+ i = self.db.user.create(username='user1', address='user1@foo.com')
+ self.assertEqual(uidFromAddress(self.db, ('', 'user1@foo.com'), 0), i)
+ self.assertEqual(uidFromAddress(self.db, ('', 'USER1@foo.com'), 0), i)
+ i = self.db.user.create(username='user2', address='USER2@foo.com')
+ self.assertEqual(uidFromAddress(self.db, ('', 'USER2@foo.com'), 0), i)
+ self.assertEqual(uidFromAddress(self.db, ('', 'user2@foo.com'), 0), i)
+
+ def testUserAlternateLookup(self):
+ i = self.db.user.create(username='user1', address='user1@foo.com',
+ alternate_addresses='user1@bar.com')
+ self.assertEqual(uidFromAddress(self.db, ('', 'user1@bar.com'), 0), i)
+ self.assertEqual(uidFromAddress(self.db, ('', 'USER1@bar.com'), 0), i)
+
+ def testUserCreate(self):
+ i = uidFromAddress(self.db, ('', 'user@foo.com'), 1)
+ self.assertNotEqual(uidFromAddress(self.db, ('', 'user@bar.com'), 1), i)
+
+ def testRFC2822(self):
+ ascii_header = "[issue243] This is a \"test\" - with 'quotation' marks"
+ unicode_header = '[issue244] \xd0\xb0\xd0\xbd\xd0\xb4\xd1\x80\xd0\xb5\xd0\xb9'
+ unicode_encoded = '=?utf-8?q?[issue244]_=D0=B0=D0=BD=D0=B4=D1=80=D0=B5=D0=B9?='
+ self.assertEqual(rfc2822.encode_header(ascii_header), ascii_header)
+ self.assertEqual(rfc2822.encode_header(unicode_header), unicode_encoded)
+
+ def testRegistrationConfirmation(self):
+ otk = "Aj4euk4LZSAdwePohj90SME5SpopLETL"
+ self.db.otks.set(otk, username='johannes', __time='')
+ message = StringIO('''Content-Type: text/plain;
+ charset="iso-8859-1"
+From: Chef <chef@bork.bork.bork>
+To: issue_tracker@your.tracker.email.domain.example
+Cc: richard@test
+Message-Id: <dummy_test_message_id>
+Subject: Re: Complete your registration to Roundup issue tracker\r
+ -- key %s
+
+This is a test confirmation of registration.
+''' % otk)
+ handler = self.instance.MailGW(self.instance, self.db)
+ handler.trapExceptions = 0
+ handler.main(message)
+
+ self.db.user.lookup('johannes')
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(MailgwTestCase))
+ return suite
+
+if __name__ == '__main__':
+ runner = unittest.TextTestRunner()
+ unittest.main(testRunner=runner)
-#
-# $Log: not supported by cvs2svn $
-# Revision 1.18 2002/05/15 03:27:16 richard
-# . fixed SCRIPT_NAME in ZRoundup for instances not at top level of Zope
-# (thanks dman)
-# . fixed some sorting issues that were breaking some unit tests under py2.2
-# . mailgw test output dir was confusing the init test (but only on 2.2 *shrug*)
-#
-# fixed bug in the init unit test that meant only the bsddb test ran if it
-# could (it clobbered the anydbm test)
-#
-# Revision 1.17 2002/05/02 07:56:34 richard
-# . added option to automatically add the authors and recipients of messages
-# to the nosy lists with the options ADD_AUTHOR_TO_NOSY (default 'new') and
-# ADD_RECIPIENTS_TO_NOSY (default 'new'). These settings emulate the current
-# behaviour. Setting them to 'yes' will add the author/recipients to the nosy
-# on messages that create issues and followup messages.
-# . added missing documentation for a few of the config option values
-#
-# Revision 1.16 2002/03/19 21:58:11 grubert
-# . for python2.1 test_mailgw compareString allows an extra trailing empty line (for quopri.
-#
-# Revision 1.15 2002/03/19 06:37:00 richard
-# Made the email checking spit out a diff - much easier to spot the problem!
-#
-# Revision 1.14 2002/03/18 18:32:00 rochecompaan
-# All messages sent to the nosy list are now encoded as quoted-printable.
-#
-# Revision 1.13 2002/02/15 07:08:45 richard
-# . Alternate email addresses are now available for users. See the MIGRATION
-# file for info on how to activate the feature.
-#
-# Revision 1.12 2002/02/15 00:13:38 richard
-# . #503204 ] mailgw needs a default class
-# - partially done - the setting of additional properties can wait for a
-# better configuration system.
-#
-# Revision 1.11 2002/02/14 23:38:12 richard
-# Fixed the unit tests for the mailgw re: the x-roundup-name header.
-# Also made the test runner more user-friendly:
-# ./run_tests - detect all tests in test/test_<name>.py and run them
-# ./run_tests <name> - run only test/test_<name>.py
-# eg ./run_tests mailgw - run the mailgw test from test/test_mailgw.py
-#
-# Revision 1.10 2002/02/12 08:08:55 grubert
-# . Clean up mail handling, multipart handling.
-#
-# Revision 1.9 2002/02/05 14:15:29 grubert
-# . respect encodings in non multipart messages.
-#
-# Revision 1.8 2002/02/04 09:40:21 grubert
-# . add test for multipart messages with first part being encoded.
-#
-# Revision 1.7 2002/01/22 11:54:45 rochecompaan
-# Fixed status change in mail gateway.
-#
-# Revision 1.6 2002/01/21 10:05:48 rochecompaan
-# Feature:
-# . the mail gateway now responds with an error message when invalid
-# values for arguments are specified for link or multilink properties
-# . modified unit test to check nosy and assignedto when specified as
-# arguments
-#
-# Fixed:
-# . fixed setting nosy as argument in subject line
-#
-# Revision 1.5 2002/01/15 00:12:40 richard
-# #503340 ] creating issue with [asignedto=p.ohly]
-#
-# Revision 1.4 2002/01/14 07:12:15 richard
-# removed file writing from tests...
-#
-# Revision 1.3 2002/01/14 02:20:15 richard
-# . changed all config accesses so they access either the instance or the
-# config attriubute on the db. This means that all config is obtained from
-# instance_config instead of the mish-mash of classes. This will make
-# switching to a ConfigParser setup easier too, I hope.
-#
-# At a minimum, this makes migration a _little_ easier (a lot easier in the
-# 0.5.0 switch, I hope!)
-#
-# Revision 1.2 2002/01/11 23:22:29 richard
-# . #502437 ] rogue reactor and unittest
-# in short, the nosy reactor was modifying the nosy list. That code had
-# been there for a long time, and I suspsect it was there because we
-# weren't generating the nosy list correctly in other places of the code.
-# We're now doing that, so the nosy-modifying code can go away from the
-# nosy reactor.
-#
-# Revision 1.1 2002/01/02 02:31:38 richard
-# Sorry for the huge checkin message - I was only intending to implement #496356
-# but I found a number of places where things had been broken by transactions:
-# . modified ROUNDUPDBSENDMAILDEBUG to be SENDMAILDEBUG and hold a filename
-# for _all_ roundup-generated smtp messages to be sent to.
-# . the transaction cache had broken the roundupdb.Class set() reactors
-# . newly-created author users in the mailgw weren't being committed to the db
-#
-# Stuff that made it into CHANGES.txt (ie. the stuff I was actually working
-# on when I found that stuff :):
-# . #496356 ] Use threading in messages
-# . detectors were being registered multiple times
-# . added tests for mailgw
-# . much better attaching of erroneous messages in the mail gateway
-#
-#
-#
-#
# vim: set filetype=python ts=4 sw=4 et si