25 next_headers = { |
26 next_headers = { |
26 'if-modified-since': req.get_response_header('last-modified', raw=True), |
27 'if-modified-since': req.get_response_header('last-modified', raw=True), |
27 } |
28 } |
28 _, req = self._publish_static_files('data/cubicweb.css', next_headers) |
29 _, req = self._publish_static_files('data/cubicweb.css', next_headers) |
29 self.assertEqual(304, req.status_out) |
30 self.assertEqual(304, req.status_out) |
|
31 |
|
32 |
|
33 |
|
34 class DataControllerTC(CubicWebTC): |
|
35 |
|
36 tags = CubicWebTC.tags | Tags('static_controller', 'data', 'http') |
|
37 |
|
38 def _publish_static_files(self, url, header={}): |
|
39 req = self.request(headers=header) |
|
40 req._url = url |
|
41 return self.app_handle_request(req, url), req |
|
42 |
|
43 def _check_datafile_ok(self, fname): |
|
44 _, req = self._publish_static_files(fname) |
|
45 self.assertEqual(200, req.status_out) |
|
46 self.assertIn('last-modified', req.headers_out) |
|
47 next_headers = { |
|
48 'if-modified-since': req.get_response_header('last-modified', raw=True), |
|
49 } |
|
50 _, req = self._publish_static_files(fname, next_headers) |
|
51 self.assertEqual(304, req.status_out) |
|
52 |
|
53 def _check_no_datafile(self, fname): |
|
54 _, req = self._publish_static_files(fname) |
|
55 self.assertEqual(404, req.status_out) |
|
56 |
|
57 def test_static_data_mode(self): |
|
58 hash = self.vreg.config.instance_md5_version() |
|
59 self.assertEqual(32, len(hash)) |
|
60 |
|
61 with tempattr(self.vreg.config, 'mode', 'test'): |
|
62 self._check_datafile_ok('data/cubicweb.css') |
|
63 self._check_no_datafile('data/does/not/exist') |
|
64 self._check_no_datafile('data/%s/cubicweb.css' % ('0'*len(hash))) |
|
65 |
|
66 with tempattr(self.vreg.config, 'mode', 'notest'): |
|
67 self._check_datafile_ok('data/cubicweb.css') |
|
68 self._check_datafile_ok('data/%s/cubicweb.css' % hash) |
|
69 self._check_no_datafile('data/does/not/exist') |
|
70 self._check_no_datafile('data/%s/cubicweb.css' % ('0'*len(hash))) |
30 |
71 |
31 |
72 |
32 class ConcatFilesTC(CubicWebTC): |
73 class ConcatFilesTC(CubicWebTC): |
33 |
74 |
34 tags = CubicWebTC.tags | Tags('static_controller', 'concat') |
75 tags = CubicWebTC.tags | Tags('static_controller', 'concat') |