cubicweb/web/test/unittest_views_basecontrollers.py
changeset 11241 a2091fa8cb2c
parent 11200 8ddfed7a5981
child 11268 f6938ae0dea8
equal deleted inserted replaced
11240:1694e6e9ff94 11241:a2091fa8cb2c
    15 #
    15 #
    16 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License along
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """cubicweb.web.views.basecontrollers unit tests"""
    18 """cubicweb.web.views.basecontrollers unit tests"""
    19 
    19 
       
    20 import time
       
    21 
    20 from six import text_type
    22 from six import text_type
    21 from six.moves.urllib.parse import urlsplit, urlunsplit, urljoin, parse_qs
    23 from six.moves.urllib.parse import urlsplit, urlunsplit, urljoin, parse_qs
    22 
    24 
    23 import lxml
    25 import lxml
    24 
    26 
    29 from cubicweb.schema import RRQLExpression
    31 from cubicweb.schema import RRQLExpression
    30 from cubicweb.devtools.testlib import CubicWebTC
    32 from cubicweb.devtools.testlib import CubicWebTC
    31 from cubicweb.devtools.webtest import CubicWebTestTC
    33 from cubicweb.devtools.webtest import CubicWebTestTC
    32 from cubicweb.utils import json_dumps
    34 from cubicweb.utils import json_dumps
    33 from cubicweb.uilib import rql_for_eid
    35 from cubicweb.uilib import rql_for_eid
    34 from cubicweb.web import Redirect, RemoteCallFailed
    36 from cubicweb.web import Redirect, RemoteCallFailed, http_headers
    35 import cubicweb.server.session
    37 import cubicweb.server.session
    36 from cubicweb.server.session import Connection
    38 from cubicweb.server.session import Connection
    37 from cubicweb.web.views.autoform import get_pending_inserts, get_pending_deletes
    39 from cubicweb.web.views.autoform import get_pending_inserts, get_pending_deletes
    38 from cubicweb.web.views.basecontrollers import JSonController, xhtmlize, jsonize
    40 from cubicweb.web.views.basecontrollers import JSonController, xhtmlize, jsonize
    39 from cubicweb.web.views.ajaxcontroller import ajaxfunc, AjaxFunction
    41 from cubicweb.web.views.ajaxcontroller import ajaxfunc, AjaxFunction
    42 from cubicweb.predicates import is_instance
    44 from cubicweb.predicates import is_instance
    43 
    45 
    44 
    46 
    45 class ViewControllerTC(CubicWebTestTC):
    47 class ViewControllerTC(CubicWebTestTC):
    46     def test_view_ctrl_with_valid_cache_headers(self):
    48     def test_view_ctrl_with_valid_cache_headers(self):
       
    49         now = time.time()
    47         resp = self.webapp.get('/manage')
    50         resp = self.webapp.get('/manage')
    48         self.assertEqual(resp.etag, 'manage/guests')
    51         self.assertEqual(resp.etag, 'manage/guests')
    49         self.assertEqual(resp.status_code, 200)
    52         self.assertEqual(resp.status_code, 200)
       
    53         self.assertGreaterEqual(http_headers.parseDateTime(resp.headers['Last-Modified']), int(now))
    50         cache_headers = {'if-modified-since': resp.headers['Last-Modified'],
    54         cache_headers = {'if-modified-since': resp.headers['Last-Modified'],
    51                          'if-none-match': resp.etag}
    55                          'if-none-match': resp.etag}
    52         resp = self.webapp.get('/manage', headers=cache_headers)
    56         resp = self.webapp.get('/manage', headers=cache_headers)
    53         self.assertEqual(resp.status_code, 304)
    57         self.assertEqual(resp.status_code, 304)
    54         self.assertEqual(len(resp.body), 0)
    58         self.assertEqual(len(resp.body), 0)