web/test/test_views.py
changeset 9836 71045bb09136
parent 8961 cc1a0aad580c
child 10282 f96093ad32e4
equal deleted inserted replaced
9835:5ad968dd9d51 9836:71045bb09136
     1 # copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
    14 # details.
    14 # details.
    15 #
    15 #
    16 # You should have received a copy of the GNU Lesser General Public License along
    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/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """automatic tests"""
    18 """automatic tests"""
    19 from cubicweb.devtools import htmlparser
    19 from cubicweb.devtools.testlib import AutoPopulateTest, AutomaticWebTest
    20 from cubicweb.devtools.testlib import CubicWebTC, AutoPopulateTest, AutomaticWebTest
       
    21 from cubicweb.view import AnyRsetView
    20 from cubicweb.view import AnyRsetView
    22 
    21 
    23 class AutomaticWebTest(AutomaticWebTest):
    22 class AutomaticWebTest(AutomaticWebTest):
    24     application_rql = [
    23     application_rql = [
    25         'Any L,F WHERE E is CWUser, E login L, E firstname F',
    24         'Any L,F WHERE E is CWUser, E login L, E firstname F',
    26         'Any L,F,E WHERE E is CWUser, E login L, E firstname F',
    25         'Any L,F,E WHERE E is CWUser, E login L, E firstname F',
    27         'Any COUNT(X) WHERE X is CWUser',
    26         'Any COUNT(X) WHERE X is CWUser',
    28         ]
    27         ]
    29 
    28 
    30     def to_test_etypes(self):
    29     def to_test_etypes(self):
    31         # We do not really want to test cube views here. So we can drop testing 
    30         # We do not really want to test cube views here. So we can drop testing
    32         # some EntityType. The two Blog types below require the sioc cube that 
    31         # some EntityType. The two Blog types below require the sioc cube that
    33         # we do not want to add as a dependency.
    32         # we do not want to add as a dependency.
    34         etypes = super(AutomaticWebTest, self).to_test_etypes()
    33         etypes = super(AutomaticWebTest, self).to_test_etypes()
    35         etypes -= set(('Blog', 'BlogEntry'))
    34         etypes -= set(('Blog', 'BlogEntry'))
    36         return etypes
    35         return etypes
    37 
    36 
    48 
    47 
    49     def test_regr_copy_view(self):
    48     def test_regr_copy_view(self):
    50         """regression test: make sure we can ask a copy of a
    49         """regression test: make sure we can ask a copy of a
    51         composite entity
    50         composite entity
    52         """
    51         """
    53         rset = self.execute('CWUser X WHERE X login "admin"')
    52         with self.admin_access.web_request() as req:
    54         self.view('copy', rset)
    53             rset = req.execute('CWUser X WHERE X login "admin"')
       
    54             self.view('copy', rset, req=req)
    55 
    55 
    56     def test_sortable_js_added(self):
    56     def test_sortable_js_added(self):
    57         rset = self.execute('CWUser X')
    57         with self.admin_access.web_request() as req:
    58         # sortable.js should not be included by default
    58             rset = req.execute('CWUser X')
    59         self.assertFalse('jquery.tablesorter.js' in self.view('oneline', rset))
    59             # sortable.js should not be included by default
    60         # but should be included by the tableview
    60             self.assertFalse('jquery.tablesorter.js' in self.view('oneline', rset, req=req))
    61         rset = self.execute('Any P,F,S LIMIT 1 WHERE P is CWUser, P firstname F, P surname S')
    61             # but should be included by the tableview
    62         self.assertIn('jquery.tablesorter.js', self.view('table', rset).source)
    62             rset = req.execute('Any P,F,S LIMIT 1 WHERE P is CWUser, P firstname F, P surname S')
       
    63             self.assertIn('jquery.tablesorter.js', self.view('table', rset, req=req).source)
    63 
    64 
    64     def test_js_added_only_once(self):
    65     def test_js_added_only_once(self):
    65         self.vreg._loadedmods[__name__] = {}
    66         with self.admin_access.web_request() as req:
    66         self.vreg.register(SomeView)
    67             self.vreg._loadedmods[__name__] = {}
    67         rset = self.execute('CWUser X')
    68             self.vreg.register(SomeView)
    68         source = self.view('someview', rset).source
    69             rset = req.execute('CWUser X')
    69         self.assertEqual(source.count('spam.js'), 1)
    70             source = self.view('someview', rset, req=req).source
       
    71             self.assertEqual(source.count('spam.js'), 1)
    70 
    72 
    71     def test_unrelateddivs(self):
    73     def test_unrelateddivs(self):
    72         rset = self.execute('Any X WHERE X is CWUser, X login "admin"')
    74         with self.admin_access.client_cnx() as cnx:
    73         group = self.request().create_entity('CWGroup', name=u'R&D')
    75             group = cnx.create_entity('CWGroup', name=u'R&D')
    74         req = self.request(relation='in_group_subject')
    76             cnx.commit()
    75         self.view('unrelateddivs', rset, req)
    77         with self.admin_access.web_request(relation='in_group_subject') as req:
       
    78             rset = req.execute('Any X WHERE X is CWUser, X login "admin"')
       
    79             self.view('unrelateddivs', rset, req=req)
    76 
    80 
    77 
    81 
    78 if __name__ == '__main__':
    82 if __name__ == '__main__':
    79     from logilab.common.testlib import unittest_main
    83     from logilab.common.testlib import unittest_main
    80     unittest_main()
    84     unittest_main()