web/test/unittest_views_pyviews.py
changeset 11057 0b59724cb3f2
parent 11052 058bb3dc685f
child 11058 23eb30449fe5
equal deleted inserted replaced
11052:058bb3dc685f 11057:0b59724cb3f2
     1 # copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
       
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
     3 #
       
     4 # This file is part of CubicWeb.
       
     5 #
       
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
       
     7 # terms of the GNU Lesser General Public License as published by the Free
       
     8 # Software Foundation, either version 2.1 of the License, or (at your option)
       
     9 # any later version.
       
    10 #
       
    11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT
       
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
       
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
       
    14 # details.
       
    15 #
       
    16 # You should have received a copy of the GNU Lesser General Public License along
       
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
       
    18 from logilab.common.testlib import unittest_main
       
    19 from cubicweb.devtools.testlib import CubicWebTC
       
    20 
       
    21 class PyViewsTC(CubicWebTC):
       
    22 
       
    23     def test_pyvaltable(self):
       
    24         with self.admin_access.web_request() as req:
       
    25             view = self.vreg['views'].select('pyvaltable', req,
       
    26                                              pyvalue=[[1, 'a'], [2, 'b']])
       
    27             content = view.render(pyvalue=[[1, 'a'], [2, 'b']],
       
    28                                   headers=['num', 'char'])
       
    29             self.assertEqual(content.strip(), '''<table class="listing"><tbody>\
       
    30 <tr class="even" onmouseout="$(this).removeClass(&quot;highlighted&quot;)" onmouseover="$(this).addClass(&quot;highlighted&quot;);"><td >1</td><td >a</td></tr>
       
    31 <tr class="odd" onmouseout="$(this).removeClass(&quot;highlighted&quot;)" onmouseover="$(this).addClass(&quot;highlighted&quot;);"><td >2</td><td >b</td></tr>
       
    32 </tbody></table>''')
       
    33 
       
    34     def test_pyvallist(self):
       
    35         with self.admin_access.web_request() as req:
       
    36             view = self.vreg['views'].select('pyvallist', req,
       
    37                                              pyvalue=[1, 'a'])
       
    38             content = view.render(pyvalue=[1, 'a'])
       
    39             self.assertEqual(content.strip(), '''<ul>
       
    40 <li>1</li>
       
    41 <li>a</li>
       
    42 </ul>''')
       
    43 
       
    44 if __name__ == '__main__':
       
    45     unittest_main()