Code

Fixed the unit tests for the new multilist controls in the mailgw
[roundup.git] / test / test_mailgw.py
index 93a1f8fb5b955affa47a0ed2c928b764fa0defb6..e8325bc5a89fdd071b412cb05ef3e1d4e5ecd39b 100644 (file)
@@ -8,10 +8,18 @@
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 #
-# $Id: test_mailgw.py,v 1.20 2002-05-29 01:16:17 richard Exp $
+# $Id: test_mailgw.py,v 1.23 2002-07-14 02:02:43 richard Exp $
 
 import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys, difflib
 
+# 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 roundup.mailgw import MailGW
 from roundup import init, instance
 
@@ -89,7 +97,7 @@ class MailgwTestCase(unittest.TestCase, DiffHelper):
     def doNewIssue(self):
         message = cStringIO.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>
@@ -98,6 +106,7 @@ Subject: [issue] Testing...
 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()
@@ -113,7 +122,7 @@ This is a test submission of a new issue.
         self.instance.ADD_AUTHOR_TO_NOSY = 'yes'
         message = cStringIO.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>
@@ -122,6 +131,7 @@ Subject: [issue] Testing...
 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()
@@ -142,6 +152,7 @@ This is a test submission of a new issue.
 ''')
         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()
@@ -152,7 +163,7 @@ This is a test submission of a new issue.
     def testNewIssueNoClass(self):
         message = cStringIO.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>
@@ -161,6 +172,7 @@ Subject: Testing...
 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()
@@ -169,7 +181,7 @@ This is a test submission of a new issue.
     def testNewIssueAuthMsg(self):
         message = cStringIO.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]
@@ -177,6 +189,7 @@ 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)
@@ -187,8 +200,8 @@ TO: chef@bork.bork.bork, mary@test, richard@test
 Content-Type: text/plain
 Subject: [issue1] Testing...
 To: chef@bork.bork.bork, mary@test, richard@test
-From: Chef <issue_tracker@your.tracker.email.domain.example>
-Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
+From: "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
@@ -234,6 +247,7 @@ Subject: [issue1] Testing...
 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(),
 '''FROM: roundup-admin@your.tracker.email.domain.example
@@ -241,8 +255,8 @@ TO: chef@bork.bork.bork, richard@test
 Content-Type: text/plain
 Subject: [issue1] Testing...
 To: chef@bork.bork.bork, richard@test
-From: mary <issue_tracker@your.tracker.email.domain.example>
-Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
+From: "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>
@@ -272,11 +286,12 @@ 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]
+Subject: [issue1] Testing... [assignedto=mary; nosy=+john]
 
 This is a followup
 ''')
         handler = self.instance.MailGW(self.instance, self.db)
+        handler.trapExceptions = 0
         handler.main(message)
         l = self.db.issue.get('1', 'nosy')
         l.sort()
@@ -288,8 +303,8 @@ TO: chef@bork.bork.bork, john@test, mary@test
 Content-Type: text/plain
 Subject: [issue1] Testing...
 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>
+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>
@@ -320,11 +335,12 @@ 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(),
@@ -333,8 +349,8 @@ TO: chef@bork.bork.bork, john@test, mary@test
 Content-Type: text/plain
 Subject: [issue1] Testing...
 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>
+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>
@@ -371,6 +387,7 @@ Subject: [issue1] Testing...
 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(),
@@ -379,8 +396,8 @@ TO: chef@bork.bork.bork, richard@test
 Content-Type: text/plain
 Subject: [issue1] Testing...
 To: chef@bork.bork.bork, richard@test
-From: john <issue_tracker@your.tracker.email.domain.example>
-Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
+From: "john" <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>
@@ -418,6 +435,7 @@ Subject: [issue1] Testing...
 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(),
@@ -426,8 +444,8 @@ TO: chef@bork.bork.bork
 Content-Type: text/plain
 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>
+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>
@@ -465,6 +483,7 @@ Subject: [issue1] Testing...
 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(),
@@ -473,8 +492,8 @@ TO: chef@bork.bork.bork, john@test, richard@test
 Content-Type: text/plain
 Subject: [issue1] Testing...
 To: chef@bork.bork.bork, john@test, richard@test
-From: john <issue_tracker@your.tracker.email.domain.example>
-Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
+From: "john" <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>
@@ -511,6 +530,7 @@ Subject: [issue1] Testing...
 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(),
@@ -519,8 +539,8 @@ TO: chef@bork.bork.bork, richard@test
 Content-Type: text/plain
 Subject: [issue1] Testing...
 To: chef@bork.bork.bork, richard@test
-From: john <issue_tracker@your.tracker.email.domain.example>
-Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
+From: "john" <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>
@@ -557,6 +577,7 @@ Subject: [issue1] Testing...
 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(),
@@ -565,8 +586,8 @@ TO: chef@bork.bork.bork
 Content-Type: text/plain
 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>
+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>
@@ -601,6 +622,7 @@ 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()
@@ -626,6 +648,7 @@ A message with encoding (encoded oe =F6)
 
 ''')
         handler = self.instance.MailGW(self.instance, self.db)
+        handler.trapExceptions = 0
         handler.main(message)
         self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
 '''FROM: roundup-admin@your.tracker.email.domain.example
@@ -633,8 +656,8 @@ TO: chef@bork.bork.bork, richard@test
 Content-Type: text/plain
 Subject: [issue1] Testing...
 To: chef@bork.bork.bork, richard@test
-From: mary <issue_tracker@your.tracker.email.domain.example>
-Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
+From: "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>
@@ -679,6 +702,7 @@ A message with first part encoded (encoded oe =F6)
 
 ''')
         handler = self.instance.MailGW(self.instance, self.db)
+        handler.trapExceptions = 0
         handler.main(message)
         self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(),
 '''FROM: roundup-admin@your.tracker.email.domain.example
@@ -686,8 +710,8 @@ TO: chef@bork.bork.bork, richard@test
 Content-Type: text/plain
 Subject: [issue1] Testing...
 To: chef@bork.bork.bork, richard@test
-From: mary <issue_tracker@your.tracker.email.domain.example>
-Reply-To: Roundup issue tracker <issue_tracker@your.tracker.email.domain.example>
+From: "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>
@@ -719,6 +743,28 @@ def suite():
 
 #
 # $Log: not supported by cvs2svn $
+# Revision 1.22  2002/07/09 01:21:24  richard
+# Added ability for unit tests to turn off exception handling in mailgw so
+# that exceptions are reported earlier (and hence make sense).
+#
+# Revision 1.21  2002/06/18 03:59:59  dman13
+# Updated message strings to match the RFC822 address quoting performed
+# by the 'email' and 'rfc822' modules.  The verification really should
+# use a RFC2822 message parser rather than literal string comparisions
+# to allow for legal variations in messages.
+#
+# Revision 1.20  2002/05/29 01:16:17  richard
+# Sorry about this huge checkin! It's fixing a lot of related stuff in one go
+# though.
+#
+# . #541941 ] changing multilink properties by mail
+# . #526730 ] search for messages capability
+# . #505180 ] split MailGW.handle_Message
+#   - also changed cgi client since it was duplicating the functionality
+# . build htmlbase if tests are run using CVS checkout (removed note from
+#   installation.txt)
+# . don't create an empty message on email issue creation if the email is empty
+#
 # Revision 1.19  2002/05/23 04:26:05  richard
 # 'I must run unit tests before committing\n' * 100
 #