cubicweb/web/test/unittest_views_debug_html.py
changeset 12780 8caa109dfe94
equal deleted inserted replaced
12779:44147dab9d27 12780:8caa109dfe94
       
     1 # copyright 2019 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
       
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
     3 #
       
     4 # This file is part of CubicWeb.
       
     5 #
       
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
       
     7 # terms of the GNU Lesser General Public License as published by the Free
       
     8 # Software Foundation, either version 2.1 of the License, or (at your option)
       
     9 # any later version.
       
    10 #
       
    11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT
       
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
       
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
       
    14 # details.
       
    15 #
       
    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/>.
       
    18 
       
    19 import inspect
       
    20 
       
    21 from cubicweb.view import View
       
    22 from cubicweb.devtools.testlib import CubicWebTC
       
    23 
       
    24 
       
    25 class DebugHtmlRenderingTC(CubicWebTC):
       
    26     def setUp(self):
       
    27         super().setUp()
       
    28         View.debug_html_rendering = True
       
    29 
       
    30     def tearDown(self):
       
    31         super().tearDown()
       
    32         View.debug_html_rendering = False
       
    33 
       
    34     def test_debug_html_rendering_inject_tags(self):
       
    35         with self.admin_access.web_request() as req:
       
    36             view = self.vreg['views'].select("index", req)
       
    37             view_class = view.__class__
       
    38             page = view.render()
       
    39 
       
    40             self.assertIn('cubicweb-generated-by="%s.%s"' % (view_class.__module__,
       
    41                                                              view_class.__name__),
       
    42                           page)
       
    43             source_file = inspect.getsourcefile(view_class)
       
    44             self.assertIn('cubicweb-from-source="%s' % (source_file), page)
       
    45 
       
    46 
       
    47 if __name__ == '__main__':
       
    48     from logilab.common.testlib import unittest_main
       
    49     unittest_main()