cubicweb/web/test/unittest_views_pyviews.py
author Denis Laxalde <denis.laxalde@logilab.fr>
Sat, 16 Jan 2016 13:48:51 +0100
changeset 11057 0b59724cb3f2
parent 9806 web/test/unittest_views_pyviews.py@37931aaebcfc
permissions -rw-r--r--
Reorganize source tree to have a "cubicweb" top-level package Basically: mkdir cubicweb hg mv *.py -X setup.py cubicweb hg mv dataimport devtools entities etwist ext hooks i18n misc schemas server skeleton sobjects test web wsgi cubicweb Other changes: * adjust path to cubicweb-ctl in devtools tests * update setup.py to avoid importing __pkginfo__ (exec it instead), replace os.path.walk by os.walk and prepend `modname` here and there * update tox.ini to account for new test locations * update doc/conf.py so that it still finds __pkginfo__.py and CWDIR in doc/Makefile
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9806
37931aaebcfc [webtest/pyviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7992
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: 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):
9806
37931aaebcfc [webtest/pyviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7992
diff changeset
    24
        with self.admin_access.web_request() as req:
37931aaebcfc [webtest/pyviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7992
diff changeset
    25
            view = self.vreg['views'].select('pyvaltable', req,
37931aaebcfc [webtest/pyviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7992
diff changeset
    26
                                             pyvalue=[[1, 'a'], [2, 'b']])
37931aaebcfc [webtest/pyviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7992
diff changeset
    27
            content = view.render(pyvalue=[[1, 'a'], [2, 'b']],
37931aaebcfc [webtest/pyviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7992
diff changeset
    28
                                  headers=['num', 'char'])
37931aaebcfc [webtest/pyviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7992
diff changeset
    29
            self.assertEqual(content.strip(), '''<table class="listing"><tbody>\
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    30
<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
    31
<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
    32
</tbody></table>''')
1987
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    33
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    34
    def test_pyvallist(self):
9806
37931aaebcfc [webtest/pyviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7992
diff changeset
    35
        with self.admin_access.web_request() as req:
37931aaebcfc [webtest/pyviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7992
diff changeset
    36
            view = self.vreg['views'].select('pyvallist', req,
37931aaebcfc [webtest/pyviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7992
diff changeset
    37
                                             pyvalue=[1, 'a'])
37931aaebcfc [webtest/pyviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7992
diff changeset
    38
            content = view.render(pyvalue=[1, 'a'])
37931aaebcfc [webtest/pyviews] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7992
diff changeset
    39
            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
    40
<li>1</li>
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    41
<li>a</li>
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    42
</ul>''')
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    43
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    44
if __name__ == '__main__':
d495e9ce9367 basic views for python values (eg without any result set)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    45
    unittest_main()