Mercurial > p > roundup > code
comparison test/test_mailgw.py @ 5493:725266c03eab
updated mailgw to no longer use mimetools based on jerrykan's patch
| author | Christof Meerwald <cmeerw@cmeerw.org> |
|---|---|
| date | Sun, 12 Aug 2018 16:15:10 +0100 |
| parents | b0048969990d |
| children | b7fa56ced601 |
comparison
equal
deleted
inserted
replaced
| 5492:6b0c542642be | 5493:725266c03eab |
|---|---|
| 26 from .pytest_patcher import mark_class | 26 from .pytest_patcher import mark_class |
| 27 skip_pgp = mark_class(pytest.mark.skip( | 27 skip_pgp = mark_class(pytest.mark.skip( |
| 28 reason="Skipping PGP tests: 'pyme' not installed")) | 28 reason="Skipping PGP tests: 'pyme' not installed")) |
| 29 | 29 |
| 30 | 30 |
| 31 from roundup.anypy.strings import StringIO, u2s | 31 from roundup.anypy.strings import StringIO, b2s, u2s |
| 32 | 32 |
| 33 if 'SENDMAILDEBUG' not in os.environ: | 33 if 'SENDMAILDEBUG' not in os.environ: |
| 34 os.environ['SENDMAILDEBUG'] = 'mail-test.log' | 34 os.environ['SENDMAILDEBUG'] = 'mail-test.log' |
| 35 SENDMAILDEBUG = os.environ['SENDMAILDEBUG'] | 35 SENDMAILDEBUG = os.environ['SENDMAILDEBUG'] |
| 36 | 36 |
| 892 if n in content : | 892 if n in content : |
| 893 self.assertEqual(f.content, content [n]) | 893 self.assertEqual(f.content, content [n]) |
| 894 self.assertEqual(msg.content, 'test attachment second text/plain') | 894 self.assertEqual(msg.content, 'test attachment second text/plain') |
| 895 | 895 |
| 896 def testMultipartCharsetUTF8NoAttach(self): | 896 def testMultipartCharsetUTF8NoAttach(self): |
| 897 c = 'umlaut \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f' | 897 c = b2s(b'umlaut \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f') |
| 898 self.doNewIssue() | 898 self.doNewIssue() |
| 899 self.db.config.NOSY_MAX_ATTACHMENT_SIZE = 0 | 899 self.db.config.NOSY_MAX_ATTACHMENT_SIZE = 0 |
| 900 self._handle_mail(self.multipart_msg_latin1) | 900 self._handle_mail(self.multipart_msg_latin1) |
| 901 messages = self.db.issue.get('1', 'messages') | 901 messages = self.db.issue.get('1', 'messages') |
| 902 messages.sort() | 902 messages.sort() |
| 942 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1> | 942 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1> |
| 943 _______________________________________________________________________ | 943 _______________________________________________________________________ |
| 944 ''') | 944 ''') |
| 945 | 945 |
| 946 def testMultipartCharsetLatin1NoAttach(self): | 946 def testMultipartCharsetLatin1NoAttach(self): |
| 947 c = 'umlaut \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f' | 947 c = b2s(b'umlaut \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f') |
| 948 self.doNewIssue() | 948 self.doNewIssue() |
| 949 self.db.config.NOSY_MAX_ATTACHMENT_SIZE = 0 | 949 self.db.config.NOSY_MAX_ATTACHMENT_SIZE = 0 |
| 950 self.db.config.MAIL_CHARSET = 'iso-8859-1' | 950 self.db.config.MAIL_CHARSET = 'iso-8859-1' |
| 951 self._handle_mail(self.multipart_msg_latin1) | 951 self._handle_mail(self.multipart_msg_latin1) |
| 952 messages = self.db.issue.get('1', 'messages') | 952 messages = self.db.issue.get('1', 'messages') |
| 993 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1> | 993 <http://tracker.example/cgi-bin/roundup.cgi/bugs/issue1> |
| 994 _______________________________________________________________________ | 994 _______________________________________________________________________ |
| 995 ''') | 995 ''') |
| 996 | 996 |
| 997 def testMultipartCharsetUTF8AttachFile(self): | 997 def testMultipartCharsetUTF8AttachFile(self): |
| 998 c = 'umlaut \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f' | 998 c = b2s(b'umlaut \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f') |
| 999 self.doNewIssue() | 999 self.doNewIssue() |
| 1000 self._handle_mail(self.multipart_msg_latin1) | 1000 self._handle_mail(self.multipart_msg_latin1) |
| 1001 messages = self.db.issue.get('1', 'messages') | 1001 messages = self.db.issue.get('1', 'messages') |
| 1002 messages.sort() | 1002 messages.sort() |
| 1003 msg = self.db.msg.getnode (messages[-1]) | 1003 msg = self.db.msg.getnode (messages[-1]) |
| 1055 | 1055 |
| 1056 --utf-8-- | 1056 --utf-8-- |
| 1057 ''') | 1057 ''') |
| 1058 | 1058 |
| 1059 def testMultipartCharsetLatin1AttachFile(self): | 1059 def testMultipartCharsetLatin1AttachFile(self): |
| 1060 c = 'umlaut \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f' | 1060 c = b2s(b'umlaut \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f') |
| 1061 self.doNewIssue() | 1061 self.doNewIssue() |
| 1062 self.db.config.MAIL_CHARSET = 'iso-8859-1' | 1062 self.db.config.MAIL_CHARSET = 'iso-8859-1' |
| 1063 self._handle_mail(self.multipart_msg_latin1) | 1063 self._handle_mail(self.multipart_msg_latin1) |
| 1064 messages = self.db.issue.get('1', 'messages') | 1064 messages = self.db.issue.get('1', 'messages') |
| 1065 messages.sort() | 1065 messages.sort() |
| 1285 self._handle_mail(self.multipart_msg_notext) | 1285 self._handle_mail(self.multipart_msg_notext) |
| 1286 messages = self.db.issue.get('1', 'messages') | 1286 messages = self.db.issue.get('1', 'messages') |
| 1287 messages.sort() | 1287 messages.sort() |
| 1288 msg = self.db.msg.getnode(messages[-1]) | 1288 msg = self.db.msg.getnode(messages[-1]) |
| 1289 # html converted to utf-8 text | 1289 # html converted to utf-8 text |
| 1290 self.assertEqual(msg.content, mycontent+" \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f") | 1290 self.assertEqual(msg.content, mycontent+b2s(b" \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f")) |
| 1291 self.assertEqual(msg.type, None) | 1291 self.assertEqual(msg.type, None) |
| 1292 self.assertEqual(len(msg.files), 2) | 1292 self.assertEqual(len(msg.files), 2) |
| 1293 name = "unnamed" # no name for any files | 1293 name = "unnamed" # no name for any files |
| 1294 types = { 0: "text/csv", 1: "text/html" } | 1294 types = { 0: "text/csv", 1: "text/html" } |
| 1295 # replace quoted printable string at end of html document | 1295 # replace quoted printable string at end of html document |
| 1296 # with it's utf-8 encoded equivalent so comparison | 1296 # with it's utf-8 encoded equivalent so comparison |
| 1297 # works. | 1297 # works. |
| 1298 content = { 0: "75,23,16,18\n", 1: self.html_doc.replace(" =E4=F6=FC=C4=D6=DC=DF"," \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f")} | 1298 content = { 0: "75,23,16,18\n", 1: self.html_doc.replace(" =E4=F6=FC=C4=D6=DC=DF",b2s(b" \xc3\xa4\xc3\xb6\xc3\xbc\xc3\x84\xc3\x96\xc3\x9c\xc3\x9f"))} |
| 1299 for n, id in enumerate (msg.files): | 1299 for n, id in enumerate (msg.files): |
| 1300 f = self.db.file.getnode (id) | 1300 f = self.db.file.getnode (id) |
| 1301 self.assertEqual(f.name, name) | 1301 self.assertEqual(f.name, name) |
| 1302 self.assertEqual(f.type, types[n]) | 1302 self.assertEqual(f.type, types[n]) |
| 1303 self.assertEqual(f.content, content[n]) | 1303 self.assertEqual(f.content, content[n]) |
| 2646 This is a test submission of a new issue. | 2646 This is a test submission of a new issue. |
| 2647 ''' | 2647 ''' |
| 2648 self._allowAnonymousSubmit() | 2648 self._allowAnonymousSubmit() |
| 2649 self._handle_mail(message) | 2649 self._handle_mail(message) |
| 2650 title = self.db.issue.get('1', 'title') | 2650 title = self.db.issue.get('1', 'title') |
| 2651 self.assertEquals(title, 'Test \xc3\x84\xc3\x96\xc3\x9c umlauts X1 X2') | 2651 self.assertEquals(title, b2s(b'Test \xc3\x84\xc3\x96\xc3\x9c umlauts X1 X2')) |
| 2652 m = set(self.db.user.list()) | 2652 m = set(self.db.user.list()) |
| 2653 new = list(m - l)[0] | 2653 new = list(m - l)[0] |
| 2654 name = self.db.user.get(new, 'realname') | 2654 name = self.db.user.get(new, 'realname') |
| 2655 self.assertEquals(name, 'Firstname \xc3\xa4\xc3\xb6\xc3\x9f Last') | 2655 self.assertEquals(name, b2s(b'Firstname \xc3\xa4\xc3\xb6\xc3\x9f Last')) |
| 2656 | 2656 |
| 2657 def testNewUserAuthorMixedEncodedNameSpacing(self): | 2657 def testNewUserAuthorMixedEncodedNameSpacing(self): |
| 2658 l = set(self.db.user.list()) | 2658 l = set(self.db.user.list()) |
| 2659 # From: name has Euro symbol in it | 2659 # From: name has Euro symbol in it |
| 2660 message = '''Content-Type: text/plain; | 2660 message = '''Content-Type: text/plain; |
| 2668 This is a test submission of a new issue. | 2668 This is a test submission of a new issue. |
| 2669 ''' | 2669 ''' |
| 2670 self._allowAnonymousSubmit() | 2670 self._allowAnonymousSubmit() |
| 2671 self._handle_mail(message) | 2671 self._handle_mail(message) |
| 2672 title = self.db.issue.get('1', 'title') | 2672 title = self.db.issue.get('1', 'title') |
| 2673 self.assertEquals(title, 'Test (\xc3\x84\xc3\x96\xc3\x9c) umlauts X1') | 2673 self.assertEquals(title, b2s(b'Test (\xc3\x84\xc3\x96\xc3\x9c) umlauts X1')) |
| 2674 m = set(self.db.user.list()) | 2674 m = set(self.db.user.list()) |
| 2675 new = list(m - l)[0] | 2675 new = list(m - l)[0] |
| 2676 name = self.db.user.get(new, 'realname') | 2676 name = self.db.user.get(new, 'realname') |
| 2677 self.assertEquals(name, | 2677 self.assertEquals(name, |
| 2678 '(\xc3\xa4\xc3\xb6\xc3\x9f\xc3\xa4\xc3\xb6\xc3\x9f)') | 2678 b2s(b'(\xc3\xa4\xc3\xb6\xc3\x9f\xc3\xa4\xc3\xb6\xc3\x9f)')) |
| 2679 | 2679 |
| 2680 def testUnknownUser(self): | 2680 def testUnknownUser(self): |
| 2681 l = set(self.db.user.list()) | 2681 l = set(self.db.user.list()) |
| 2682 message = '''Content-Type: text/plain; | 2682 message = '''Content-Type: text/plain; |
| 2683 charset="iso-8859-1" | 2683 charset="iso-8859-1" |
| 2837 ''') | 2837 ''') |
| 2838 | 2838 |
| 2839 | 2839 |
| 2840 def testMultipartEnc01(self): | 2840 def testMultipartEnc01(self): |
| 2841 self.doNewIssue() | 2841 self.doNewIssue() |
| 2842 self._handle_mail('''Content-Type: text/plain; | 2842 self._handle_mail('''From: mary <mary@test.test> |
| 2843 charset="iso-8859-1" | |
| 2844 From: mary <mary@test.test> | |
| 2845 To: issue_tracker@your.tracker.email.domain.example | 2843 To: issue_tracker@your.tracker.email.domain.example |
| 2846 Message-Id: <followup_dummy_id> | 2844 Message-Id: <followup_dummy_id> |
| 2847 In-Reply-To: <dummy_test_message_id> | 2845 In-Reply-To: <dummy_test_message_id> |
| 2848 Subject: [issue1] Testing... | 2846 Subject: [issue1] Testing... |
| 2849 Content-Type: multipart/mixed; | 2847 Content-Type: multipart/mixed; |
| 2891 _______________________________________________________________________ | 2889 _______________________________________________________________________ |
| 2892 ''') | 2890 ''') |
| 2893 | 2891 |
| 2894 def testContentDisposition(self): | 2892 def testContentDisposition(self): |
| 2895 self.doNewIssue() | 2893 self.doNewIssue() |
| 2896 self._handle_mail('''Content-Type: text/plain; | 2894 self._handle_mail('''From: mary <mary@test.test> |
| 2897 charset="iso-8859-1" | |
| 2898 From: mary <mary@test.test> | |
| 2899 To: issue_tracker@your.tracker.email.domain.example | 2895 To: issue_tracker@your.tracker.email.domain.example |
| 2900 Message-Id: <followup_dummy_id> | 2896 Message-Id: <followup_dummy_id> |
| 2901 In-Reply-To: <dummy_test_message_id> | 2897 In-Reply-To: <dummy_test_message_id> |
| 2902 Subject: [issue1] Testing... | 2898 Subject: [issue1] Testing... |
| 2903 Content-Type: multipart/mixed; boundary="bCsyhTFzCvuiizWE" | 2899 Content-Type: multipart/mixed; boundary="bCsyhTFzCvuiizWE" |
| 4185 self.assertEqual(self.db.file.get(fileid, 'type'), 'message/rfc822') | 4181 self.assertEqual(self.db.file.get(fileid, 'type'), 'message/rfc822') |
| 4186 | 4182 |
| 4187 def testForwardedMessageAttachment(self): | 4183 def testForwardedMessageAttachment(self): |
| 4188 message = '''Return-Path: <rgg@test.test> | 4184 message = '''Return-Path: <rgg@test.test> |
| 4189 Received: from localhost(127.0.0.1), claiming to be "[115.130.26.69]" | 4185 Received: from localhost(127.0.0.1), claiming to be "[115.130.26.69]" |
| 4190 via SMTP by localhost, id smtpdAAApLaWrq; Tue Apr 13 23:10:05 2010 | 4186 via SMTP by localhost, id smtpdAAApLaWrq; Tue Apr 13 23:10:05 2010 |
| 4191 Message-ID: <4BC4F9C7.50409@test.test> | 4187 Message-ID: <4BC4F9C7.50409@test.test> |
| 4192 Date: Wed, 14 Apr 2010 09:09:59 +1000 | 4188 Date: Wed, 14 Apr 2010 09:09:59 +1000 |
| 4193 From: Rupert Goldie <rgg@test.test> | 4189 From: Rupert Goldie <rgg@test.test> |
| 4194 User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) | 4190 User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) |
| 4195 MIME-Version: 1.0 | 4191 MIME-Version: 1.0 |
