Mercurial > p > roundup > code
comparison test/db_test_base.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 | 6b0c542642be |
| children | b7fa56ced601 |
comparison
equal
deleted
inserted
replaced
| 5492:6b0c542642be | 5493:725266c03eab |
|---|---|
| 2577 res = dict(mail_to = None, mail_msg = None) | 2577 res = dict(mail_to = None, mail_msg = None) |
| 2578 def dummy_snd(s, to, msg, res=res) : | 2578 def dummy_snd(s, to, msg, res=res) : |
| 2579 res["mail_to"], res["mail_msg"] = to, msg | 2579 res["mail_to"], res["mail_msg"] = to, msg |
| 2580 backup, Mailer.smtp_send = Mailer.smtp_send, dummy_snd | 2580 backup, Mailer.smtp_send = Mailer.smtp_send, dummy_snd |
| 2581 try : | 2581 try : |
| 2582 f1 = db.file.create(name="test1.txt", content="x" * 20) | 2582 f1 = db.file.create(name="test1.txt", content="x" * 20, type="application/octet-stream") |
| 2583 f2 = db.file.create(name="test2.txt", content="y" * 5000) | 2583 f2 = db.file.create(name="test2.txt", content="y" * 5000, type="application/octet-stream") |
| 2584 m = db.msg.create(content="one two", author="admin", | 2584 m = db.msg.create(content="one two", author="admin", |
| 2585 files = [f1, f2]) | 2585 files = [f1, f2]) |
| 2586 i = db.issue.create(title='spam', files = [f1, f2], | 2586 i = db.issue.create(title='spam', files = [f1, f2], |
| 2587 messages = [m], nosy = [db.user.lookup("fred")]) | 2587 messages = [m], nosy = [db.user.lookup("fred")]) |
| 2588 | 2588 |
| 2595 self.assert_("one two" in mail_msg) | 2595 self.assert_("one two" in mail_msg) |
| 2596 self.assert_("File 'test1.txt' not attached" not in mail_msg) | 2596 self.assert_("File 'test1.txt' not attached" not in mail_msg) |
| 2597 self.assert_(b2s(base64.encodestring(s2b("xxx"))).rstrip() in mail_msg) | 2597 self.assert_(b2s(base64.encodestring(s2b("xxx"))).rstrip() in mail_msg) |
| 2598 self.assert_("File 'test2.txt' not attached" in mail_msg) | 2598 self.assert_("File 'test2.txt' not attached" in mail_msg) |
| 2599 self.assert_(b2s(base64.encodestring(s2b("yyy"))).rstrip() not in mail_msg) | 2599 self.assert_(b2s(base64.encodestring(s2b("yyy"))).rstrip() not in mail_msg) |
| 2600 finally : | |
| 2601 roundupdb._ = old_translate_ | |
| 2602 Mailer.smtp_send = backup | |
| 2603 | |
| 2604 def testNosyMailTextAndBinary(self) : | |
| 2605 """Creates one issue with two attachments, one as text and one as binary. | |
| 2606 """ | |
| 2607 old_translate_ = roundupdb._ | |
| 2608 roundupdb._ = i18n.get_translation(language='C').gettext | |
| 2609 db = self.db | |
| 2610 res = dict(mail_to = None, mail_msg = None) | |
| 2611 def dummy_snd(s, to, msg, res=res) : | |
| 2612 res["mail_to"], res["mail_msg"] = to, msg | |
| 2613 backup, Mailer.smtp_send = Mailer.smtp_send, dummy_snd | |
| 2614 try : | |
| 2615 f1 = db.file.create(name="test1.txt", content="Hello world", type="text/plain") | |
| 2616 f2 = db.file.create(name="test2.bin", content=b"\x01\x02\x03\xfe\xff", type="application/octet-stream") | |
| 2617 m = db.msg.create(content="one two", author="admin", | |
| 2618 files = [f1, f2]) | |
| 2619 i = db.issue.create(title='spam', files = [f1, f2], | |
| 2620 messages = [m], nosy = [db.user.lookup("fred")]) | |
| 2621 | |
| 2622 db.issue.nosymessage(i, m, {}) | |
| 2623 mail_msg = str(res["mail_msg"]) | |
| 2624 self.assertEqual(res["mail_to"], ["fred@example.com"]) | |
| 2625 self.assert_("From: admin" in mail_msg) | |
| 2626 self.assert_("Subject: [issue1] spam" in mail_msg) | |
| 2627 self.assert_("New submission from admin" in mail_msg) | |
| 2628 self.assert_("one two" in mail_msg) | |
| 2629 self.assert_("Hello world" in mail_msg) | |
| 2630 self.assert_(b2s(base64.encodestring(b"\x01\x02\x03\xfe\xff")).rstrip() in mail_msg) | |
| 2600 finally : | 2631 finally : |
| 2601 roundupdb._ = old_translate_ | 2632 roundupdb._ = old_translate_ |
| 2602 Mailer.smtp_send = backup | 2633 Mailer.smtp_send = backup |
| 2603 | 2634 |
| 2604 @pytest.mark.skipif(gpgmelib.pyme is None, reason='Skipping PGPNosy test') | 2635 @pytest.mark.skipif(gpgmelib.pyme is None, reason='Skipping PGPNosy test') |
| 2621 res.append (dict (mail_to = to, mail_msg = msg)) | 2652 res.append (dict (mail_to = to, mail_msg = msg)) |
| 2622 backup, Mailer.smtp_send = Mailer.smtp_send, dummy_snd | 2653 backup, Mailer.smtp_send = Mailer.smtp_send, dummy_snd |
| 2623 try : | 2654 try : |
| 2624 john = db.user.create(username="john", roles='User,pgp', | 2655 john = db.user.create(username="john", roles='User,pgp', |
| 2625 address='john@test.test', realname='John Doe') | 2656 address='john@test.test', realname='John Doe') |
| 2626 f1 = db.file.create(name="test1.txt", content="x" * 20) | 2657 f1 = db.file.create(name="test1.txt", content="x" * 20, type="application/octet-stream") |
| 2627 f2 = db.file.create(name="test2.txt", content="y" * 5000) | 2658 f2 = db.file.create(name="test2.txt", content="y" * 5000, type="application/octet-stream") |
| 2628 m = db.msg.create(content="one two", author="admin", | 2659 m = db.msg.create(content="one two", author="admin", |
| 2629 files = [f1, f2]) | 2660 files = [f1, f2]) |
| 2630 i = db.issue.create(title='spam', files = [f1, f2], | 2661 i = db.issue.create(title='spam', files = [f1, f2], |
| 2631 messages = [m], nosy = [db.user.lookup("fred"), john]) | 2662 messages = [m], nosy = [db.user.lookup("fred"), john]) |
| 2632 | 2663 |
