Mercurial > p > roundup > code
comparison test/test_mailgw.py @ 2705:d81a7b03435f
init.initialize() was removed in r1.30 (27-jul-2004)
initialize test tracker as it is done in admin.py
trim trailing spaces; fix vim modeline
| author | Alexander Smishlajev <a1s@users.sourceforge.net> |
|---|---|
| date | Wed, 29 Sep 2004 08:05:33 +0000 |
| parents | 77461135596d |
| children | 6b5c77c03231 |
comparison
equal
deleted
inserted
replaced
| 2704:d760b549bdf0 | 2705:d81a7b03435f |
|---|---|
| 6 # | 6 # |
| 7 # This module is distributed in the hope that it will be useful, | 7 # This module is distributed in the hope that it will be useful, |
| 8 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 8 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 10 # | 10 # |
| 11 # $Id: test_mailgw.py,v 1.69 2004-04-20 21:55:45 richard Exp $ | 11 # $Id: test_mailgw.py,v 1.70 2004-09-29 08:05:33 a1s Exp $ |
| 12 | 12 |
| 13 # TODO: test bcc | 13 # TODO: test bcc |
| 14 | 14 |
| 15 import unittest, tempfile, os, shutil, errno, imp, sys, difflib, rfc822 | 15 import unittest, tempfile, os, shutil, errno, imp, sys, difflib, rfc822 |
| 16 | 16 |
| 20 os.environ['SENDMAILDEBUG'] = 'mail-test.log' | 20 os.environ['SENDMAILDEBUG'] = 'mail-test.log' |
| 21 SENDMAILDEBUG = os.environ['SENDMAILDEBUG'] | 21 SENDMAILDEBUG = os.environ['SENDMAILDEBUG'] |
| 22 | 22 |
| 23 from roundup.mailgw import MailGW, Unauthorized, uidFromAddress, \ | 23 from roundup.mailgw import MailGW, Unauthorized, uidFromAddress, \ |
| 24 parseContent, IgnoreLoop, IgnoreBulk | 24 parseContent, IgnoreLoop, IgnoreBulk |
| 25 from roundup import init, instance, rfc2822, __version__ | 25 from roundup import init, instance, password, rfc2822, __version__ |
| 26 | 26 |
| 27 | 27 |
| 28 class Message(rfc822.Message): | 28 class Message(rfc822.Message): |
| 29 """String-based Message class with equivalence test.""" | 29 """String-based Message class with equivalence test.""" |
| 30 def __init__(self, s): | 30 def __init__(self, s): |
| 31 rfc822.Message.__init__(self, StringIO(s.strip())) | 31 rfc822.Message.__init__(self, StringIO(s.strip())) |
| 32 | 32 |
| 33 def __eq__(self, other): | 33 def __eq__(self, other): |
| 34 return (self.dict == other.dict and | 34 return (self.dict == other.dict and |
| 35 self.fp.read() == other.fp.read()) | 35 self.fp.read() == other.fp.read()) |
| 36 | 36 |
| 37 class DiffHelper: | 37 class DiffHelper: |
| 38 def compareMessages(self, new, old): | 38 def compareMessages(self, new, old): |
| 39 """Compare messages for semantic equivalence.""" | 39 """Compare messages for semantic equivalence.""" |
| 40 new, old = Message(new), Message(old) | 40 new, old = Message(new), Message(old) |
| 58 res.extend(body_diff) | 58 res.extend(body_diff) |
| 59 | 59 |
| 60 if res: | 60 if res: |
| 61 res.insert(0, 'Generated message not correct (diff follows):') | 61 res.insert(0, 'Generated message not correct (diff follows):') |
| 62 raise AssertionError, '\n'.join(res) | 62 raise AssertionError, '\n'.join(res) |
| 63 | 63 |
| 64 def compareStrings(self, s2, s1): | 64 def compareStrings(self, s2, s1): |
| 65 '''Note the reversal of s2 and s1 - difflib.SequenceMatcher wants | 65 '''Note the reversal of s2 and s1 - difflib.SequenceMatcher wants |
| 66 the first to be the "original" but in the calls in this file, | 66 the first to be the "original" but in the calls in this file, |
| 67 the second arg is the original. Ho hum. | 67 the second arg is the original. Ho hum. |
| 68 ''' | 68 ''' |
| 100 except OSError, error: | 100 except OSError, error: |
| 101 if error.errno not in (errno.ENOENT, errno.ESRCH): raise | 101 if error.errno not in (errno.ENOENT, errno.ESRCH): raise |
| 102 # create the instance | 102 # create the instance |
| 103 init.install(self.dirname, 'templates/classic') | 103 init.install(self.dirname, 'templates/classic') |
| 104 init.write_select_db(self.dirname, 'anydbm') | 104 init.write_select_db(self.dirname, 'anydbm') |
| 105 init.initialise(self.dirname, 'sekrit') | 105 self.instance = tracker = instance.open(self.dirname) |
| 106 | 106 if tracker.exists(): |
| 107 # check we can load the package | 107 tracker.nuke() |
| 108 self.instance = instance.open(self.dirname) | 108 tracker.init(password.Password('sekrit')) |
| 109 | 109 |
| 110 # and open the database | 110 # and open the database |
| 111 self.db = self.instance.open('admin') | 111 self.db = self.instance.open('admin') |
| 112 self.chef_id = self.db.user.create(username='Chef', | 112 self.chef_id = self.db.user.create(username='Chef', |
| 113 address='chef@bork.bork.bork', realname='Bork, Chef', roles='User') | 113 address='chef@bork.bork.bork', realname='Bork, Chef', roles='User') |
| 133 handler.trapExceptions = 0 | 133 handler.trapExceptions = 0 |
| 134 ret = handler.main(StringIO(message)) | 134 ret = handler.main(StringIO(message)) |
| 135 # handler can close the db on us and open a new one | 135 # handler can close the db on us and open a new one |
| 136 self.db = handler.db | 136 self.db = handler.db |
| 137 return ret | 137 return ret |
| 138 | 138 |
| 139 def _get_mail(self): | 139 def _get_mail(self): |
| 140 f = open(SENDMAILDEBUG) | 140 f = open(SENDMAILDEBUG) |
| 141 try: | 141 try: |
| 142 return f.read() | 142 return f.read() |
| 143 finally: | 143 finally: |
| 202 Message-Id: <dummy_test_message_id> | 202 Message-Id: <dummy_test_message_id> |
| 203 Subject: [issue] Testing... | 203 Subject: [issue] Testing... |
| 204 | 204 |
| 205 This is a test submission of a new issue. | 205 This is a test submission of a new issue. |
| 206 ''') | 206 ''') |
| 207 userlist = self.db.user.list() | 207 userlist = self.db.user.list() |
| 208 assert not os.path.exists(SENDMAILDEBUG) | 208 assert not os.path.exists(SENDMAILDEBUG) |
| 209 self.assertEqual(userlist, self.db.user.list(), | 209 self.assertEqual(userlist, self.db.user.list(), |
| 210 "user created when it shouldn't have been") | 210 "user created when it shouldn't have been") |
| 211 | 211 |
| 212 def testNewIssueNoClass(self): | 212 def testNewIssueNoClass(self): |
| 269 # BUG | 269 # BUG |
| 270 # def testMultipart(self): | 270 # def testMultipart(self): |
| 271 # '''With more than one part''' | 271 # '''With more than one part''' |
| 272 # see MultipartEnc tests: but if there is more than one part | 272 # see MultipartEnc tests: but if there is more than one part |
| 273 # we return a multipart/mixed and the boundary contains | 273 # we return a multipart/mixed and the boundary contains |
| 274 # the ip address of the test machine. | 274 # the ip address of the test machine. |
| 275 | 275 |
| 276 # BUG should test some binary attamchent too. | 276 # BUG should test some binary attamchent too. |
| 277 | 277 |
| 278 def testSimpleFollowup(self): | 278 def testSimpleFollowup(self): |
| 279 self.doNewIssue() | 279 self.doNewIssue() |
| 806 From: mary <mary@test> | 806 From: mary <mary@test> |
| 807 To: issue_tracker@your.tracker.email.domain.example | 807 To: issue_tracker@your.tracker.email.domain.example |
| 808 Message-Id: <followup_dummy_id> | 808 Message-Id: <followup_dummy_id> |
| 809 In-Reply-To: <dummy_test_message_id> | 809 In-Reply-To: <dummy_test_message_id> |
| 810 Subject: [issue1] Testing... | 810 Subject: [issue1] Testing... |
| 811 Content-Type: multipart/mixed; boundary="bCsyhTFzCvuiizWE" | 811 Content-Type: multipart/mixed; boundary="bCsyhTFzCvuiizWE" |
| 812 Content-Disposition: inline | 812 Content-Disposition: inline |
| 813 | 813 |
| 814 | 814 |
| 815 --bCsyhTFzCvuiizWE | 815 --bCsyhTFzCvuiizWE |
| 816 Content-Type: text/plain; charset=us-ascii | 816 Content-Type: text/plain; charset=us-ascii |
| 817 Content-Disposition: inline | 817 Content-Disposition: inline |
| 818 | 818 |
| 819 test attachment binary | 819 test attachment binary |
| 820 | 820 |
| 821 --bCsyhTFzCvuiizWE | 821 --bCsyhTFzCvuiizWE |
| 822 Content-Type: application/octet-stream | 822 Content-Type: application/octet-stream |
| 823 Content-Disposition: attachment; filename="main.dvi" | 823 Content-Disposition: attachment; filename="main.dvi" |
| 824 | 824 |
| 825 xxxxxx | 825 xxxxxx |
| 826 | 826 |
| 827 --bCsyhTFzCvuiizWE-- | 827 --bCsyhTFzCvuiizWE-- |
| 828 ''') | 828 ''') |
| 829 messages = self.db.issue.get('1', 'messages') | 829 messages = self.db.issue.get('1', 'messages') |
| 830 messages.sort() | 830 messages.sort() |
| 965 To: issue_tracker@your.tracker.email.domain.example | 965 To: issue_tracker@your.tracker.email.domain.example |
| 966 Message-Id: <followup_dummy_id> | 966 Message-Id: <followup_dummy_id> |
| 967 In-Reply-To: <dummy_test_message_id> | 967 In-Reply-To: <dummy_test_message_id> |
| 968 Subject: [keyword1] Testing... [name=Bar] | 968 Subject: [keyword1] Testing... [name=Bar] |
| 969 | 969 |
| 970 ''') | 970 ''') |
| 971 self.assertEqual(self.db.keyword.get('1', 'name'), 'Bar') | 971 self.assertEqual(self.db.keyword.get('1', 'name'), 'Bar') |
| 972 | 972 |
| 973 def testResentFrom(self): | 973 def testResentFrom(self): |
| 974 nodeid = self._handle_mail('''Content-Type: text/plain; | 974 nodeid = self._handle_mail('''Content-Type: text/plain; |
| 975 charset="iso-8859-1" | 975 charset="iso-8859-1" |
| 1024 | 1024 |
| 1025 if __name__ == '__main__': | 1025 if __name__ == '__main__': |
| 1026 runner = unittest.TextTestRunner() | 1026 runner = unittest.TextTestRunner() |
| 1027 unittest.main(testRunner=runner) | 1027 unittest.main(testRunner=runner) |
| 1028 | 1028 |
| 1029 # vim: set filetype=python ts=4 sw=4 et si | 1029 # vim: set filetype=python sts=4 sw=4 et si : |
