From: richard Date: Thu, 17 Apr 2003 06:51:44 +0000 (+0000) Subject: fixes to unit tests for recent changes X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=527a7a1ac36f6984db2e1bc802dfcaa5f8404cbc;p=roundup.git fixes to unit tests for recent changes git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1664 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/CHANGES.txt b/CHANGES.txt index 900ea99..2a93850 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -63,7 +63,6 @@ Feature: - Roundup templates are now distributed much more sanely, allowing for 3rd-party templates. - Fixed: - applied unicode patch. All data is stored in utf-8. Incoming messages converted from any encoding to utf-8, outgoing messages are encoded diff --git a/roundup/mailgw.py b/roundup/mailgw.py index 1a5332b..66102eb 100644 --- a/roundup/mailgw.py +++ b/roundup/mailgw.py @@ -73,7 +73,7 @@ are calling the create() method to create a new node). If an auditor raises an exception, the original message is bounced back to the sender with the explanatory message given in the exception. -$Id: mailgw.py,v 1.115 2003-04-17 03:37:59 richard Exp $ +$Id: mailgw.py,v 1.116 2003-04-17 06:51:44 richard Exp $ ''' import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri @@ -1024,7 +1024,24 @@ def uidFromAddress(db, address, create=1, **user_props): # couldn't match address or username, so create a new user if create: - return db.user.create(username=address, address=address, + # generate a username + if '@' in address: + username = address.split('@')[0] + else: + username = address + trying = username + n = 0 + while 1: + try: + # does this username exist already? + db.user.lookup(trying) + except KeyError: + break + n += 1 + trying = username + str(n) + + # create! + return db.user.create(username=trying, address=address, realname=realname, roles=db.config.NEW_EMAIL_USER_ROLES, password=password.Password(password.generatePassword()), **user_props) diff --git a/run_tests b/run_tests index febf5e5..0f0445c 100755 --- a/run_tests +++ b/run_tests @@ -9,14 +9,7 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # -# $Id: run_tests,v 1.8 2002-09-10 01:07:04 richard Exp $ - -# make sure we have the htmlbase -try: - from roundup.templates.classic import htmlbase -except ImportError: - import setup - setup.buildTemplates() +# $Id: run_tests,v 1.9 2003-04-17 06:51:44 richard Exp $ from test import go import sys diff --git a/test/test_cgi.py b/test/test_cgi.py index 85319e3..d87f2ec 100644 --- a/test/test_cgi.py +++ b/test/test_cgi.py @@ -8,7 +8,7 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # -# $Id: test_cgi.py,v 1.14 2003-03-26 06:46:17 richard Exp $ +# $Id: test_cgi.py,v 1.15 2003-04-17 06:51:44 richard Exp $ import unittest, os, shutil, errno, sys, difflib, cgi, re @@ -45,7 +45,7 @@ class FormTestCase(unittest.TestCase): except OSError, error: if error.errno not in (errno.ENOENT, errno.ESRCH): raise # create the instance - init.install(self.dirname, 'classic') + init.install(self.dirname, 'templates/classic') init.write_select_db(self.dirname, 'anydbm') init.initialise(self.dirname, 'sekrit') # check we can load the package diff --git a/test/test_init.py b/test/test_init.py index b58d0ce..e84c695 100644 --- a/test/test_init.py +++ b/test/test_init.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: test_init.py,v 1.22 2003-03-18 00:50:24 richard Exp $ +# $Id: test_init.py,v 1.23 2003-04-17 06:51:44 richard Exp $ import unittest, os, shutil, errno, imp, sys @@ -43,7 +43,7 @@ class ClassicTestCase(MyTestCase): ae = self.assertEqual # create the instance - init.install(self.dirname, 'classic') + init.install(self.dirname, 'templates/classic') init.write_select_db(self.dirname, self.backend) init.initialise(self.dirname, 'sekrit') diff --git a/test/test_mailgw.py b/test/test_mailgw.py index 65a1eea..138059b 100644 --- a/test/test_mailgw.py +++ b/test/test_mailgw.py @@ -8,7 +8,7 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # -# $Id: test_mailgw.py,v 1.43 2003-04-10 05:11:58 richard Exp $ +# $Id: test_mailgw.py,v 1.44 2003-04-17 06:51:44 richard Exp $ import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys, difflib import rfc822 @@ -69,7 +69,7 @@ class MailgwTestCase(unittest.TestCase, DiffHelper): except OSError, error: if error.errno not in (errno.ENOENT, errno.ESRCH): raise # create the instance - init.install(self.dirname, 'classic') + init.install(self.dirname, 'templates/classic') init.write_select_db(self.dirname, 'anydbm') init.initialise(self.dirname, 'sekrit') # check we can load the package @@ -215,7 +215,6 @@ New submission from Bork, Chef : This is a test submission of a new issue. - ---------- assignedto: richard messages: 1 @@ -272,7 +271,6 @@ Contrary, Mary added the comment: This is a second followup - ---------- status: unread -> chatting _______________________________________________________________________ @@ -321,7 +319,6 @@ richard added the comment: This is a followup - ---------- assignedto: -> mary nosy: +john, mary @@ -368,7 +365,6 @@ richard added the comment: This is a followup - ---------- assignedto: -> mary nosy: +john, mary @@ -416,7 +412,6 @@ John Doe added the comment: This is a followup - ---------- nosy: +john status: unread -> chatting @@ -465,7 +460,6 @@ richard added the comment: This is a followup - ---------- nosy: +john status: unread -> chatting @@ -514,7 +508,6 @@ John Doe added the comment: This is a followup - ---------- nosy: +john status: unread -> chatting @@ -562,7 +555,6 @@ John Doe added the comment: This is a followup - ---------- status: unread -> chatting _______________________________________________________________________ @@ -610,7 +602,6 @@ richard added the comment: This is a followup - ---------- status: unread -> chatting _______________________________________________________________________ @@ -620,6 +611,28 @@ _______________________________________________________________________ ''') + def testFollowupEmptyMessage(self): + self.doNewIssue() + + message = cStringIO.StringIO('''Content-Type: text/plain; + charset="iso-8859-1" +From: richard +To: issue_tracker@your.tracker.email.domain.example +Message-Id: +In-Reply-To: +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(os.environ['SENDMAILDEBUG']) + def testNosyRemove(self): self.doNewIssue() @@ -854,7 +867,6 @@ richard added the comment: This is a followup - ---------- status: unread -> chatting _______________________________________________________________________ @@ -918,6 +930,10 @@ This is a followup self.assertEqual(uidFromAddress(self.db, ('', 'USER2@foo.com'), 0), i) self.assertEqual(uidFromAddress(self.db, ('', 'user2@foo.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 suite(): l = [unittest.makeSuite(MailgwTestCase), ]