Mercurial > p > roundup > code
comparison test/test_mailgw.py @ 905:502a5ae11cc5
Very close now. The cgi and mailgw now use the new security API.
The two templates have been migrated to that setup. Lots of unit
tests. Still some issue in the web form for editing Roles assigned to
users.
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Fri, 26 Jul 2002 08:27:00 +0000 |
| parents | 6dd691e37aa8 |
| children | a8d80ffe37cc |
comparison
equal
deleted
inserted
replaced
| 904:02763530b9e8 | 905:502a5ae11cc5 |
|---|---|
| 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.23 2002-07-14 02:02:43 richard Exp $ | 11 # $Id: test_mailgw.py,v 1.24 2002-07-26 08:27:00 richard Exp $ |
| 12 | 12 |
| 13 import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys, difflib | 13 import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys, difflib |
| 14 | 14 |
| 15 # Note: Should parse emails according to RFC2822 instead of performing a | 15 # Note: Should parse emails according to RFC2822 instead of performing a |
| 16 # literal string comparision. Parsing the messages allows the tests to work for | 16 # literal string comparision. Parsing the messages allows the tests to work for |
| 18 #try : | 18 #try : |
| 19 # import email | 19 # import email |
| 20 #except ImportError : | 20 #except ImportError : |
| 21 # import rfc822 as email | 21 # import rfc822 as email |
| 22 | 22 |
| 23 from roundup.mailgw import MailGW | 23 from roundup.mailgw import MailGW, Unauthorized |
| 24 from roundup import init, instance | 24 from roundup import init, instance |
| 25 | 25 |
| 26 # TODO: make this output only enough equal lines for context, not all of | 26 # TODO: make this output only enough equal lines for context, not all of |
| 27 # them | 27 # them |
| 28 class DiffHelper: | 28 class DiffHelper: |
| 111 if os.path.exists(os.environ['SENDMAILDEBUG']): | 111 if os.path.exists(os.environ['SENDMAILDEBUG']): |
| 112 error = open(os.environ['SENDMAILDEBUG']).read() | 112 error = open(os.environ['SENDMAILDEBUG']).read() |
| 113 self.assertEqual('no error', error) | 113 self.assertEqual('no error', error) |
| 114 l = self.db.issue.get(nodeid, 'nosy') | 114 l = self.db.issue.get(nodeid, 'nosy') |
| 115 l.sort() | 115 l.sort() |
| 116 self.assertEqual(l, ['2', '3']) | 116 self.assertEqual(l, ['3', '4']) |
| 117 | 117 |
| 118 def testNewIssue(self): | 118 def testNewIssue(self): |
| 119 self.doNewIssue() | 119 self.doNewIssue() |
| 120 | 120 |
| 121 def testNewIssueNosy(self): | 121 def testNewIssueNosy(self): |
| 136 if os.path.exists(os.environ['SENDMAILDEBUG']): | 136 if os.path.exists(os.environ['SENDMAILDEBUG']): |
| 137 error = open(os.environ['SENDMAILDEBUG']).read() | 137 error = open(os.environ['SENDMAILDEBUG']).read() |
| 138 self.assertEqual('no error', error) | 138 self.assertEqual('no error', error) |
| 139 l = self.db.issue.get(nodeid, 'nosy') | 139 l = self.db.issue.get(nodeid, 'nosy') |
| 140 l.sort() | 140 l.sort() |
| 141 self.assertEqual(l, ['2', '3']) | 141 self.assertEqual(l, ['3', '4']) |
| 142 | 142 |
| 143 def testAlternateAddress(self): | 143 def testAlternateAddress(self): |
| 144 message = cStringIO.StringIO('''Content-Type: text/plain; | 144 message = cStringIO.StringIO('''Content-Type: text/plain; |
| 145 charset="iso-8859-1" | 145 charset="iso-8859-1" |
| 146 From: John Doe <john.doe@test> | 146 From: John Doe <john.doe@test> |
| 293 handler = self.instance.MailGW(self.instance, self.db) | 293 handler = self.instance.MailGW(self.instance, self.db) |
| 294 handler.trapExceptions = 0 | 294 handler.trapExceptions = 0 |
| 295 handler.main(message) | 295 handler.main(message) |
| 296 l = self.db.issue.get('1', 'nosy') | 296 l = self.db.issue.get('1', 'nosy') |
| 297 l.sort() | 297 l.sort() |
| 298 self.assertEqual(l, ['2', '3', '4', '5']) | 298 self.assertEqual(l, ['3', '4', '5', '6']) |
| 299 | 299 |
| 300 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(), | 300 self.compareStrings(open(os.environ['SENDMAILDEBUG']).read(), |
| 301 '''FROM: roundup-admin@your.tracker.email.domain.example | 301 '''FROM: roundup-admin@your.tracker.email.domain.example |
| 302 TO: chef@bork.bork.bork, john@test, mary@test | 302 TO: chef@bork.bork.bork, john@test, mary@test |
| 303 Content-Type: text/plain | 303 Content-Type: text/plain |
| 624 handler = self.instance.MailGW(self.instance, self.db) | 624 handler = self.instance.MailGW(self.instance, self.db) |
| 625 handler.trapExceptions = 0 | 625 handler.trapExceptions = 0 |
| 626 handler.main(message) | 626 handler.main(message) |
| 627 l = self.db.issue.get('1', 'nosy') | 627 l = self.db.issue.get('1', 'nosy') |
| 628 l.sort() | 628 l.sort() |
| 629 self.assertEqual(l, ['2']) | 629 self.assertEqual(l, ['3']) |
| 630 | 630 |
| 631 # NO NOSY MESSAGE SHOULD BE SENT! | 631 # NO NOSY MESSAGE SHOULD BE SENT! |
| 632 self.assert_(not os.path.exists(os.environ['SENDMAILDEBUG'])) | 632 self.assert_(not os.path.exists(os.environ['SENDMAILDEBUG'])) |
| 633 | |
| 634 def testNewUserAuthor(self): | |
| 635 # first without the permission | |
| 636 Anonid = self.db.role.lookup('Anonymous') | |
| 637 self.db.role.set(Anonid, permissions=[]) | |
| 638 anonid = self.db.user.lookup('anonymous') | |
| 639 self.db.user.set(anonid, roles='Anonymous') | |
| 640 | |
| 641 self.db.security.hasPermission('Email Registration', anonid) | |
| 642 l = self.db.user.list() | |
| 643 l.sort() | |
| 644 s = '''Content-Type: text/plain; | |
| 645 charset="iso-8859-1" | |
| 646 From: fubar <fubar@bork.bork.bork> | |
| 647 To: issue_tracker@your.tracker.email.domain.example | |
| 648 Message-Id: <dummy_test_message_id> | |
| 649 Subject: [issue] Testing... | |
| 650 | |
| 651 This is a test submission of a new issue. | |
| 652 ''' | |
| 653 message = cStringIO.StringIO(s) | |
| 654 handler = self.instance.MailGW(self.instance, self.db) | |
| 655 handler.trapExceptions = 0 | |
| 656 self.assertRaises(Unauthorized, handler.main, message) | |
| 657 m = self.db.user.list() | |
| 658 m.sort() | |
| 659 self.assertEqual(l, m) | |
| 660 | |
| 661 # now with the permission | |
| 662 p = self.db.security.getPermission('Email Registration') | |
| 663 self.db.role.set(Anonid, permissions=[p]) | |
| 664 handler = self.instance.MailGW(self.instance, self.db) | |
| 665 handler.trapExceptions = 0 | |
| 666 message = cStringIO.StringIO(s) | |
| 667 handler.main(message) | |
| 668 m = self.db.user.list() | |
| 669 m.sort() | |
| 670 self.assertNotEqual(l, m) | |
| 633 | 671 |
| 634 def testEnc01(self): | 672 def testEnc01(self): |
| 635 self.doNewIssue() | 673 self.doNewIssue() |
| 636 message = cStringIO.StringIO('''Content-Type: text/plain; | 674 message = cStringIO.StringIO('''Content-Type: text/plain; |
| 637 charset="iso-8859-1" | 675 charset="iso-8859-1" |
| 741 return unittest.TestSuite(l) | 779 return unittest.TestSuite(l) |
| 742 | 780 |
| 743 | 781 |
| 744 # | 782 # |
| 745 # $Log: not supported by cvs2svn $ | 783 # $Log: not supported by cvs2svn $ |
| 784 # Revision 1.23 2002/07/14 02:02:43 richard | |
| 785 # Fixed the unit tests for the new multilist controls in the mailgw | |
| 786 # | |
| 746 # Revision 1.22 2002/07/09 01:21:24 richard | 787 # Revision 1.22 2002/07/09 01:21:24 richard |
| 747 # Added ability for unit tests to turn off exception handling in mailgw so | 788 # Added ability for unit tests to turn off exception handling in mailgw so |
| 748 # that exceptions are reported earlier (and hence make sense). | 789 # that exceptions are reported earlier (and hence make sense). |
| 749 # | 790 # |
| 750 # Revision 1.21 2002/06/18 03:59:59 dman13 | 791 # Revision 1.21 2002/06/18 03:59:59 dman13 |
