1 from __future__ import with_statement |
1 from __future__ import with_statement |
2 |
2 |
|
3 from logilab.common.testlib import tag, Tags |
3 from cubicweb.devtools.testlib import CubicWebTC |
4 from cubicweb.devtools.testlib import CubicWebTC |
4 |
5 |
5 import os |
6 import os |
6 import os.path as osp |
7 import os.path as osp |
7 import glob |
8 import glob |
8 |
9 |
9 from cubicweb.utils import HTMLHead |
10 from cubicweb.utils import HTMLHead |
10 from cubicweb.web import StatusResponse |
11 from cubicweb.web import StatusResponse |
11 from cubicweb.web.views.staticcontrollers import ConcatFilesHandler |
12 from cubicweb.web.views.staticcontrollers import ConcatFilesHandler |
12 |
13 |
|
14 class StaticControllerCacheTC(CubicWebTC): |
|
15 |
|
16 tags = CubicWebTC.tags | Tags('static_controller', 'cache', 'http') |
|
17 |
|
18 |
|
19 def _publish_static_files(self, url, header={}): |
|
20 req = self.request(headers=header) |
|
21 req._url = url |
|
22 return self.app_handle_request(req, url), req |
|
23 |
|
24 def test_static_file_are_cached(self): |
|
25 _, req = self._publish_static_files('data/cubicweb.css') |
|
26 self.assertEqual(200, req.status_out) |
|
27 self.assertIn('last-modified', req.headers_out) |
|
28 next_headers = { |
|
29 'if-modified-since': req.get_response_header('last-modified', raw=True), |
|
30 } |
|
31 _, req = self._publish_static_files('data/cubicweb.css', next_headers) |
|
32 self.assertEqual(304, req.status_out) |
|
33 |
|
34 |
13 class ConcatFilesTC(CubicWebTC): |
35 class ConcatFilesTC(CubicWebTC): |
|
36 |
|
37 tags = CubicWebTC.tags | Tags('static_controller', 'concat') |
14 |
38 |
15 def tearDown(self): |
39 def tearDown(self): |
16 super(ConcatFilesTC, self).tearDown() |
40 super(ConcatFilesTC, self).tearDown() |
17 self._cleanup_concat_cache() |
41 self._cleanup_concat_cache() |
18 |
42 |