Mercurial > p > roundup > code
comparison test/test_cgi.py @ 4112:6441ffe588f7
fix bug introduced into CSV export and view (issue 2550529)
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Mon, 16 Mar 2009 04:16:43 +0000 |
| parents | 34434785f308 |
| children | 966592263fb8 |
comparison
equal
deleted
inserted
replaced
| 4111:49a964df49ea | 4112:6441ffe588f7 |
|---|---|
| 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_cgi.py,v 1.36 2008-08-07 06:12:57 richard Exp $ | 11 # $Id: test_cgi.py,v 1.36 2008-08-07 06:12:57 richard Exp $ |
| 12 | 12 |
| 13 import unittest, os, shutil, errno, sys, difflib, cgi, re | 13 import unittest, os, shutil, errno, sys, difflib, cgi, re, StringIO |
| 14 | 14 |
| 15 from roundup.cgi import client, actions, exceptions | 15 from roundup.cgi import client, actions, exceptions |
| 16 from roundup.cgi.exceptions import FormError | 16 from roundup.cgi.exceptions import FormError |
| 17 from roundup.cgi.templating import HTMLItem | 17 from roundup.cgi.templating import HTMLItem |
| 18 from roundup.cgi.form_parser import FormParser | 18 from roundup.cgi.form_parser import FormParser |
| 19 from roundup import init, instance, password, hyperdb, date | 19 from roundup import init, instance, password, hyperdb, date |
| 20 | |
| 21 from mocknull import MockNull | |
| 20 | 22 |
| 21 import db_test_base | 23 import db_test_base |
| 22 | 24 |
| 23 NEEDS_INSTANCE = 1 | 25 NEEDS_INSTANCE = 1 |
| 24 | 26 |
| 612 | 614 |
| 613 # | 615 # |
| 614 # SECURITY | 616 # SECURITY |
| 615 # | 617 # |
| 616 # XXX test all default permissions | 618 # XXX test all default permissions |
| 617 def _make_client(self, form, classname='user', nodeid='2', userid='2'): | 619 def _make_client(self, form, classname='user', nodeid='1', userid='2'): |
| 618 cl = client.Client(self.instance, None, {'PATH_INFO':'/', | 620 cl = client.Client(self.instance, None, {'PATH_INFO':'/', |
| 619 'REQUEST_METHOD':'POST'}, makeForm(form)) | 621 'REQUEST_METHOD':'POST'}, makeForm(form)) |
| 620 cl.classname = 'user' | 622 cl.classname = 'user' |
| 621 cl.nodeid = '1' | 623 cl.nodeid = nodeid |
| 622 cl.db = self.db | 624 cl.db = self.db |
| 623 cl.userid = '2' | 625 cl.userid = userid |
| 624 cl.language = ('en',) | 626 cl.language = ('en',) |
| 625 return cl | 627 return cl |
| 626 | 628 |
| 627 def testClassPermission(self): | 629 def testClassPermission(self): |
| 628 cl = self._make_client(dict(username='bob')) | 630 cl = self._make_client(dict(username='bob')) |
| 644 actions.EditItemAction(cl).handle) | 646 actions.EditItemAction(cl).handle) |
| 645 cl = self._make_client({'password':'bob', '@confirm@password':'bob'}) | 647 cl = self._make_client({'password':'bob', '@confirm@password':'bob'}) |
| 646 self.failUnlessRaises(exceptions.Unauthorised, | 648 self.failUnlessRaises(exceptions.Unauthorised, |
| 647 actions.EditItemAction(cl).handle) | 649 actions.EditItemAction(cl).handle) |
| 648 | 650 |
| 651 def testCSVExport(self): | |
| 652 cl = self._make_client({'@columns': 'id,name'}, nodeid=None, | |
| 653 userid='1') | |
| 654 cl.classname = 'status' | |
| 655 output = StringIO.StringIO() | |
| 656 cl.request = MockNull() | |
| 657 cl.request.wfile = output | |
| 658 actions.ExportCSVAction(cl).handle() | |
| 659 self.assertEquals('id,name\r\n1,unread\r\n2,deferred\r\n3,chatting\r\n' | |
| 660 '4,need-eg\r\n5,in-progress\r\n6,testing\r\n7,done-cbb\r\n' | |
| 661 '8,resolved\r\n', | |
| 662 output.getvalue()) | |
| 663 | |
| 664 def testCSVExportFailPermission(self): | |
| 665 cl = self._make_client({'@columns': 'id,email,password'}, nodeid=None, | |
| 666 userid='2') | |
| 667 cl.classname = 'user' | |
| 668 output = StringIO.StringIO() | |
| 669 cl.request = MockNull() | |
| 670 cl.request.wfile = output | |
| 671 self.assertRaises(exceptions.Unauthorised, | |
| 672 actions.ExportCSVAction(cl).handle) | |
| 673 | |
| 674 | |
| 675 def test_suite(): | |
| 676 suite = unittest.TestSuite() | |
| 677 | |
| 649 def test_suite(): | 678 def test_suite(): |
| 650 suite = unittest.TestSuite() | 679 suite = unittest.TestSuite() |
| 651 suite.addTest(unittest.makeSuite(FormTestCase)) | 680 suite.addTest(unittest.makeSuite(FormTestCase)) |
| 652 suite.addTest(unittest.makeSuite(MessageTestCase)) | 681 suite.addTest(unittest.makeSuite(MessageTestCase)) |
| 653 return suite | 682 return suite |
