Mercurial > p > roundup > code
comparison test/test_cgi.py @ 5418:55f09ca366c4
Python 3 preparation: StringIO.
This generally arranges for StringIO and cStringIO references to use
io.StringIO for Python 3 but io.BytesIO for Python 2, consistent with
the string representations generally used in Roundup. A special
FasterStringIO in the TAL code, which referenced internals of the old
Python 2 StringIO module, is cut down so it doesn't actually do
anything beyond the StringIO class it inherits from (it would also be
reasonable to remove FasterStringIO completely). One place in
roundup_server.py clearly needing binary I/O is made to use io.BytesIO
unconditionally.
| author | Joseph Myers <jsm@polyomino.org.uk> |
|---|---|
| date | Wed, 25 Jul 2018 09:08:29 +0000 |
| parents | d26921b851c3 |
| children | 2b4f606d8e72 |
comparison
equal
deleted
inserted
replaced
| 5417:c749d6795bc2 | 5418:55f09ca366c4 |
|---|---|
| 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 from __future__ import print_function | 11 from __future__ import print_function |
| 12 import unittest, os, shutil, errno, sys, difflib, cgi, re, StringIO | 12 import unittest, os, shutil, errno, sys, difflib, cgi, re |
| 13 | 13 |
| 14 from roundup.cgi import client, actions, exceptions | 14 from roundup.cgi import client, actions, exceptions |
| 15 from roundup.cgi.exceptions import FormError, NotFound | 15 from roundup.cgi.exceptions import FormError, NotFound |
| 16 from roundup.exceptions import UsageError | 16 from roundup.exceptions import UsageError |
| 17 from roundup.cgi.templating import HTMLItem, HTMLRequest, NoTemplate | 17 from roundup.cgi.templating import HTMLItem, HTMLRequest, NoTemplate |
| 18 from roundup.cgi.templating import HTMLProperty, _HTMLItem, anti_csrf_nonce | 18 from roundup.cgi.templating import HTMLProperty, _HTMLItem, anti_csrf_nonce |
| 19 from roundup.cgi.form_parser import FormParser | 19 from roundup.cgi.form_parser import FormParser |
| 20 from roundup import init, instance, password, hyperdb, date | 20 from roundup import init, instance, password, hyperdb, date |
| 21 from roundup.anypy.strings import StringIO | |
| 21 | 22 |
| 22 # For testing very simple rendering | 23 # For testing very simple rendering |
| 23 from roundup.cgi.engine_zopetal import RoundupPageTemplate | 24 from roundup.cgi.engine_zopetal import RoundupPageTemplate |
| 24 | 25 |
| 25 from .mocknull import MockNull | 26 from .mocknull import MockNull |
| 1456 | 1457 |
| 1457 def testCSVExport(self): | 1458 def testCSVExport(self): |
| 1458 cl = self._make_client({'@columns': 'id,name'}, nodeid=None, | 1459 cl = self._make_client({'@columns': 'id,name'}, nodeid=None, |
| 1459 userid='1') | 1460 userid='1') |
| 1460 cl.classname = 'status' | 1461 cl.classname = 'status' |
| 1461 output = StringIO.StringIO() | 1462 output = StringIO() |
| 1462 cl.request = MockNull() | 1463 cl.request = MockNull() |
| 1463 cl.request.wfile = output | 1464 cl.request.wfile = output |
| 1464 actions.ExportCSVAction(cl).handle() | 1465 actions.ExportCSVAction(cl).handle() |
| 1465 self.assertEquals('id,name\r\n1,unread\r\n2,deferred\r\n3,chatting\r\n' | 1466 self.assertEquals('id,name\r\n1,unread\r\n2,deferred\r\n3,chatting\r\n' |
| 1466 '4,need-eg\r\n5,in-progress\r\n6,testing\r\n7,done-cbb\r\n' | 1467 '4,need-eg\r\n5,in-progress\r\n6,testing\r\n7,done-cbb\r\n' |
| 1469 | 1470 |
| 1470 def testCSVExportBadColumnName(self): | 1471 def testCSVExportBadColumnName(self): |
| 1471 cl = self._make_client({'@columns': 'falseid,name'}, nodeid=None, | 1472 cl = self._make_client({'@columns': 'falseid,name'}, nodeid=None, |
| 1472 userid='1') | 1473 userid='1') |
| 1473 cl.classname = 'status' | 1474 cl.classname = 'status' |
| 1474 output = StringIO.StringIO() | 1475 output = StringIO() |
| 1475 cl.request = MockNull() | 1476 cl.request = MockNull() |
| 1476 cl.request.wfile = output | 1477 cl.request.wfile = output |
| 1477 self.assertRaises(exceptions.NotFound, | 1478 self.assertRaises(exceptions.NotFound, |
| 1478 actions.ExportCSVAction(cl).handle) | 1479 actions.ExportCSVAction(cl).handle) |
| 1479 | 1480 |
| 1480 def testCSVExportFailPermissionBadColumn(self): | 1481 def testCSVExportFailPermissionBadColumn(self): |
| 1481 cl = self._make_client({'@columns': 'id,email,password'}, nodeid=None, | 1482 cl = self._make_client({'@columns': 'id,email,password'}, nodeid=None, |
| 1482 userid='2') | 1483 userid='2') |
| 1483 cl.classname = 'user' | 1484 cl.classname = 'user' |
| 1484 output = StringIO.StringIO() | 1485 output = StringIO() |
| 1485 cl.request = MockNull() | 1486 cl.request = MockNull() |
| 1486 cl.request.wfile = output | 1487 cl.request.wfile = output |
| 1487 # used to be self.assertRaises(exceptions.Unauthorised, | 1488 # used to be self.assertRaises(exceptions.Unauthorised, |
| 1488 # but not acting like the column name is not found | 1489 # but not acting like the column name is not found |
| 1489 # see issue2550755 - should this return Unauthorised? | 1490 # see issue2550755 - should this return Unauthorised? |
| 1494 | 1495 |
| 1495 def testCSVExportFailPermissionValidColumn(self): | 1496 def testCSVExportFailPermissionValidColumn(self): |
| 1496 cl = self._make_client({'@columns': 'id,address,password'}, nodeid=None, | 1497 cl = self._make_client({'@columns': 'id,address,password'}, nodeid=None, |
| 1497 userid='2') | 1498 userid='2') |
| 1498 cl.classname = 'user' | 1499 cl.classname = 'user' |
| 1499 output = StringIO.StringIO() | 1500 output = StringIO() |
| 1500 cl.request = MockNull() | 1501 cl.request = MockNull() |
| 1501 cl.request.wfile = output | 1502 cl.request.wfile = output |
| 1502 # used to be self.assertRaises(exceptions.Unauthorised, | 1503 # used to be self.assertRaises(exceptions.Unauthorised, |
| 1503 # but not acting like the column name is not found | 1504 # but not acting like the column name is not found |
| 1504 self.assertRaises(exceptions.Unauthorised, | 1505 self.assertRaises(exceptions.Unauthorised, |
