web/test/unittest_views_staticcontrollers.py
author Julien Cristau <julien.cristau@logilab.fr>
Wed, 02 Apr 2014 15:42:25 +0200
changeset 9624 a42fae4cd45a
parent 9233 7d3316bfa4ff
child 9812 122c0b6a82a3
permissions -rw-r--r--
[web/sessions] use session.sessionid instead of deprecated session.id
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9233
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
     1
from logilab.common import tempattr
8323
fe60a77ae4a7 static-file: properly set/use cache header for static file (closes #2255013)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8312
diff changeset
     2
from logilab.common.testlib import tag, Tags
8298
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     3
from cubicweb.devtools.testlib import CubicWebTC
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     4
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     5
import os
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     6
import os.path as osp
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     7
import glob
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     8
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     9
from cubicweb.utils import HTMLHead
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    10
from cubicweb.web.views.staticcontrollers import ConcatFilesHandler
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    11
8323
fe60a77ae4a7 static-file: properly set/use cache header for static file (closes #2255013)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8312
diff changeset
    12
class StaticControllerCacheTC(CubicWebTC):
fe60a77ae4a7 static-file: properly set/use cache header for static file (closes #2255013)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8312
diff changeset
    13
fe60a77ae4a7 static-file: properly set/use cache header for static file (closes #2255013)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8312
diff changeset
    14
    tags = CubicWebTC.tags | Tags('static_controller', 'cache', 'http')
fe60a77ae4a7 static-file: properly set/use cache header for static file (closes #2255013)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8312
diff changeset
    15
fe60a77ae4a7 static-file: properly set/use cache header for static file (closes #2255013)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8312
diff changeset
    16
fe60a77ae4a7 static-file: properly set/use cache header for static file (closes #2255013)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8312
diff changeset
    17
    def _publish_static_files(self, url, header={}):
fe60a77ae4a7 static-file: properly set/use cache header for static file (closes #2255013)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8312
diff changeset
    18
        req = self.request(headers=header)
fe60a77ae4a7 static-file: properly set/use cache header for static file (closes #2255013)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8312
diff changeset
    19
        req._url = url
fe60a77ae4a7 static-file: properly set/use cache header for static file (closes #2255013)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8312
diff changeset
    20
        return self.app_handle_request(req, url), req
fe60a77ae4a7 static-file: properly set/use cache header for static file (closes #2255013)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8312
diff changeset
    21
fe60a77ae4a7 static-file: properly set/use cache header for static file (closes #2255013)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8312
diff changeset
    22
    def test_static_file_are_cached(self):
fe60a77ae4a7 static-file: properly set/use cache header for static file (closes #2255013)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8312
diff changeset
    23
        _, req = self._publish_static_files('data/cubicweb.css')
fe60a77ae4a7 static-file: properly set/use cache header for static file (closes #2255013)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8312
diff changeset
    24
        self.assertEqual(200, req.status_out)
fe60a77ae4a7 static-file: properly set/use cache header for static file (closes #2255013)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8312
diff changeset
    25
        self.assertIn('last-modified', req.headers_out)
fe60a77ae4a7 static-file: properly set/use cache header for static file (closes #2255013)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8312
diff changeset
    26
        next_headers = {
fe60a77ae4a7 static-file: properly set/use cache header for static file (closes #2255013)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8312
diff changeset
    27
            'if-modified-since': req.get_response_header('last-modified', raw=True),
fe60a77ae4a7 static-file: properly set/use cache header for static file (closes #2255013)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8312
diff changeset
    28
        }
fe60a77ae4a7 static-file: properly set/use cache header for static file (closes #2255013)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8312
diff changeset
    29
        _, req = self._publish_static_files('data/cubicweb.css', next_headers)
fe60a77ae4a7 static-file: properly set/use cache header for static file (closes #2255013)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8312
diff changeset
    30
        self.assertEqual(304, req.status_out)
fe60a77ae4a7 static-file: properly set/use cache header for static file (closes #2255013)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8312
diff changeset
    31
fe60a77ae4a7 static-file: properly set/use cache header for static file (closes #2255013)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8312
diff changeset
    32
9233
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    33
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    34
class DataControllerTC(CubicWebTC):
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    35
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    36
    tags = CubicWebTC.tags | Tags('static_controller', 'data', 'http')
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    37
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    38
    def _publish_static_files(self, url, header={}):
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    39
        req = self.request(headers=header)
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    40
        req._url = url
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    41
        return self.app_handle_request(req, url), req
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    42
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    43
    def _check_datafile_ok(self, fname):
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    44
        _, req = self._publish_static_files(fname)
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    45
        self.assertEqual(200, req.status_out)
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    46
        self.assertIn('last-modified', req.headers_out)
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    47
        next_headers = {
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    48
            'if-modified-since': req.get_response_header('last-modified', raw=True),
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    49
        }
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    50
        _, req = self._publish_static_files(fname, next_headers)
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    51
        self.assertEqual(304, req.status_out)
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    52
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    53
    def _check_no_datafile(self, fname):
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    54
        _, req = self._publish_static_files(fname)
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    55
        self.assertEqual(404, req.status_out)
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    56
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    57
    def test_static_data_mode(self):
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    58
        hash = self.vreg.config.instance_md5_version()
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    59
        self.assertEqual(32, len(hash))
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    60
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    61
        with tempattr(self.vreg.config, 'mode', 'test'):
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    62
            self._check_datafile_ok('data/cubicweb.css')
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    63
            self._check_no_datafile('data/does/not/exist')
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    64
            self._check_no_datafile('data/%s/cubicweb.css' % ('0'*len(hash)))
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    65
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    66
        with tempattr(self.vreg.config, 'mode', 'notest'):
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    67
            self._check_datafile_ok('data/cubicweb.css')
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    68
            self._check_datafile_ok('data/%s/cubicweb.css' % hash)
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    69
            self._check_no_datafile('data/does/not/exist')
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    70
            self._check_no_datafile('data/%s/cubicweb.css' % ('0'*len(hash)))
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    71
7d3316bfa4ff [web] allow /data/ url again (closes #2464798)
David Douard <david.douard@logilab.fr>
parents: 8694
diff changeset
    72
8298
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    73
class ConcatFilesTC(CubicWebTC):
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    74
8323
fe60a77ae4a7 static-file: properly set/use cache header for static file (closes #2255013)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8312
diff changeset
    75
    tags = CubicWebTC.tags | Tags('static_controller', 'concat')
fe60a77ae4a7 static-file: properly set/use cache header for static file (closes #2255013)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8312
diff changeset
    76
8298
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    77
    def tearDown(self):
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
        super(ConcatFilesTC, self).tearDown()
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
        self._cleanup_concat_cache()
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    81
    def _cleanup_concat_cache(self):
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
        uicachedir = osp.join(self.config.apphome, 'uicache')
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
        for fname in glob.glob(osp.join(uicachedir, 'cache_concat_*')):
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
            os.unlink(osp.join(uicachedir, fname))
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    86
    def _publish_js_files(self, js_files):
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    87
        req = self.request()
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    88
        head = HTMLHead(req)
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    89
        url = head.concat_urls([req.data_url(js_file) for js_file in js_files])[len(req.base_url()):]
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    90
        req._url = url
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8298
diff changeset
    91
        return self.app_handle_request(req, url), req
8298
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    92
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    93
    def expected_content(self, js_files):
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    94
        content = u''
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    95
        for js_file in js_files:
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    96
            dirpath, rid = self.config.locate_resource(js_file)
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
            if dirpath is not None: # ignore resources not found
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
                with open(osp.join(dirpath, rid)) as f:
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
                    content += f.read() + '\n'
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
        return content
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   101
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
    def test_cache(self):
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
        js_files = ('cubicweb.ajax.js', 'jquery.js')
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8298
diff changeset
   104
        result, req = self._publish_js_files(js_files)
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8298
diff changeset
   105
        self.assertNotEqual(404, req.status_out)
8298
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
        # check result content
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
        self.assertEqual(result, self.expected_content(js_files))
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
        # make sure we kept a cached version on filesystem
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
        concat_hander = ConcatFilesHandler(self.config)
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
        filepath = concat_hander.build_filepath(js_files)
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
        self.assertTrue(osp.isfile(filepath))
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   112
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   113
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   114
    def test_invalid_file_in_debug_mode(self):
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   115
        js_files = ('cubicweb.ajax.js', 'dummy.js')
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   116
        # in debug mode, an error is raised
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   117
        self.config.debugmode = True
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   118
        try:
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8298
diff changeset
   119
            result, req = self._publish_js_files(js_files)
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8298
diff changeset
   120
            #print result
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8298
diff changeset
   121
            self.assertEqual(404, req.status_out)
8298
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   122
        finally:
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
            self.config.debugmode = False
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   124
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
    def test_invalid_file_in_production_mode(self):
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   126
        js_files = ('cubicweb.ajax.js', 'dummy.js')
8312
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8298
diff changeset
   127
        result, req = self._publish_js_files(js_files)
6c2119509fac [web] Move request handling logic into cubicweb application. (closes #2200684)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8298
diff changeset
   128
        self.assertNotEqual(404, req.status_out)
8298
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   129
        # check result content
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   130
        self.assertEqual(result, self.expected_content(js_files))
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   131
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   132
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   133
if __name__ == '__main__':
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   134
    from logilab.common.testlib import unittest_main
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   135
    unittest_main()
2a4bc6f75e9c [twisted] move out url logic from twisted (closes #2200593)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   136