Skip to content

Commit 35ca8bf

Browse files
author
Richard Jones
committed
fixes to unit tests for recent changes
1 parent 434f806 commit 35ca8bf

File tree

6 files changed

+52
-27
lines changed

6 files changed

+52
-27
lines changed

CHANGES.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ Feature:
6363
- Roundup templates are now distributed much more sanely, allowing for
6464
3rd-party templates.
6565

66-
6766
Fixed:
6867
- applied unicode patch. All data is stored in utf-8. Incoming messages
6968
converted from any encoding to utf-8, outgoing messages are encoded

roundup/mailgw.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class node. Any parts of other types are each stored in separate files
7373
an exception, the original message is bounced back to the sender with the
7474
explanatory message given in the exception.
7575
76-
$Id: mailgw.py,v 1.115 2003-04-17 03:37:59 richard Exp $
76+
$Id: mailgw.py,v 1.116 2003-04-17 06:51:44 richard Exp $
7777
'''
7878

7979
import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri
@@ -1024,7 +1024,24 @@ def uidFromAddress(db, address, create=1, **user_props):
10241024

10251025
# couldn't match address or username, so create a new user
10261026
if create:
1027-
return db.user.create(username=address, address=address,
1027+
# generate a username
1028+
if '@' in address:
1029+
username = address.split('@')[0]
1030+
else:
1031+
username = address
1032+
trying = username
1033+
n = 0
1034+
while 1:
1035+
try:
1036+
# does this username exist already?
1037+
db.user.lookup(trying)
1038+
except KeyError:
1039+
break
1040+
n += 1
1041+
trying = username + str(n)
1042+
1043+
# create!
1044+
return db.user.create(username=trying, address=address,
10281045
realname=realname, roles=db.config.NEW_EMAIL_USER_ROLES,
10291046
password=password.Password(password.generatePassword()),
10301047
**user_props)

run_tests

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,7 @@
99
# but WITHOUT ANY WARRANTY; without even the implied warranty of
1010
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1111
#
12-
# $Id: run_tests,v 1.8 2002-09-10 01:07:04 richard Exp $
13-
14-
# make sure we have the htmlbase
15-
try:
16-
from roundup.templates.classic import htmlbase
17-
except ImportError:
18-
import setup
19-
setup.buildTemplates()
12+
# $Id: run_tests,v 1.9 2003-04-17 06:51:44 richard Exp $
2013

2114
from test import go
2215
import sys

test/test_cgi.py

Lines changed: 2 additions & 2 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_cgi.py,v 1.14 2003-03-26 06:46:17 richard Exp $
11+
# $Id: test_cgi.py,v 1.15 2003-04-17 06:51:44 richard Exp $
1212

1313
import unittest, os, shutil, errno, sys, difflib, cgi, re
1414

@@ -45,7 +45,7 @@ def setUp(self):
4545
except OSError, error:
4646
if error.errno not in (errno.ENOENT, errno.ESRCH): raise
4747
# create the instance
48-
init.install(self.dirname, 'classic')
48+
init.install(self.dirname, 'templates/classic')
4949
init.write_select_db(self.dirname, 'anydbm')
5050
init.initialise(self.dirname, 'sekrit')
5151
# check we can load the package

test/test_init.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: test_init.py,v 1.22 2003-03-18 00:50:24 richard Exp $
18+
# $Id: test_init.py,v 1.23 2003-04-17 06:51:44 richard Exp $
1919

2020
import unittest, os, shutil, errno, imp, sys
2121

@@ -43,7 +43,7 @@ def testCreation(self):
4343
ae = self.assertEqual
4444

4545
# create the instance
46-
init.install(self.dirname, 'classic')
46+
init.install(self.dirname, 'templates/classic')
4747
init.write_select_db(self.dirname, self.backend)
4848
init.initialise(self.dirname, 'sekrit')
4949

test/test_mailgw.py

Lines changed: 28 additions & 12 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.43 2003-04-10 05:11:58 richard Exp $
11+
# $Id: test_mailgw.py,v 1.44 2003-04-17 06:51:44 richard Exp $
1212

1313
import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys, difflib
1414
import rfc822
@@ -69,7 +69,7 @@ def setUp(self):
6969
except OSError, error:
7070
if error.errno not in (errno.ENOENT, errno.ESRCH): raise
7171
# create the instance
72-
init.install(self.dirname, 'classic')
72+
init.install(self.dirname, 'templates/classic')
7373
init.write_select_db(self.dirname, 'anydbm')
7474
init.initialise(self.dirname, 'sekrit')
7575
# check we can load the package
@@ -215,7 +215,6 @@ def testNewIssueAuthMsg(self):
215215
216216
This is a test submission of a new issue.
217217
218-
219218
----------
220219
assignedto: richard
221220
messages: 1
@@ -272,7 +271,6 @@ def testSimpleFollowup(self):
272271
273272
This is a second followup
274273
275-
276274
----------
277275
status: unread -> chatting
278276
_______________________________________________________________________
@@ -321,7 +319,6 @@ def testFollowup(self):
321319
322320
This is a followup
323321
324-
325322
----------
326323
assignedto: -> mary
327324
nosy: +john, mary
@@ -368,7 +365,6 @@ def testFollowupTitleMatch(self):
368365
369366
This is a followup
370367
371-
372368
----------
373369
assignedto: -> mary
374370
nosy: +john, mary
@@ -416,7 +412,6 @@ def testFollowupNosyAuthor(self):
416412
417413
This is a followup
418414
419-
420415
----------
421416
nosy: +john
422417
status: unread -> chatting
@@ -465,7 +460,6 @@ def testFollowupNosyRecipients(self):
465460
466461
This is a followup
467462
468-
469463
----------
470464
nosy: +john
471465
status: unread -> chatting
@@ -514,7 +508,6 @@ def testFollowupNosyAuthorAndCopy(self):
514508
515509
This is a followup
516510
517-
518511
----------
519512
nosy: +john
520513
status: unread -> chatting
@@ -562,7 +555,6 @@ def testFollowupNoNosyAuthor(self):
562555
563556
This is a followup
564557
565-
566558
----------
567559
status: unread -> chatting
568560
_______________________________________________________________________
@@ -610,7 +602,6 @@ def testFollowupNoNosyRecipients(self):
610602
611603
This is a followup
612604
613-
614605
----------
615606
status: unread -> chatting
616607
_______________________________________________________________________
@@ -620,6 +611,28 @@ def testFollowupNoNosyRecipients(self):
620611
621612
''')
622613

614+
def testFollowupEmptyMessage(self):
615+
self.doNewIssue()
616+
617+
message = cStringIO.StringIO('''Content-Type: text/plain;
618+
charset="iso-8859-1"
619+
From: richard <richard@test>
620+
621+
Message-Id: <followup_dummy_id>
622+
In-Reply-To: <dummy_test_message_id>
623+
Subject: [issue1] Testing... [assignedto=mary; nosy=+john]
624+
625+
''')
626+
handler = self.instance.MailGW(self.instance, self.db)
627+
handler.trapExceptions = 0
628+
handler.main(message)
629+
l = self.db.issue.get('1', 'nosy')
630+
l.sort()
631+
self.assertEqual(l, ['3', '4', '5', '6'])
632+
633+
# should be no file created (ie. no message)
634+
assert not os.path.exists(os.environ['SENDMAILDEBUG'])
635+
623636
def testNosyRemove(self):
624637
self.doNewIssue()
625638

@@ -854,7 +867,6 @@ def testFollowupStupidQuoting(self):
854867
855868
This is a followup
856869
857-
858870
----------
859871
status: unread -> chatting
860872
_______________________________________________________________________
@@ -918,6 +930,10 @@ def testUserLookup(self):
918930
self.assertEqual(uidFromAddress(self.db, ('', '[email protected]'), 0), i)
919931
self.assertEqual(uidFromAddress(self.db, ('', '[email protected]'), 0), i)
920932

933+
def testUserCreate(self):
934+
i = uidFromAddress(self.db, ('', '[email protected]'), 1)
935+
self.assertNotEqual(uidFromAddress(self.db, ('', '[email protected]'), 1), i)
936+
921937
def suite():
922938
l = [unittest.makeSuite(MailgwTestCase),
923939
]

0 commit comments

Comments
 (0)