web/test/unittest_views_baseviews.py
changeset 8941 7b26fe71404f
parent 8694 d901c36bcfce
child 9137 c791d8fddc15
equal deleted inserted replaced
8940:ae898a084da2 8941:7b26fe71404f
    19 from logilab.common.testlib import unittest_main
    19 from logilab.common.testlib import unittest_main
    20 from logilab.mtconverter import html_unescape
    20 from logilab.mtconverter import html_unescape
    21 
    21 
    22 from cubicweb.devtools.testlib import CubicWebTC
    22 from cubicweb.devtools.testlib import CubicWebTC
    23 from cubicweb.utils import json
    23 from cubicweb.utils import json
    24 from cubicweb.view import StartupView, TRANSITIONAL_DOCTYPE_NOEXT
    24 from cubicweb.view import StartupView, TRANSITIONAL_DOCTYPE
    25 from cubicweb.web.htmlwidgets import TableWidget
    25 from cubicweb.web.htmlwidgets import TableWidget
    26 from cubicweb.web.views import vid_from_rset
    26 from cubicweb.web.views import vid_from_rset
    27 
    27 
    28 def loadjson(value):
    28 def loadjson(value):
    29     return json.loads(html_unescape(value))
    29     return json.loads(html_unescape(value))
   131 
   131 
   132         with self.temporary_appobjects(MyView):
   132         with self.temporary_appobjects(MyView):
   133             html_source = self.view('my-view').source
   133             html_source = self.view('my-view').source
   134             source_lines = [line.strip() for line in html_source.splitlines(False)
   134             source_lines = [line.strip() for line in html_source.splitlines(False)
   135                             if line.strip()]
   135                             if line.strip()]
   136             self.assertListEqual(source_lines[:2],
   136             self.assertListEqual(['<!DOCTYPE html>', '<html lang="en">'], source_lines[:2])
   137                                  ['<!DOCTYPE html>',
       
   138                                   '<html xmlns="http://www.w3.org/1999/xhtml" xmlns:cubicweb="http://www.logilab.org/2008/cubicweb" xml:lang="en" lang="en">'])
       
   139 
   137 
   140     def test_set_doctype_no_reset_xmldecl(self):
   138     def test_set_doctype_no_reset_xmldecl(self):
   141         """
   139         """
   142         tests `cubicweb.web.request.CubicWebRequestBase.set_doctype`
   140         tests `cubicweb.web.request.CubicWebRequestBase.set_doctype`
   143         with no xmldecl reset
   141         with no xmldecl reset
   144         """
   142         """
   145         html_doctype = TRANSITIONAL_DOCTYPE_NOEXT.strip()
   143         html_doctype = TRANSITIONAL_DOCTYPE.strip()
   146         class MyView(StartupView):
   144         class MyView(StartupView):
   147             __regid__ = 'my-view'
   145             __regid__ = 'my-view'
   148             def call(self):
   146             def call(self):
   149                 self._cw.set_doctype(html_doctype, reset_xmldecl=False)
   147                 self._cw.set_doctype(html_doctype, reset_xmldecl=False)
   150                 self._cw.main_stream.set_namespaces([('xmlns', 'http://www.w3.org/1999/xhtml')])
       
   151                 self._cw.main_stream.set_htmlattrs([('lang', 'cz')])
   148                 self._cw.main_stream.set_htmlattrs([('lang', 'cz')])
   152 
   149 
   153         with self.temporary_appobjects(MyView):
   150         with self.temporary_appobjects(MyView):
   154             html_source = self.view('my-view').source
   151             html_source = self.view('my-view').source
   155             source_lines = [line.strip() for line in html_source.splitlines(False)
   152             source_lines = [line.strip() for line in html_source.splitlines(False)
   156                             if line.strip()]
   153                             if line.strip()]
   157             self.assertListEqual(source_lines[:3],
   154             self.assertListEqual([html_doctype, '<html lang="cz">', '<head>'],
   158                                  ['<?xml version="1.0" encoding="UTF-8"?>',
   155                                  source_lines[:3])
   159                                   html_doctype,
       
   160                                   '<html xmlns="http://www.w3.org/1999/xhtml" lang="cz">'])
       
   161 
   156 
   162 if __name__ == '__main__':
   157 if __name__ == '__main__':
   163     unittest_main()
   158     unittest_main()