--- a/devtools/testlib.py Wed Jun 04 12:41:21 2014 +0200
+++ b/devtools/testlib.py Wed Jul 02 14:42:24 2014 +0200
@@ -823,12 +823,13 @@
def list_startup_views(self):
"""returns the list of startup views"""
- req = self.request()
- for view in self.vreg['views'].possible_views(req, None):
- if view.category == 'startupview':
- yield view.__regid__
- else:
- not_selected(self.vreg, view)
+ with self.admin_access.web_request() as req:
+ for view in self.vreg['views'].possible_views(req, None):
+ if view.category == 'startupview':
+ yield view.__regid__
+ else:
+ not_selected(self.vreg, view)
+
# web ui testing utilities #################################################
@@ -1297,38 +1298,40 @@
def iter_individual_rsets(self, etypes=None, limit=None):
etypes = etypes or self.to_test_etypes()
- for etype in etypes:
- if limit:
- rql = 'Any X LIMIT %s WHERE X is %s' % (limit, etype)
- else:
- rql = 'Any X WHERE X is %s' % etype
- rset = self.execute(rql)
- for row in xrange(len(rset)):
- if limit and row > limit:
- break
- # XXX iirk
- rset2 = rset.limit(limit=1, offset=row)
- yield rset2
+ with self.admin_access.web_request() as req:
+ for etype in etypes:
+ if limit:
+ rql = 'Any X LIMIT %s WHERE X is %s' % (limit, etype)
+ else:
+ rql = 'Any X WHERE X is %s' % etype
+ rset = req.execute(rql)
+ for row in xrange(len(rset)):
+ if limit and row > limit:
+ break
+ # XXX iirk
+ rset2 = rset.limit(limit=1, offset=row)
+ yield rset2
def iter_automatic_rsets(self, limit=10):
"""generates basic resultsets for each entity type"""
etypes = self.to_test_etypes()
if not etypes:
return
- for etype in etypes:
- yield self.execute('Any X LIMIT %s WHERE X is %s' % (limit, etype))
- etype1 = etypes.pop()
- try:
- etype2 = etypes.pop()
- except KeyError:
- etype2 = etype1
- # test a mixed query (DISTINCT/GROUP to avoid getting duplicate
- # X which make muledit view failing for instance (html validation fails
- # because of some duplicate "id" attributes)
- yield self.execute('DISTINCT Any X, MAX(Y) GROUPBY X WHERE X is %s, Y is %s' % (etype1, etype2))
- # test some application-specific queries if defined
- for rql in self.application_rql:
- yield self.execute(rql)
+ with self.admin_access.web_request() as req:
+ for etype in etypes:
+ yield req.execute('Any X LIMIT %s WHERE X is %s' % (limit, etype))
+ etype1 = etypes.pop()
+ try:
+ etype2 = etypes.pop()
+ except KeyError:
+ etype2 = etype1
+ # test a mixed query (DISTINCT/GROUP to avoid getting duplicate
+ # X which make muledit view failing for instance (html validation fails
+ # because of some duplicate "id" attributes)
+ yield req.execute('DISTINCT Any X, MAX(Y) GROUPBY X WHERE X is %s, Y is %s' % (etype1, etype2))
+ # test some application-specific queries if defined
+ for rql in self.application_rql:
+ yield req.execute(rql)
def _test_everything_for(self, rset):
"""this method tries to find everything that can be tested
@@ -1390,8 +1393,8 @@
## startup views
def test_startup_views(self):
for vid in self.list_startup_views():
- req = self.request()
- yield self.view, vid, None, req
+ with self.admin_access.web_request() as req:
+ yield self.view, vid, None, req
# registry instrumentization ###################################################
--- a/web/test/test_views.py Wed Jun 04 12:41:21 2014 +0200
+++ b/web/test/test_views.py Wed Jul 02 14:42:24 2014 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of CubicWeb.
@@ -16,8 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License along
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
"""automatic tests"""
-from cubicweb.devtools import htmlparser
-from cubicweb.devtools.testlib import CubicWebTC, AutoPopulateTest, AutomaticWebTest
+from cubicweb.devtools.testlib import AutoPopulateTest, AutomaticWebTest
from cubicweb.view import AnyRsetView
class AutomaticWebTest(AutomaticWebTest):
@@ -28,8 +27,8 @@
]
def to_test_etypes(self):
- # We do not really want to test cube views here. So we can drop testing
- # some EntityType. The two Blog types below require the sioc cube that
+ # We do not really want to test cube views here. So we can drop testing
+ # some EntityType. The two Blog types below require the sioc cube that
# we do not want to add as a dependency.
etypes = super(AutomaticWebTest, self).to_test_etypes()
etypes -= set(('Blog', 'BlogEntry'))
@@ -50,29 +49,34 @@
"""regression test: make sure we can ask a copy of a
composite entity
"""
- rset = self.execute('CWUser X WHERE X login "admin"')
- self.view('copy', rset)
+ with self.admin_access.web_request() as req:
+ rset = req.execute('CWUser X WHERE X login "admin"')
+ self.view('copy', rset, req=req)
def test_sortable_js_added(self):
- rset = self.execute('CWUser X')
- # sortable.js should not be included by default
- self.assertFalse('jquery.tablesorter.js' in self.view('oneline', rset))
- # but should be included by the tableview
- rset = self.execute('Any P,F,S LIMIT 1 WHERE P is CWUser, P firstname F, P surname S')
- self.assertIn('jquery.tablesorter.js', self.view('table', rset).source)
+ with self.admin_access.web_request() as req:
+ rset = req.execute('CWUser X')
+ # sortable.js should not be included by default
+ self.assertFalse('jquery.tablesorter.js' in self.view('oneline', rset, req=req))
+ # but should be included by the tableview
+ rset = req.execute('Any P,F,S LIMIT 1 WHERE P is CWUser, P firstname F, P surname S')
+ self.assertIn('jquery.tablesorter.js', self.view('table', rset, req=req).source)
def test_js_added_only_once(self):
- self.vreg._loadedmods[__name__] = {}
- self.vreg.register(SomeView)
- rset = self.execute('CWUser X')
- source = self.view('someview', rset).source
- self.assertEqual(source.count('spam.js'), 1)
+ with self.admin_access.web_request() as req:
+ self.vreg._loadedmods[__name__] = {}
+ self.vreg.register(SomeView)
+ rset = req.execute('CWUser X')
+ source = self.view('someview', rset, req=req).source
+ self.assertEqual(source.count('spam.js'), 1)
def test_unrelateddivs(self):
- rset = self.execute('Any X WHERE X is CWUser, X login "admin"')
- group = self.request().create_entity('CWGroup', name=u'R&D')
- req = self.request(relation='in_group_subject')
- self.view('unrelateddivs', rset, req)
+ with self.admin_access.client_cnx() as cnx:
+ group = cnx.create_entity('CWGroup', name=u'R&D')
+ cnx.commit()
+ with self.admin_access.web_request(relation='in_group_subject') as req:
+ rset = req.execute('Any X WHERE X is CWUser, X login "admin"')
+ self.view('unrelateddivs', rset, req=req)
if __name__ == '__main__':