# HG changeset patch # User RĂ©mi Cardona # Date 1449588425 -3600 # Node ID 9c6c3e68422ec8eb410dfae45047ee58133a5c1b # Parent 3f620fd1ed1886fd7485bd2fe27adebafd1d17f8 [web/views] Controllers should always return bytes Previous code breaks only on py3k. diff -r 3f620fd1ed18 -r 9c6c3e68422e web/test/unittest_views_basecontrollers.py --- a/web/test/unittest_views_basecontrollers.py Wed Dec 09 15:51:20 2015 +0100 +++ b/web/test/unittest_views_basecontrollers.py Tue Dec 08 16:27:05 2015 +0100 @@ -23,12 +23,12 @@ import lxml from logilab.common.testlib import unittest_main - from logilab.common.decorators import monkeypatch from cubicweb import Binary, NoSelectableObject, ValidationError from cubicweb.schema import RRQLExpression from cubicweb.devtools.testlib import CubicWebTC +from cubicweb.devtools.webtest import CubicWebTestTC from cubicweb.utils import json_dumps from cubicweb.uilib import rql_for_eid from cubicweb.web import Redirect, RemoteCallFailed @@ -41,6 +41,19 @@ from cubicweb.server.hook import Hook, Operation from cubicweb.predicates import is_instance + +class ViewControllerTC(CubicWebTestTC): + def test_view_ctrl_with_valid_cache_headers(self): + resp = self.webapp.get('/manage') + self.assertEqual(resp.etag, 'manage/guests') + self.assertEqual(resp.status_code, 200) + cache_headers = {'if-modified-since': resp.headers['Last-Modified'], + 'if-none-match': resp.etag} + resp = self.webapp.get('/manage', headers=cache_headers) + self.assertEqual(resp.status_code, 304) + self.assertEqual(len(resp.body), 0) + + def req_form(user): return {'eid': [str(user.eid)], '_cw_entity_fields:%s' % user.eid: '_cw_generic_field', diff -r 3f620fd1ed18 -r 9c6c3e68422e web/views/basecontrollers.py --- a/web/views/basecontrollers.py Wed Dec 09 15:51:20 2015 +0100 +++ b/web/views/basecontrollers.py Tue Dec 08 16:27:05 2015 +0100 @@ -128,7 +128,7 @@ view, rset = self._select_view_and_rset(rset) view.set_http_cache_headers() if self._cw.is_client_cache_valid(): - return '' + return b'' template = self.appli.main_template_id(self._cw) return self._cw.vreg['views'].main_template(self._cw, template, rset=rset, view=view)