diff -r 430a7dc5e2cf -r 7d3316bfa4ff web/test/unittest_views_staticcontrollers.py --- a/web/test/unittest_views_staticcontrollers.py Mon Sep 16 10:59:59 2013 +0200 +++ b/web/test/unittest_views_staticcontrollers.py Thu Sep 19 18:03:09 2013 +0200 @@ -1,3 +1,4 @@ +from logilab.common import tempattr from logilab.common.testlib import tag, Tags from cubicweb.devtools.testlib import CubicWebTC @@ -29,6 +30,46 @@ self.assertEqual(304, req.status_out) + +class DataControllerTC(CubicWebTC): + + tags = CubicWebTC.tags | Tags('static_controller', 'data', 'http') + + def _publish_static_files(self, url, header={}): + req = self.request(headers=header) + req._url = url + return self.app_handle_request(req, url), req + + def _check_datafile_ok(self, fname): + _, req = self._publish_static_files(fname) + self.assertEqual(200, req.status_out) + self.assertIn('last-modified', req.headers_out) + next_headers = { + 'if-modified-since': req.get_response_header('last-modified', raw=True), + } + _, req = self._publish_static_files(fname, next_headers) + self.assertEqual(304, req.status_out) + + def _check_no_datafile(self, fname): + _, req = self._publish_static_files(fname) + self.assertEqual(404, req.status_out) + + def test_static_data_mode(self): + hash = self.vreg.config.instance_md5_version() + self.assertEqual(32, len(hash)) + + with tempattr(self.vreg.config, 'mode', 'test'): + self._check_datafile_ok('data/cubicweb.css') + self._check_no_datafile('data/does/not/exist') + self._check_no_datafile('data/%s/cubicweb.css' % ('0'*len(hash))) + + with tempattr(self.vreg.config, 'mode', 'notest'): + self._check_datafile_ok('data/cubicweb.css') + self._check_datafile_ok('data/%s/cubicweb.css' % hash) + self._check_no_datafile('data/does/not/exist') + self._check_no_datafile('data/%s/cubicweb.css' % ('0'*len(hash))) + + class ConcatFilesTC(CubicWebTC): tags = CubicWebTC.tags | Tags('static_controller', 'concat')