web/test/unittest_views_baseviews.py
author Julien Cristau <julien.cristau@logilab.fr>
Tue, 24 Nov 2015 14:08:47 +0100
changeset 10907 9ae707db5265
parent 10726 bb91f581c389
permissions -rw-r--r--
Remove trailing empty lines Makes pep8 happier
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9838
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
     1
# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
1977
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1654
diff changeset
    18
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
from logilab.common.testlib import unittest_main
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
from logilab.mtconverter import html_unescape
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    22
from cubicweb.devtools.testlib import CubicWebTC
5940
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    23
from cubicweb.utils import json
8941
7b26fe71404f drop xhtml content-type support (closes #2065651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
    24
from cubicweb.view import StartupView, TRANSITIONAL_DOCTYPE
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    25
from cubicweb.web.views import vid_from_rset
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
def loadjson(value):
5940
0e3ae19b181a [uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    28
    return json.loads(html_unescape(value))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    30
class VidFromRsetTC(CubicWebTC):
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    31
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    32
    def test_no_rset(self):
9838
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    33
        with self.admin_access.web_request() as req:
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    34
            self.assertEqual(vid_from_rset(req, None, self.schema), 'index')
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    35
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
    def test_no_entity(self):
9838
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    37
        with self.admin_access.web_request() as req:
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    38
            rset = req.execute('Any X WHERE X login "blabla"')
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    39
            self.assertEqual(vid_from_rset(req, rset, self.schema), 'noresult')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    41
    def test_one_entity(self):
9838
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    42
        with self.admin_access.web_request() as req:
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    43
            rset = req.execute('Any X WHERE X login "admin"')
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    44
            self.assertEqual(vid_from_rset(req, rset, self.schema), 'primary')
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    45
            rset = req.execute('Any X, L WHERE X login "admin", X login L')
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    46
            self.assertEqual(vid_from_rset(req, rset, self.schema), 'primary')
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    47
            req.search_state = ('pasnormal',)
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    48
            rset = req.execute('Any X WHERE X login "admin"')
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    49
            self.assertEqual(vid_from_rset(req, rset, self.schema), 'outofcontext-search')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    51
    def test_one_entity_eid(self):
9838
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    52
        with self.admin_access.web_request() as req:
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    53
            rset = req.execute('Any X WHERE X eid 1')
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    54
            self.assertEqual(vid_from_rset(req, rset, self.schema), 'primary')
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    55
2637
07103211e511 R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2381
diff changeset
    56
    def test_more_than_one_entity_same_type(self):
9838
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    57
        with self.admin_access.web_request() as req:
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    58
            rset = req.execute('Any X WHERE X is CWUser')
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    59
            self.assertEqual(vid_from_rset(req, rset, self.schema), 'sameetypelist')
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    60
            rset = req.execute('Any X, L WHERE X login L')
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    61
            self.assertEqual(vid_from_rset(req, rset, self.schema), 'sameetypelist')
2637
07103211e511 R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2381
diff changeset
    62
07103211e511 R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2381
diff changeset
    63
    def test_more_than_one_entity_diff_type(self):
9838
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    64
        with self.admin_access.web_request() as req:
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    65
            rset = req.execute('Any X WHERE X is IN (CWUser, CWGroup)')
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    66
            self.assertEqual(vid_from_rset(req, rset, self.schema), 'list')
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    67
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
    def test_more_than_one_entity_by_row(self):
9838
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    69
        with self.admin_access.web_request() as req:
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    70
            rset = req.execute('Any X, G WHERE X in_group G')
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    71
            self.assertEqual(vid_from_rset(req, rset, self.schema), 'table')
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    72
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    73
    def test_more_than_one_entity_by_row_2(self):
9838
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    74
        with self.admin_access.web_request() as req:
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    75
            rset = req.execute('Any X, GN WHERE X in_group G, G name GN')
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    76
            self.assertEqual(vid_from_rset(req, rset, self.schema), 'table')
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    77
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
    def test_aggregat(self):
9838
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    79
        with self.admin_access.web_request() as req:
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    80
            rset = req.execute('Any X, COUNT(T) GROUPBY X WHERE X is T')
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    81
            self.assertEqual(vid_from_rset(req, rset, self.schema), 'table')
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    82
            rset = req.execute('Any MAX(X) WHERE X is CWUser')
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    83
            self.assertEqual(vid_from_rset(req, rset, self.schema), 'table')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
    def test_subquery(self):
9838
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    86
        with self.admin_access.web_request() as req:
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    87
            rset = req.execute(
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    88
'DISTINCT Any X,N ORDERBY N '
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    89
'WITH X,N BEING ('
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    90
'     (DISTINCT Any P,N WHERE P is CWUser, P login N)'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    91
'       UNION'
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    92
'     (DISTINCT Any W,N WHERE W is CWGroup, W name N))')
9838
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    93
            self.assertEqual(vid_from_rset(req, rset, self.schema), 'table')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    94
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    95
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    96
class TableViewTC(CubicWebTC):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
9838
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
    98
    def _prepare_entity(self, req):
4083
3b285889b8e9 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3777
diff changeset
    99
        e = req.create_entity("State", name=u'<toto>', description=u'loo"ong blabla')
9838
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
   100
        rset = req.execute('Any X, D, CD, NOW - CD WHERE X is State, '
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
   101
                           'X description D, X creation_date CD, X eid %(x)s',
5174
78438ad513ca #759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4494
diff changeset
   102
                           {'x': e.eid})
2650
18aec79ec3a3 R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2637
diff changeset
   103
        view = self.vreg['views'].select('table', req, rset=rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   104
        return e, rset, view
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   105
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
    def test_sortvalue(self):
9838
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
   107
        with self.admin_access.web_request() as req:
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
   108
            e, _, view = self._prepare_entity(req)
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
   109
            colrenderers = view.build_column_renderers()[:3]
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
   110
            self.assertListEqual([renderer.sortvalue(0) for renderer in colrenderers],
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
   111
                                 [u'<toto>', u'loo"ong blabla', e.creation_date])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   112
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   113
7187
496f51b92154 [views] extend HTMLStream API to be able to change doctype / xmldecl
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   114
class HTMLStreamTests(CubicWebTC):
496f51b92154 [views] extend HTMLStream API to be able to change doctype / xmldecl
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   115
496f51b92154 [views] extend HTMLStream API to be able to change doctype / xmldecl
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   116
    def test_set_doctype_reset_xmldecl(self):
496f51b92154 [views] extend HTMLStream API to be able to change doctype / xmldecl
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   117
        """
496f51b92154 [views] extend HTMLStream API to be able to change doctype / xmldecl
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   118
        tests `cubicweb.web.request.CubicWebRequestBase.set_doctype`
496f51b92154 [views] extend HTMLStream API to be able to change doctype / xmldecl
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   119
        with xmldecl reset
496f51b92154 [views] extend HTMLStream API to be able to change doctype / xmldecl
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   120
        """
496f51b92154 [views] extend HTMLStream API to be able to change doctype / xmldecl
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   121
        class MyView(StartupView):
496f51b92154 [views] extend HTMLStream API to be able to change doctype / xmldecl
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   122
            __regid__ = 'my-view'
496f51b92154 [views] extend HTMLStream API to be able to change doctype / xmldecl
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   123
            def call(self):
496f51b92154 [views] extend HTMLStream API to be able to change doctype / xmldecl
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   124
                self._cw.set_doctype('<!DOCTYPE html>')
496f51b92154 [views] extend HTMLStream API to be able to change doctype / xmldecl
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   125
9838
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
   126
        with self.admin_access.web_request() as req:
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
   127
            with self.temporary_appobjects(MyView):
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
   128
                html_source = self.view('my-view', req=req).source
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
   129
                source_lines = [line.strip()
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
   130
                                for line in html_source.splitlines(False)
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
   131
                                if line.strip()]
10726
bb91f581c389 [py3k] PageInfo.source contains bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9838
diff changeset
   132
                self.assertListEqual([b'<!DOCTYPE html>',
bb91f581c389 [py3k] PageInfo.source contains bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9838
diff changeset
   133
                                      b'<html xmlns:cubicweb="http://www.cubicweb.org" lang="en">'],
9838
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
   134
                                     source_lines[:2])
7187
496f51b92154 [views] extend HTMLStream API to be able to change doctype / xmldecl
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   135
496f51b92154 [views] extend HTMLStream API to be able to change doctype / xmldecl
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   136
    def test_set_doctype_no_reset_xmldecl(self):
496f51b92154 [views] extend HTMLStream API to be able to change doctype / xmldecl
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   137
        """
496f51b92154 [views] extend HTMLStream API to be able to change doctype / xmldecl
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   138
        tests `cubicweb.web.request.CubicWebRequestBase.set_doctype`
496f51b92154 [views] extend HTMLStream API to be able to change doctype / xmldecl
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   139
        with no xmldecl reset
496f51b92154 [views] extend HTMLStream API to be able to change doctype / xmldecl
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   140
        """
8941
7b26fe71404f drop xhtml content-type support (closes #2065651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8694
diff changeset
   141
        html_doctype = TRANSITIONAL_DOCTYPE.strip()
7187
496f51b92154 [views] extend HTMLStream API to be able to change doctype / xmldecl
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   142
        class MyView(StartupView):
496f51b92154 [views] extend HTMLStream API to be able to change doctype / xmldecl
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   143
            __regid__ = 'my-view'
496f51b92154 [views] extend HTMLStream API to be able to change doctype / xmldecl
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   144
            def call(self):
9137
c791d8fddc15 [web doctype test] don't give reset_xmldecl to avoid deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8941
diff changeset
   145
                self._cw.set_doctype(html_doctype)
7187
496f51b92154 [views] extend HTMLStream API to be able to change doctype / xmldecl
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   146
                self._cw.main_stream.set_htmlattrs([('lang', 'cz')])
496f51b92154 [views] extend HTMLStream API to be able to change doctype / xmldecl
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   147
9838
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
   148
        with self.admin_access.web_request() as req:
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
   149
            with self.temporary_appobjects(MyView):
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
   150
                html_source = self.view('my-view', req=req).source
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
   151
                source_lines = [line.strip()
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
   152
                                for line in html_source.splitlines(False)
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
   153
                                if line.strip()]
10726
bb91f581c389 [py3k] PageInfo.source contains bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9838
diff changeset
   154
                self.assertListEqual([html_doctype.encode('ascii'),
bb91f581c389 [py3k] PageInfo.source contains bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9838
diff changeset
   155
                                      b'<html xmlns:cubicweb="http://www.cubicweb.org" lang="cz">',
bb91f581c389 [py3k] PageInfo.source contains bytes
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9838
diff changeset
   156
                                      b'<head>'],
9838
14640aeb5ddc [webtests/baseviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9523
diff changeset
   157
                                     source_lines[:3])
7187
496f51b92154 [views] extend HTMLStream API to be able to change doctype / xmldecl
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   158
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   159
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   160
    unittest_main()