Commit 4b7b78fc authored by Rémi Cardona's avatar Rémi Cardona
Browse files

[web/views] Controllers should always return bytes

Previous code breaks only on py3k.
parent 3f620fd1ed18
......@@ -23,12 +23,12 @@ from six.moves.urllib.parse import urlsplit, urlunsplit, urljoin, parse_qs
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 @@ import cubicweb.transaction as tx
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',
......
......@@ -128,7 +128,7 @@ class ViewController(Controller):
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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment