Switched from TwistedWeb2 to TwistedWeb
- added HTTPResponse class in etwist/http.py (could be then abstracted in cubicweb/web)
- added twisted.web2 http_headers.py file in cubicweb/web to handle HTTP headers conversion between raw headers and python object
- deleted caching for base views (except for startup views). A better solution would be using weak entity tags (but they don't seem
to be implemented in twisted.web).
- added forbidden access message when browsing static local directories
- tested with TwistedWeb 8, 9 and 10
TODO:
=====
- Handle file uploading in forms.
twisted.web seems to keep very little information (only file content) about uploaded files in twisted_request.args['input_field_name']. But it doesn't seem to keep track of filenames.
Possible solutions :
- use web2 code to parse raw request content still stored and available in twisted_request.content
- find a magic function in twisted.web API to get the filenames
- More tests.
"""cubicweb.web.controller unit tests
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
"""
from datetime import datetime, date, time
from logilab.common.testlib import unittest_main
from cubicweb.devtools import testlib
class BaseControllerTC(testlib.CubicWebTC):
def test_parse_datetime_ok(self):
ctrl = self.vreg['controllers'].select('view', self.request())
pd = ctrl._cw.parse_datetime
self.assertIsInstance(pd('2006/06/24 12:18'), datetime)
self.assertIsInstance(pd('2006/06/24'), date)
self.assertIsInstance(pd('2006/06/24 12:18', 'Datetime'), datetime)
self.assertIsInstance(pd('2006/06/24', 'Datetime'), datetime)
self.assertIsInstance(pd('2006/06/24', 'Date'), date)
self.assertIsInstance(pd('12:18', 'Time'), time)
def test_parse_datetime_ko(self):
ctrl = self.vreg['controllers'].select('view', self.request())
pd = ctrl._cw.parse_datetime
self.assertRaises(ValueError,
pd, '2006/06/24 12:188', 'Datetime')
self.assertRaises(ValueError,
pd, '2006/06/240', 'Datetime')
self.assertRaises(ValueError,
pd, '2006/06/24 12:18', 'Date')
self.assertRaises(ValueError,
pd, '2006/24/06', 'Date')
self.assertRaises(ValueError,
pd, '2006/06/240', 'Date')
self.assertRaises(ValueError,
pd, '12:188', 'Time')
if __name__ == '__main__':
unittest_main()