web/test/unittest_views_pyviews.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 21 Oct 2011 14:32:37 +0200
changeset 7992 4ff9f25cb06e
parent 6340 470d8e828fda
child 9806 37931aaebcfc
permissions -rw-r--r--
[table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView See the tickets for a description of the why. * one should now use RsetTableView instead of TableView and EntityTableView instead of EntityAttributesTableView. * a flexible layout object has been extracted, TableLayout * PyVaTableView has been rewritten using the same base class / renderer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
     1
# copyright 2003-2011 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: 4916
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: 4916
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: 4916
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: 4916
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: 4916
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: 4916
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: 4916
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: 4916
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: 4916
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: 4916
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: 4916
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: 4916
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: 4916
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: 4916
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: 4916
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
1987
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    18
from logilab.common.testlib import unittest_main
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    19
from cubicweb.devtools.testlib import CubicWebTC
1987
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    20
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    21
class PyViewsTC(CubicWebTC):
1987
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    22
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    23
    def test_pyvaltable(self):
3468
b02fa4db2868 [tests] make unittest_viewselectors pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2773
diff changeset
    24
        view = self.vreg['views'].select('pyvaltable', self.request(),
b02fa4db2868 [tests] make unittest_viewselectors pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2773
diff changeset
    25
                                         pyvalue=[[1, 'a'], [2, 'b']])
b02fa4db2868 [tests] make unittest_viewselectors pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2773
diff changeset
    26
        content = view.render(pyvalue=[[1, 'a'], [2, 'b']],
b02fa4db2868 [tests] make unittest_viewselectors pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2773
diff changeset
    27
                              headers=['num', 'char'])
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    28
        self.assertEqual(content.strip(), '''<table class="listing"><tbody>\
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    29
<tr class="even" onmouseout="$(this).removeClass(&quot;highlighted&quot;)" onmouseover="$(this).addClass(&quot;highlighted&quot;);"><td >1</td><td >a</td></tr>
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    30
<tr class="odd" onmouseout="$(this).removeClass(&quot;highlighted&quot;)" onmouseover="$(this).addClass(&quot;highlighted&quot;);"><td >2</td><td >b</td></tr>
4916
4b8cdda342ae fix tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3468
diff changeset
    31
</tbody></table>''')
1987
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    32
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    33
    def test_pyvallist(self):
3468
b02fa4db2868 [tests] make unittest_viewselectors pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2773
diff changeset
    34
        view = self.vreg['views'].select('pyvallist', self.request(),
b02fa4db2868 [tests] make unittest_viewselectors pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2773
diff changeset
    35
                                         pyvalue=[1, 'a'])
b02fa4db2868 [tests] make unittest_viewselectors pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2773
diff changeset
    36
        content = view.render(pyvalue=[1, 'a'])
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    37
        self.assertEqual(content.strip(), '''<ul>
1987
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    38
<li>1</li>
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    39
<li>a</li>
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    40
</ul>''')
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    41
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    42
if __name__ == '__main__':
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    43
    unittest_main()