[webtests/views_selectors] use the new connection api
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Mon, 02 Jun 2014 18:04:35 +0200
changeset 9811 25ba231d2910
parent 9810 51ebb1b925cb
child 9812 122c0b6a82a3
[webtests/views_selectors] use the new connection api
web/test/unittest_viewselector.py
--- a/web/test/unittest_viewselector.py	Mon Jun 02 17:21:52 2014 +0200
+++ b/web/test/unittest_viewselector.py	Mon Jun 02 18:04:35 2014 +0200
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# 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.
@@ -21,16 +21,17 @@
 from logilab.common.testlib import unittest_main
 
 from cubicweb.devtools.testlib import CubicWebTC
-from cubicweb import CW_SOFTWARE_ROOT as BASE, Binary, UnknownProperty
-from cubicweb.predicates import (match_user_groups, is_instance,
+from cubicweb import Binary, UnknownProperty
+from cubicweb.predicates import (is_instance,
                                  specified_etype_implements, rql_condition)
 from cubicweb.web import NoSelectableObject
 from cubicweb.web.action import Action
-from cubicweb.web.views import (
-    primary, baseviews, tableview, editforms, calendar, management, embedding,
-    actions, startup, cwuser, schema, xbel, vcard, owl, treeview, idownloadable,
-    wdoc, debug, cwuser, cwproperties, cwsources, workflow, xmlrss, rdf,
-    csvexport, json, undohistory)
+
+from cubicweb.web.views import (primary, baseviews, tableview,
+                                editforms, management, actions, startup, cwuser, schema, xbel,
+                                vcard, owl, treeview, idownloadable, wdoc, debug, cwuser,
+                                cwproperties, cwsources, xmlrss, rdf, csvexport, json,
+                                undohistory)
 
 from cubes.folder import views as folderviews
 
@@ -55,11 +56,12 @@
 class ViewSelectorTC(CubicWebTC):
 
     def setup_database(self):
-        req = self.request()
-        req.create_entity('BlogEntry', title=u"une news !", content=u"cubicweb c'est beau")
-        req.create_entity('Bookmark', title=u"un signet !", path=u"view?vid=index")
-        req.create_entity('EmailAddress', address=u"devel@logilab.fr", alias=u'devel')
-        req.create_entity('Tag', name=u'x')
+        with self.admin_access.repo_cnx() as cnx:
+            cnx.create_entity('BlogEntry', title=u"une news !", content=u"cubicweb c'est beau")
+            cnx.create_entity('Bookmark', title=u"un signet !", path=u"view?vid=index")
+            cnx.create_entity('EmailAddress', address=u"devel@logilab.fr", alias=u'devel')
+            cnx.create_entity('Tag', name=u'x')
+            cnx.commit()
 
 class VRegistryTC(ViewSelectorTC):
     """test the view selector"""
@@ -85,389 +87,377 @@
         assert self.vreg['views']['propertiesform']
 
     def test_possible_views_none_rset(self):
-        req = self.request()
-        self.assertListEqual(self.pviews(req, None),
-                             [('cw.sources-management', cwsources.CWSourcesManagementView),
-                              ('cw.users-and-groups-management', cwuser.UsersAndGroupsManagementView),
-                              ('gc', debug.GCView),
-                              ('index', startup.IndexView),
-                              ('info', debug.ProcessInformationView),
-                              ('manage', startup.ManageView),
-                              ('owl', owl.OWLView),
-                              ('propertiesform', cwproperties.CWPropertiesForm),
-                              ('registry', debug.RegistryView),
-                              ('schema', schema.SchemaView),
-                              ('siteinfo', debug.SiteInfoView),
-                              ('systempropertiesform', cwproperties.SystemCWPropertiesForm),
-                              ('tree', folderviews.FolderTreeView),
-                              ('undohistory', undohistory.UndoHistoryView),
-                              ])
+        with self.admin_access.web_request() as req:
+            self.assertListEqual(self.pviews(req, None),
+                                 [('cw.sources-management', cwsources.CWSourcesManagementView),
+                                  ('cw.users-and-groups-management', cwuser.UsersAndGroupsManagementView),
+                                  ('gc', debug.GCView),
+                                  ('index', startup.IndexView),
+                                  ('info', debug.ProcessInformationView),
+                                  ('manage', startup.ManageView),
+                                  ('owl', owl.OWLView),
+                                  ('propertiesform', cwproperties.CWPropertiesForm),
+                                  ('registry', debug.RegistryView),
+                                  ('schema', schema.SchemaView),
+                                  ('siteinfo', debug.SiteInfoView),
+                                  ('systempropertiesform', cwproperties.SystemCWPropertiesForm),
+                                  ('tree', folderviews.FolderTreeView),
+                                  ('undohistory', undohistory.UndoHistoryView)])
 
     def test_possible_views_noresult(self):
-        req = self.request()
-        rset = req.execute('Any X WHERE X eid 999999')
-        self.assertListEqual([('jsonexport', json.JsonRsetView)],
-                             self.pviews(req, rset))
+        with self.admin_access.web_request() as req:
+            rset = req.execute('Any X WHERE X eid 999999')
+            self.assertListEqual([('jsonexport', json.JsonRsetView)],
+                                 self.pviews(req, rset))
 
     def test_possible_views_one_egroup(self):
-        req = self.request()
-        rset = req.execute('CWGroup X WHERE X name "managers"')
-        self.assertListEqual(self.pviews(req, rset),
-                             [('csvexport', csvexport.CSVRsetView),
-                              ('ecsvexport', csvexport.CSVEntityView),
-                              ('ejsonexport', json.JsonEntityView),
-                              ('filetree', treeview.FileTreeView),
-                              ('jsonexport', json.JsonRsetView),
-                              ('list', baseviews.ListView),
-                              ('oneline', baseviews.OneLineView),
-                              ('owlabox', owl.OWLABOXView),
-                              ('primary', cwuser.CWGroupPrimaryView)] + RDFVIEWS + [
-                              ('rsetxml', xmlrss.XMLRsetView),
-                              ('rss', xmlrss.RSSView),
-                              ('sameetypelist', baseviews.SameETypeListView),
-                              ('security', management.SecurityManagementView),
-                              ('table', tableview.RsetTableView),
-                              ('text', baseviews.TextView),
-                              ('treeview', treeview.TreeView),
-                              ('xbel', xbel.XbelView),
-                              ('xml', xmlrss.XMLView),
-                              ])
+        with self.admin_access.web_request() as req:
+            rset = req.execute('CWGroup X WHERE X name "managers"')
+            self.assertListEqual(self.pviews(req, rset),
+                                 [('csvexport', csvexport.CSVRsetView),
+                                  ('ecsvexport', csvexport.CSVEntityView),
+                                  ('ejsonexport', json.JsonEntityView),
+                                  ('filetree', treeview.FileTreeView),
+                                  ('jsonexport', json.JsonRsetView),
+                                  ('list', baseviews.ListView),
+                                  ('oneline', baseviews.OneLineView),
+                                  ('owlabox', owl.OWLABOXView),
+                                  ('primary', cwuser.CWGroupPrimaryView)] + \
+                                 RDFVIEWS + \
+                                 [('rsetxml', xmlrss.XMLRsetView),
+                                  ('rss', xmlrss.RSSView),
+                                  ('sameetypelist', baseviews.SameETypeListView),
+                                  ('security', management.SecurityManagementView),
+                                  ('table', tableview.RsetTableView),
+                                  ('text', baseviews.TextView),
+                                  ('treeview', treeview.TreeView),
+                                  ('xbel', xbel.XbelView),
+                                  ('xml', xmlrss.XMLView)])
 
     def test_possible_views_multiple_egroups(self):
-        req = self.request()
-        rset = req.execute('CWGroup X')
-        self.assertListEqual(self.pviews(req, rset),
-                             [('csvexport', csvexport.CSVRsetView),
-                              ('ecsvexport', csvexport.CSVEntityView),
-                              ('ejsonexport', json.JsonEntityView),
-                              ('filetree', treeview.FileTreeView),
-                              ('jsonexport', json.JsonRsetView),
-                              ('list', baseviews.ListView),
-                              ('oneline', baseviews.OneLineView),
-                              ('owlabox', owl.OWLABOXView),
-                              ('primary', cwuser.CWGroupPrimaryView)] + RDFVIEWS + [
-                              ('rsetxml', xmlrss.XMLRsetView),
-                              ('rss', xmlrss.RSSView),
-                              ('sameetypelist', baseviews.SameETypeListView),
-                              ('security', management.SecurityManagementView),
-                              ('table', tableview.RsetTableView),
-                              ('text', baseviews.TextView),
-                              ('treeview', treeview.TreeView),
-                              ('xbel', xbel.XbelView),
-                              ('xml', xmlrss.XMLView),
-                              ])
+        with self.admin_access.web_request() as req:
+            rset = req.execute('CWGroup X')
+            self.assertListEqual(self.pviews(req, rset),
+                                 [('csvexport', csvexport.CSVRsetView),
+                                  ('ecsvexport', csvexport.CSVEntityView),
+                                  ('ejsonexport', json.JsonEntityView),
+                                  ('filetree', treeview.FileTreeView),
+                                  ('jsonexport', json.JsonRsetView),
+                                  ('list', baseviews.ListView),
+                                  ('oneline', baseviews.OneLineView),
+                                  ('owlabox', owl.OWLABOXView),
+                                  ('primary', cwuser.CWGroupPrimaryView)] + RDFVIEWS + [
+                                  ('rsetxml', xmlrss.XMLRsetView),
+                                  ('rss', xmlrss.RSSView),
+                                  ('sameetypelist', baseviews.SameETypeListView),
+                                  ('security', management.SecurityManagementView),
+                                  ('table', tableview.RsetTableView),
+                                  ('text', baseviews.TextView),
+                                  ('treeview', treeview.TreeView),
+                                  ('xbel', xbel.XbelView),
+                                  ('xml', xmlrss.XMLView),
+                                  ])
 
     def test_propertiesform_admin(self):
         assert self.vreg['views']['propertiesform']
-        req1 = self.request()
-        req2 = self.request()
-        rset1 = req1.execute('CWUser X WHERE X login "admin"')
-        rset2 = req2.execute('CWUser X WHERE X login "anon"')
-        self.assertTrue(self.vreg['views'].select('propertiesform', req1, rset=None))
-        self.assertTrue(self.vreg['views'].select('propertiesform', req1, rset=rset1))
-        self.assertTrue(self.vreg['views'].select('propertiesform', req2, rset=rset2))
+        with self.admin_access.web_request() as req:
+            rset1 = req.execute('CWUser X WHERE X login "admin"')
+            self.assertTrue(self.vreg['views'].select('propertiesform', req, rset=None))
+            self.assertTrue(self.vreg['views'].select('propertiesform', req, rset=rset1))
+            rset2 = req.execute('CWUser X WHERE X login "anon"')
+            self.assertTrue(self.vreg['views'].select('propertiesform', req, rset=rset2))
 
     def test_propertiesform_anon(self):
-        self.login('anon')
-        req1 = self.request()
-        req2 = self.request()
-        rset1 = req1.execute('CWUser X WHERE X login "admin"')
-        rset2 = req2.execute('CWUser X WHERE X login "anon"')
-        self.assertRaises(NoSelectableObject, self.vreg['views'].select, 'propertiesform', req1, rset=None)
-        self.assertRaises(NoSelectableObject, self.vreg['views'].select, 'propertiesform', req1, rset=rset1)
-        self.assertRaises(NoSelectableObject, self.vreg['views'].select, 'propertiesform', req1, rset=rset2)
+        with self.new_access('anon').web_request() as req:
+            rset1 = req.execute('CWUser X WHERE X login "admin"')
+            self.assertRaises(NoSelectableObject, self.vreg['views'].select, 'propertiesform', req, rset=None)
+            self.assertRaises(NoSelectableObject, self.vreg['views'].select, 'propertiesform', req, rset=rset1)
+            rset2 = req.execute('CWUser X WHERE X login "anon"')
+            self.assertRaises(NoSelectableObject, self.vreg['views'].select, 'propertiesform', req, rset=rset2)
 
     def test_propertiesform_jdoe(self):
-        self.create_user(self.request(), 'jdoe')
-        self.login('jdoe')
-        req1 = self.request()
-        req2 = self.request()
-        rset1 = req1.execute('CWUser X WHERE X login "admin"')
-        rset2 = req2.execute('CWUser X WHERE X login "jdoe"')
-        self.assertTrue(self.vreg['views'].select('propertiesform', req1, rset=None))
-        self.assertRaises(NoSelectableObject, self.vreg['views'].select, 'propertiesform', req1, rset=rset1)
-        self.assertTrue(self.vreg['views'].select('propertiesform', req2, rset=rset2))
+        with self.admin_access.repo_cnx() as cnx:
+            self.create_user(cnx, 'jdoe')
+            cnx.commit()
+        with self.new_access('jdoe').web_request() as req:
+            rset1 = req.execute('CWUser X WHERE X login "admin"')
+            rset2 = req.execute('CWUser X WHERE X login "jdoe"')
+            self.assertTrue(self.vreg['views'].select('propertiesform', req, rset=None))
+            self.assertRaises(NoSelectableObject, self.vreg['views'].select, 'propertiesform', req, rset=rset1)
+            self.assertTrue(self.vreg['views'].select('propertiesform', req, rset=rset2))
 
     def test_possible_views_multiple_different_types(self):
-        req = self.request()
-        rset = req.execute('Any X')
-        self.assertListEqual(self.pviews(req, rset),
-                             [('csvexport', csvexport.CSVRsetView),
-                              ('ecsvexport', csvexport.CSVEntityView),
-                              ('ejsonexport', json.JsonEntityView),
-                              ('filetree', treeview.FileTreeView),
-                              ('jsonexport', json.JsonRsetView),
-                              ('list', baseviews.ListView),
-                              ('oneline', baseviews.OneLineView),
-                              ('owlabox', owl.OWLABOXView),
-                              ('primary', primary.PrimaryView),] + RDFVIEWS + [
-                              ('rsetxml', xmlrss.XMLRsetView),
-                              ('rss', xmlrss.RSSView),
-                              ('security', management.SecurityManagementView),
-                              ('table', tableview.RsetTableView),
-                              ('text', baseviews.TextView),
-                              ('treeview', treeview.TreeView),
-                              ('xbel', xbel.XbelView),
-                              ('xml', xmlrss.XMLView),
-                              ])
+        with self.admin_access.web_request() as req:
+            rset = req.execute('Any X')
+            self.assertListEqual(self.pviews(req, rset),
+                                 [('csvexport', csvexport.CSVRsetView),
+                                  ('ecsvexport', csvexport.CSVEntityView),
+                                  ('ejsonexport', json.JsonEntityView),
+                                  ('filetree', treeview.FileTreeView),
+                                  ('jsonexport', json.JsonRsetView),
+                                  ('list', baseviews.ListView),
+                                  ('oneline', baseviews.OneLineView),
+                                  ('owlabox', owl.OWLABOXView),
+                                  ('primary', primary.PrimaryView),] + RDFVIEWS + [
+                                  ('rsetxml', xmlrss.XMLRsetView),
+                                  ('rss', xmlrss.RSSView),
+                                  ('security', management.SecurityManagementView),
+                                  ('table', tableview.RsetTableView),
+                                  ('text', baseviews.TextView),
+                                  ('treeview', treeview.TreeView),
+                                  ('xbel', xbel.XbelView),
+                                  ('xml', xmlrss.XMLView),
+                                  ])
 
     def test_possible_views_any_rset(self):
-        req = self.request()
-        rset = req.execute('Any N, X WHERE X in_group Y, Y name N')
-        self.assertListEqual(self.pviews(req, rset),
-                             [('csvexport', csvexport.CSVRsetView),
-                              ('jsonexport', json.JsonRsetView),
-                              ('rsetxml', xmlrss.XMLRsetView),
-                              ('table', tableview.RsetTableView),
-                              ])
+        with self.admin_access.web_request() as req:
+            rset = req.execute('Any N, X WHERE X in_group Y, Y name N')
+            self.assertListEqual(self.pviews(req, rset),
+                                 [('csvexport', csvexport.CSVRsetView),
+                                  ('jsonexport', json.JsonRsetView),
+                                  ('rsetxml', xmlrss.XMLRsetView),
+                                  ('table', tableview.RsetTableView),
+                                  ])
 
     def test_possible_views_multiple_eusers(self):
-        req = self.request()
-        rset = req.execute('CWUser X')
-        self.assertListEqual(self.pviews(req, rset),
-                             [('csvexport', csvexport.CSVRsetView),
-                              ('ecsvexport', csvexport.CSVEntityView),
-                              ('ejsonexport', json.JsonEntityView),
-                              ('filetree', treeview.FileTreeView),
-                              ('foaf', cwuser.FoafView),
-                              ('jsonexport', json.JsonRsetView),
-                              ('list', baseviews.ListView),
-                              ('oneline', baseviews.OneLineView),
-                              ('owlabox', owl.OWLABOXView),
-                              ('primary', primary.PrimaryView)] + RDFVIEWS + [
-                              ('rsetxml', xmlrss.XMLRsetView),
-                              ('rss', xmlrss.RSSView),
-                              ('sameetypelist', baseviews.SameETypeListView),
-                              ('security', management.SecurityManagementView),
-                              ('table', tableview.RsetTableView),
-                              ('text', baseviews.TextView),
-                              ('treeview', treeview.TreeView),
-                              ('vcard', vcard.VCardCWUserView),
-                              ('xbel', xbel.XbelView),
-                              ('xml', xmlrss.XMLView),
-                              ])
+        with self.admin_access.web_request() as req:
+            rset = req.execute('CWUser X')
+            self.assertListEqual(self.pviews(req, rset),
+                                 [('csvexport', csvexport.CSVRsetView),
+                                  ('ecsvexport', csvexport.CSVEntityView),
+                                  ('ejsonexport', json.JsonEntityView),
+                                  ('filetree', treeview.FileTreeView),
+                                  ('foaf', cwuser.FoafView),
+                                  ('jsonexport', json.JsonRsetView),
+                                  ('list', baseviews.ListView),
+                                  ('oneline', baseviews.OneLineView),
+                                  ('owlabox', owl.OWLABOXView),
+                                  ('primary', primary.PrimaryView)] + RDFVIEWS + [
+                                  ('rsetxml', xmlrss.XMLRsetView),
+                                  ('rss', xmlrss.RSSView),
+                                  ('sameetypelist', baseviews.SameETypeListView),
+                                  ('security', management.SecurityManagementView),
+                                  ('table', tableview.RsetTableView),
+                                  ('text', baseviews.TextView),
+                                  ('treeview', treeview.TreeView),
+                                  ('vcard', vcard.VCardCWUserView),
+                                  ('xbel', xbel.XbelView),
+                                  ('xml', xmlrss.XMLView),
+                                  ])
 
     def test_possible_actions_none_rset(self):
-        req = self.request()
-        self.assertDictEqual(self.pactionsdict(req, None, skipcategories=()),
-                             {'useractions': USERACTIONS,
-                              'siteactions': SITEACTIONS,
-                              'manage': MANAGEACTIONS,
-                              'footer': FOOTERACTIONS,
+        with self.admin_access.web_request() as req:
+            self.assertDictEqual(self.pactionsdict(req, None, skipcategories=()),
+                                 {'useractions': USERACTIONS,
+                                  'siteactions': SITEACTIONS,
+                                  'manage': MANAGEACTIONS,
+                                  'footer': FOOTERACTIONS})
 
-                              })
     def test_possible_actions_no_entity(self):
-        req = self.request()
-        rset = req.execute('Any X WHERE X eid 999999')
-        self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
-                             {'useractions': USERACTIONS,
-                              'siteactions': SITEACTIONS,
-                              'manage': MANAGEACTIONS,
-                              'footer': FOOTERACTIONS,
-                              })
+        with self.admin_access.web_request() as req:
+            rset = req.execute('Any X WHERE X eid 999999')
+            self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
+                                 {'useractions': USERACTIONS,
+                                  'siteactions': SITEACTIONS,
+                                  'manage': MANAGEACTIONS,
+                                  'footer': FOOTERACTIONS,
+                                  })
 
     def test_possible_actions_same_type_entities(self):
-        req = self.request()
-        rset = req.execute('CWGroup X')
-        self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
-                             {'useractions': USERACTIONS,
-                              'siteactions': SITEACTIONS,
-                              'manage': MANAGEACTIONS,
-                              'footer': FOOTERACTIONS,
-                              'mainactions': [actions.MultipleEditAction],
-                              'moreactions': [actions.DeleteAction,
-                                              actions.AddNewAction],
-                              })
+        with self.admin_access.web_request() as req:
+            rset = req.execute('CWGroup X')
+            self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
+                                 {'useractions': USERACTIONS,
+                                  'siteactions': SITEACTIONS,
+                                  'manage': MANAGEACTIONS,
+                                  'footer': FOOTERACTIONS,
+                                  'mainactions': [actions.MultipleEditAction],
+                                  'moreactions': [actions.DeleteAction,
+                                                  actions.AddNewAction]})
 
     def test_possible_actions_different_types_entities(self):
-        req = self.request()
-        rset = req.execute('Any X')
-        self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
-                             {'useractions': USERACTIONS,
-                              'siteactions': SITEACTIONS,
-                              'manage': MANAGEACTIONS,
-                              'footer': FOOTERACTIONS,
-                              'moreactions': [actions.DeleteAction],
-                              })
+        with self.admin_access.web_request() as req:
+            rset = req.execute('Any X')
+            self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
+                                 {'useractions': USERACTIONS,
+                                  'siteactions': SITEACTIONS,
+                                  'manage': MANAGEACTIONS,
+                                  'footer': FOOTERACTIONS,
+                                  'moreactions': [actions.DeleteAction],
+                                  })
 
     def test_possible_actions_final_entities(self):
-        req = self.request()
-        rset = req.execute('Any N, X WHERE X in_group Y, Y name N')
-        self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
-                             {'useractions': USERACTIONS,
-                              'siteactions': SITEACTIONS,
-                              'manage': MANAGEACTIONS,
-                              'footer': FOOTERACTIONS,
-                              })
+        with self.admin_access.web_request() as req:
+            rset = req.execute('Any N, X WHERE X in_group Y, Y name N')
+            self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
+                                 {'useractions': USERACTIONS,
+                                  'siteactions': SITEACTIONS,
+                                  'manage': MANAGEACTIONS,
+                                  'footer': FOOTERACTIONS,
+                                  })
 
     def test_possible_actions_eetype_cwuser_entity(self):
-        req = self.request()
-        rset = req.execute('CWEType X WHERE X name "CWUser"')
-        self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
-                             {'useractions': USERACTIONS,
-                              'siteactions': SITEACTIONS,
-                              'manage': MANAGEACTIONS,
-                              'footer': FOOTERACTIONS,
-                              'mainactions': [actions.ModifyAction,
-                                              actions.ViewSameCWEType],
-                              'moreactions': [actions.ManagePermissionsAction,
-                                              actions.AddRelatedActions,
-                                              actions.DeleteAction,
-                                              actions.CopyAction,
-                                              ],
-                              })
+        with self.admin_access.web_request() as req:
+            rset = req.execute('CWEType X WHERE X name "CWUser"')
+            self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
+                                 {'useractions': USERACTIONS,
+                                  'siteactions': SITEACTIONS,
+                                  'manage': MANAGEACTIONS,
+                                  'footer': FOOTERACTIONS,
+                                  'mainactions': [actions.ModifyAction,
+                                                  actions.ViewSameCWEType],
+                                  'moreactions': [actions.ManagePermissionsAction,
+                                                  actions.AddRelatedActions,
+                                                  actions.DeleteAction,
+                                                  actions.CopyAction,
+                                                  ],
+                                  })
 
 
     def test_select_creation_form(self):
         rset = None
-        req = self.request()
-        # creation form
-        req.form['etype'] = 'CWGroup'
-        self.assertIsInstance(self.vreg['views'].select('creation', req, rset=rset),
-                              editforms.CreationFormView)
-        del req.form['etype']
-        # custom creation form
-        class CWUserCreationForm(editforms.CreationFormView):
-            __select__ = specified_etype_implements('CWUser')
-        self.vreg._loadedmods[__name__] = {}
-        self.vreg.register(CWUserCreationForm)
-        req.form['etype'] = 'CWUser'
-        self.assertIsInstance(self.vreg['views'].select('creation', req, rset=rset),
-                              CWUserCreationForm)
+        with self.admin_access.web_request() as req:
+            # creation form
+            req.form['etype'] = 'CWGroup'
+            self.assertIsInstance(self.vreg['views'].select('creation', req, rset=rset),
+                                  editforms.CreationFormView)
+
+        with self.admin_access.web_request() as req:
+            # custom creation form
+            class CWUserCreationForm(editforms.CreationFormView):
+                __select__ = specified_etype_implements('CWUser')
+
+            self.vreg._loadedmods[__name__] = {}
+            self.vreg.register(CWUserCreationForm)
+            req.form['etype'] = 'CWUser'
+
+            self.assertIsInstance(self.vreg['views'].select('creation', req, rset=rset),
+                                  CWUserCreationForm)
 
     def test_select_view(self):
         # no entity
         rset = None
-        req = self.request()
-        self.assertIsInstance(self.vreg['views'].select('index', req, rset=rset),
-                             startup.IndexView)
-        self.assertRaises(NoSelectableObject,
-                             self.vreg['views'].select, 'primary', req, rset=rset)
-        self.assertRaises(NoSelectableObject,
-                             self.vreg['views'].select, 'table', req, rset=rset)
+        with self.admin_access.web_request() as req:
+            self.assertIsInstance(self.vreg['views'].select('index', req, rset=rset),
+                                  startup.IndexView)
+            self.assertRaises(NoSelectableObject,
+                              self.vreg['views'].select, 'primary', req, rset=rset)
+            self.assertRaises(NoSelectableObject,
+                              self.vreg['views'].select, 'table', req, rset=rset)
 
-        # no entity
-        req = self.request()
-        rset = req.execute('Any X WHERE X eid 999999')
-        self.assertRaises(NoSelectableObject,
+            # no entity
+            rset = req.execute('Any X WHERE X eid 999999')
+            self.assertRaises(NoSelectableObject,
                               self.vreg['views'].select, 'index', req, rset=rset)
-        self.assertRaises(NoSelectableObject,
+            self.assertRaises(NoSelectableObject,
                               self.vreg['views'].select, 'creation', req, rset=rset)
-        self.assertRaises(NoSelectableObject,
+            self.assertRaises(NoSelectableObject,
                               self.vreg['views'].select, 'primary', req, rset=rset)
-        self.assertRaises(NoSelectableObject,
-                             self.vreg['views'].select, 'table', req, rset=rset)
-        # one entity
-        req = self.request()
-        rset = req.execute('CWGroup X WHERE X name "managers"')
-        self.assertIsInstance(self.vreg['views'].select('primary', req, rset=rset),
-                             primary.PrimaryView)
-        self.assertIsInstance(self.vreg['views'].select('list', req, rset=rset),
-                             baseviews.ListView)
-        self.assertIsInstance(self.vreg['views'].select('edition', req, rset=rset),
-                             editforms.EditionFormView)
-        self.assertIsInstance(self.vreg['views'].select('table', req, rset=rset),
-                             tableview.RsetTableView)
-        self.assertRaises(NoSelectableObject,
+            self.assertRaises(NoSelectableObject,
+                              self.vreg['views'].select, 'table', req, rset=rset)
+            # one entity
+            rset = req.execute('CWGroup X WHERE X name "managers"')
+            self.assertIsInstance(self.vreg['views'].select('primary', req, rset=rset),
+                                  primary.PrimaryView)
+            self.assertIsInstance(self.vreg['views'].select('list', req, rset=rset),
+                                  baseviews.ListView)
+            self.assertIsInstance(self.vreg['views'].select('edition', req, rset=rset),
+                                  editforms.EditionFormView)
+            self.assertIsInstance(self.vreg['views'].select('table', req, rset=rset),
+                                  tableview.RsetTableView)
+            self.assertRaises(NoSelectableObject,
                               self.vreg['views'].select, 'creation', req, rset=rset)
-        self.assertRaises(NoSelectableObject,
+            self.assertRaises(NoSelectableObject,
                               self.vreg['views'].select, 'index', req, rset=rset)
-        # list of entities of the same type
-        req = self.request()
-        rset = req.execute('CWGroup X')
-        self.assertIsInstance(self.vreg['views'].select('primary', req, rset=rset),
-                             primary.PrimaryView)
-        self.assertIsInstance(self.vreg['views'].select('list', req, rset=rset),
-                             baseviews.ListView)
-        self.assertIsInstance(self.vreg['views'].select('table', req, rset=rset),
-                             tableview.RsetTableView)
-        self.assertRaises(NoSelectableObject,
+            # list of entities of the same type
+            rset = req.execute('CWGroup X')
+            self.assertIsInstance(self.vreg['views'].select('primary', req, rset=rset),
+                                  primary.PrimaryView)
+            self.assertIsInstance(self.vreg['views'].select('list', req, rset=rset),
+                                  baseviews.ListView)
+            self.assertIsInstance(self.vreg['views'].select('table', req, rset=rset),
+                                  tableview.RsetTableView)
+            self.assertRaises(NoSelectableObject,
                               self.vreg['views'].select, 'creation', req, rset=rset)
-        # list of entities of different types
-        req = self.request()
-        rset = req.execute('Any X')
-        self.assertIsInstance(self.vreg['views'].select('primary', req, rset=rset),
+            # list of entities of different types
+            rset = req.execute('Any X')
+            self.assertIsInstance(self.vreg['views'].select('primary', req, rset=rset),
                                   primary.PrimaryView)
-        self.assertIsInstance(self.vreg['views'].select('list', req, rset=rset),
+            self.assertIsInstance(self.vreg['views'].select('list', req, rset=rset),
                                   baseviews.ListView)
-        self.assertIsInstance(self.vreg['views'].select('table', req, rset=rset),
+            self.assertIsInstance(self.vreg['views'].select('table', req, rset=rset),
                                   tableview.RsetTableView)
-        self.assertRaises(NoSelectableObject,
-                             self.vreg['views'].select, 'creation', req, rset=rset)
-        self.assertRaises(NoSelectableObject,
+            self.assertRaises(NoSelectableObject,
+                              self.vreg['views'].select, 'creation', req, rset=rset)
+            self.assertRaises(NoSelectableObject,
                               self.vreg['views'].select, 'index', req, rset=rset)
-        # whatever
-        req = self.request()
-        rset = req.execute('Any N, X WHERE X in_group Y, Y name N')
-        self.assertIsInstance(self.vreg['views'].select('table', req, rset=rset),
+            # whatever
+            rset = req.execute('Any N, X WHERE X in_group Y, Y name N')
+            self.assertIsInstance(self.vreg['views'].select('table', req, rset=rset),
                                   tableview.RsetTableView)
-        self.assertRaises(NoSelectableObject,
+            self.assertRaises(NoSelectableObject,
                               self.vreg['views'].select, 'index', req, rset=rset)
-        self.assertRaises(NoSelectableObject,
+            self.assertRaises(NoSelectableObject,
                               self.vreg['views'].select, 'creation', req, rset=rset)
-        self.assertRaises(NoSelectableObject,
-                             self.vreg['views'].select, 'primary', req, rset=rset)
-        self.assertRaises(NoSelectableObject,
-                             self.vreg['views'].select, 'list', req, rset=rset)
-        self.assertRaises(NoSelectableObject,
-                             self.vreg['views'].select, 'edition', req, rset=rset)
-        # mixed query
-        req = self.request()
-        rset = req.execute('Any U,G WHERE U is CWUser, G is CWGroup')
-        self.assertRaises(NoSelectableObject,
+            self.assertRaises(NoSelectableObject,
+                              self.vreg['views'].select, 'primary', req, rset=rset)
+            self.assertRaises(NoSelectableObject,
+                              self.vreg['views'].select, 'list', req, rset=rset)
+            self.assertRaises(NoSelectableObject,
                               self.vreg['views'].select, 'edition', req, rset=rset)
-        self.assertRaises(NoSelectableObject,
+            # mixed query
+            rset = req.execute('Any U,G WHERE U is CWUser, G is CWGroup')
+            self.assertRaises(NoSelectableObject,
+                              self.vreg['views'].select, 'edition', req, rset=rset)
+            self.assertRaises(NoSelectableObject,
                               self.vreg['views'].select, 'creation', req, rset=rset)
-        self.assertIsInstance(self.vreg['views'].select('table', req, rset=rset),
-                              tableview.RsetTableView)
+            self.assertIsInstance(self.vreg['views'].select('table', req, rset=rset),
+                                  tableview.RsetTableView)
 
     def test_interface_selector(self):
-        image = self.request().create_entity('File', data_name=u'bim.png', data=Binary('bim'))
-        # image primary view priority
-        req = self.request()
-        rset = req.execute('File X WHERE X data_name "bim.png"')
-        self.assertIsInstance(self.vreg['views'].select('primary', req, rset=rset),
-                              idownloadable.IDownloadablePrimaryView)
+        with self.admin_access.web_request() as req:
+            req.create_entity('File', data_name=u'bim.png', data=Binary('bim'))
+            # image primary view priority
+            rset = req.execute('File X WHERE X data_name "bim.png"')
+            self.assertIsInstance(self.vreg['views'].select('primary', req, rset=rset),
+                                  idownloadable.IDownloadablePrimaryView)
 
 
     def test_score_entity_selector(self):
-        image = self.request().create_entity('File', data_name=u'bim.png', data=Binary('bim'))
-        # image/ehtml primary view priority
-        req = self.request()
-        rset = req.execute('File X WHERE X data_name "bim.png"')
-        self.assertIsInstance(self.vreg['views'].select('image', req, rset=rset),
-                              idownloadable.ImageView)
-        self.assertRaises(NoSelectableObject, self.vreg['views'].select, 'ehtml', req, rset=rset)
+        with self.admin_access.web_request() as req:
+            req.create_entity('File', data_name=u'bim.png', data=Binary('bim'))
+            # image/ehtml primary view priority
+            rset = req.execute('File X WHERE X data_name "bim.png"')
+            self.assertIsInstance(self.vreg['views'].select('image', req, rset=rset),
+                                  idownloadable.ImageView)
+            self.assertRaises(NoSelectableObject, self.vreg['views'].select, 'ehtml', req, rset=rset)
 
-        fileobj = self.request().create_entity('File', data_name=u'bim.html', data=Binary('<html>bam</html'))
-        # image/ehtml primary view priority
-        req = self.request()
-        rset = req.execute('File X WHERE X data_name "bim.html"')
-        self.assertIsInstance(self.vreg['views'].select('ehtml', req, rset=rset),
-                              idownloadable.EHTMLView)
-        self.assertRaises(NoSelectableObject, self.vreg['views'].select, 'image', req, rset=rset)
+            fileobj = req.create_entity('File', data_name=u'bim.html', data=Binary('<html>bam</html'))
+            # image/ehtml primary view priority
+            rset = req.execute('File X WHERE X data_name "bim.html"')
+            self.assertIsInstance(self.vreg['views'].select('ehtml', req, rset=rset),
+                                  idownloadable.EHTMLView)
+            self.assertRaises(NoSelectableObject, self.vreg['views'].select, 'image', req, rset=rset)
 
-        fileobj = self.request().create_entity('File', data_name=u'bim.txt', data=Binary('boum'))
-        # image/ehtml primary view priority
-        req = self.request()
-        rset = req.execute('File X WHERE X data_name "bim.txt"')
-        self.assertRaises(NoSelectableObject, self.vreg['views'].select, 'image', req, rset=rset)
-        self.assertRaises(NoSelectableObject, self.vreg['views'].select, 'ehtml', req, rset=rset)
+            fileobj = req.create_entity('File', data_name=u'bim.txt', data=Binary('boum'))
+            # image/ehtml primary view priority
+            rset = req.execute('File X WHERE X data_name "bim.txt"')
+            self.assertRaises(NoSelectableObject, self.vreg['views'].select, 'image', req, rset=rset)
+            self.assertRaises(NoSelectableObject, self.vreg['views'].select, 'ehtml', req, rset=rset)
 
 
     def _test_view(self, vid, rql, args):
-        if rql is None:
-            rset = None
-            req = self.request()
-        else:
-            req = self.request()
-            rset = req.execute(rql)
-        try:
-            obj = self.vreg['views'].select(vid, req, rset=rset, **args)
-            return obj.render(**args)
-        except Exception:
-            print vid, rset, args
-            raise
+        with self.admin_access.web_request() as req:
+            if rql is None:
+                rset = None
+            else:
+                rset = req.execute(rql)
+            try:
+                obj = self.vreg['views'].select(vid, req, rset=rset, **args)
+                return obj.render(**args)
+            except Exception:
+                print vid, rset, args
+                raise
 
     def test_form(self):
         for vid, rql, args in (
@@ -502,6 +492,7 @@
     __select__ = is_instance('CWEType') & rql_condition('X name "CWEType"')
     title = 'bla'
 
+
 class RQLActionTC(ViewSelectorTC):
 
     def setUp(self):
@@ -516,34 +507,33 @@
         del self.vreg['actions']['testaction']
 
     def test(self):
-        req = self.request()
-        rset = req.execute('CWEType X WHERE X name "CWEType"')
-        self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
-                             {'useractions': USERACTIONS,
-                              'siteactions': SITEACTIONS,
-                              'footer': FOOTERACTIONS,
-                              'manage': MANAGEACTIONS,
-                              'mainactions': [actions.ModifyAction, actions.ViewSameCWEType],
-                              'moreactions': [actions.ManagePermissionsAction,
-                                              actions.AddRelatedActions,
-                                              actions.DeleteAction,
-                                              actions.CopyAction,
-                                              CWETypeRQLAction,
-                                              ],
-                              })
-        req = self.request()
-        rset = req.execute('CWEType X WHERE X name "CWRType"')
-        self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
-                             {'useractions': USERACTIONS,
-                              'siteactions': SITEACTIONS,
-                              'footer': FOOTERACTIONS,
-                              'manage': MANAGEACTIONS,
-                              'mainactions': [actions.ModifyAction, actions.ViewSameCWEType],
-                              'moreactions': [actions.ManagePermissionsAction,
-                                              actions.AddRelatedActions,
-                                              actions.DeleteAction,
-                                              actions.CopyAction,]
-                              })
+        with self.admin_access.web_request() as req:
+            rset = req.execute('CWEType X WHERE X name "CWEType"')
+            self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
+                                 {'useractions': USERACTIONS,
+                                  'siteactions': SITEACTIONS,
+                                  'footer': FOOTERACTIONS,
+                                  'manage': MANAGEACTIONS,
+                                  'mainactions': [actions.ModifyAction, actions.ViewSameCWEType],
+                                  'moreactions': [actions.ManagePermissionsAction,
+                                                  actions.AddRelatedActions,
+                                                  actions.DeleteAction,
+                                                  actions.CopyAction,
+                                                  CWETypeRQLAction,
+                                                  ],
+                                  })
+            rset = req.execute('CWEType X WHERE X name "CWRType"')
+            self.assertDictEqual(self.pactionsdict(req, rset, skipcategories=()),
+                                 {'useractions': USERACTIONS,
+                                  'siteactions': SITEACTIONS,
+                                  'footer': FOOTERACTIONS,
+                                  'manage': MANAGEACTIONS,
+                                  'mainactions': [actions.ModifyAction, actions.ViewSameCWEType],
+                                  'moreactions': [actions.ManagePermissionsAction,
+                                                  actions.AddRelatedActions,
+                                                  actions.DeleteAction,
+                                                  actions.CopyAction,]
+                                  })