cubicweb/web/test/unittest_views_debug_html.py
author Laurent Peuch <cortex@worlddomination.be>
Wed, 24 Jul 2019 16:11:22 +0200
changeset 12780 8caa109dfe94
permissions -rw-r--r--
[debug] add in each html snippet from where it has been generated in the code Closes #17219704
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12780
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
     1
# copyright 2019 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
     3
#
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
     4
# This file is part of CubicWeb.
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
     5
#
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
     9
# any later version.
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    10
#
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    14
# details.
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    15
#
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    18
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    19
import inspect
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    20
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    21
from cubicweb.view import View
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    22
from cubicweb.devtools.testlib import CubicWebTC
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    23
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    24
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    25
class DebugHtmlRenderingTC(CubicWebTC):
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    26
    def setUp(self):
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    27
        super().setUp()
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    28
        View.debug_html_rendering = True
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    29
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    30
    def tearDown(self):
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    31
        super().tearDown()
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    32
        View.debug_html_rendering = False
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    33
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    34
    def test_debug_html_rendering_inject_tags(self):
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    35
        with self.admin_access.web_request() as req:
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    36
            view = self.vreg['views'].select("index", req)
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    37
            view_class = view.__class__
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    38
            page = view.render()
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    39
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    40
            self.assertIn('cubicweb-generated-by="%s.%s"' % (view_class.__module__,
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    41
                                                             view_class.__name__),
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    42
                          page)
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    43
            source_file = inspect.getsourcefile(view_class)
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    44
            self.assertIn('cubicweb-from-source="%s' % (source_file), page)
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    45
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    46
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    47
if __name__ == '__main__':
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    48
    from logilab.common.testlib import unittest_main
8caa109dfe94 [debug] add in each html snippet from where it has been generated in the code
Laurent Peuch <cortex@worlddomination.be>
parents:
diff changeset
    49
    unittest_main()