author | Rémi Cardona <remi.cardona@logilab.fr> |
Tue, 15 Dec 2015 11:41:25 +0100 | |
changeset 10978 | 6f88cb7b7a84 |
parent 10167 | de62952550d9 |
permissions | -rw-r--r-- |
10167
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
1 |
# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
3 |
# |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
4 |
# This file is part of CubicWeb. |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
5 |
# |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
9 |
# any later version. |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
10 |
# |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
14 |
# details. |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
15 |
# |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
18 |
|
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
19 |
from logilab.common.testlib import unittest_main |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
20 |
from logilab.mtconverter import html_unescape |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
21 |
|
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
22 |
from cubicweb.devtools.htmlparser import XMLValidator |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
23 |
from cubicweb.devtools.testlib import CubicWebTC |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
24 |
|
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
25 |
|
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
26 |
class TreeViewTC(CubicWebTC): |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
27 |
|
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
28 |
def test_treeview(self): |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
29 |
with self.admin_access.repo_cnx() as cnx: |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
30 |
ce = cnx.create_entity |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
31 |
root = ce('TreeNode', name=u'root') |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
32 |
node = ce('TreeNode', name=u'node1', parent=root) |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
33 |
ce('TreeNode', name=u'leaf1a', parent=node) |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
34 |
ce('TreeNode', name=u'leaf1b', parent=node) |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
35 |
node = ce('TreeNode', name=u'node2', parent=root) |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
36 |
ce('TreeNode', name=u'leaf2a', parent=node) |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
37 |
ce('TreeNode', name=u'leaf2b', parent=node) |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
38 |
root_eid = root.eid |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
39 |
cnx.commit() |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
40 |
|
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
41 |
with self.admin_access.web_request() as req: |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
42 |
root = req.entity_from_eid(root_eid) |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
43 |
valid = self.content_type_validators.get('text/html', XMLValidator)() |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
44 |
page = valid.parse_string(root.view('tree', klass='oh-my-class')) |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
45 |
uls = page.find_tag('ul', gettext=False) |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
46 |
for _, attrib in uls: |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
47 |
self.assertEqual(attrib['class'], 'oh-my-class') |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
48 |
|
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
49 |
|
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
50 |
if __name__ == '__main__': |
de62952550d9
[web] Allow propagating 'klass' parameter on tree views recursively
Rémi Cardona <remi.cardona@logilab.fr>
parents:
diff
changeset
|
51 |
unittest_main() |