[vreg api update] remove some deprecation warnings
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 03 Aug 2009 16:31:30 +0200
changeset 2661 f8df42c9da6b
parent 2660 0d0924d75849
child 2662 87aed8cb7ff6
[vreg api update] remove some deprecation warnings
devtools/apptest.py
sobjects/test/data/schema.py
web/test/unittest_application.py
web/test/unittest_form.py
web/test/unittest_magicsearch.py
web/test/unittest_views_basecontrollers.py
web/test/unittest_views_editforms.py
web/test/unittest_views_navigation.py
web/views/editforms.py
web/views/massmailing.py
--- a/devtools/apptest.py	Mon Aug 03 15:57:05 2009 +0200
+++ b/devtools/apptest.py	Mon Aug 03 16:31:30 2009 +0200
@@ -249,7 +249,7 @@
         dump = simplejson.dumps
         args = [dump(arg) for arg in args]
         req = self.request(fname=fname, pageid='123', arg=args)
-        ctrl = self.vreg.select('controllers', 'json', req)
+        ctrl = self.vreg['controllers'].select('json', req)
         return ctrl.publish(), req
 
     # default test setup and teardown #########################################
@@ -294,7 +294,7 @@
         def setUp(self):
             super(ControllerTC, self).setUp()
             self.req = self.request()
-            self.ctrl = self.vreg.select('controllers', 'edit', self.req)
+            self.ctrl = self.vreg['controllers'].select('edit', self.req)
 
         def publish(self, req):
             assert req is self.ctrl.req
@@ -308,7 +308,7 @@
 
         def expect_redirect_publish(self, req=None):
             if req is not None:
-                self.ctrl = self.vreg.select('controllers', 'edit', req)
+                self.ctrl = self.vreg['controllers'].select('edit', req)
             else:
                 req = self.req
             try:
--- a/sobjects/test/data/schema.py	Mon Aug 03 15:57:05 2009 +0200
+++ b/sobjects/test/data/schema.py	Mon Aug 03 16:31:30 2009 +0200
@@ -5,6 +5,8 @@
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
+from yams.buildobjs import RelationDefinition
+
 class comments(RelationDefinition):
     subject = 'Comment'
     object = 'Card'
--- a/web/test/unittest_application.py	Mon Aug 03 15:57:05 2009 +0200
+++ b/web/test/unittest_application.py	Mon Aug 03 16:31:30 2009 +0200
@@ -7,16 +7,17 @@
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
 
-from logilab.common.testlib import TestCase, unittest_main
 import base64, Cookie
-
 import sys
 from urllib import unquote
+
+from logilab.common.testlib import TestCase, unittest_main
 from logilab.common.decorators import clear_cache
 
+from cubicweb.devtools.apptest import EnvBasedTC
+from cubicweb.devtools.fake import FakeRequest
 from cubicweb.web import Redirect, AuthenticationError, ExplicitLogin, INTERNAL_FIELD_VALUE
 from cubicweb.web.views.basecontrollers import ViewController
-from cubicweb.devtools._apptest import FakeRequest
 
 class FakeMapping:
     """emulates a mapping module"""
@@ -133,9 +134,6 @@
                            for i in (12, 13, 14)])
 
 
-from cubicweb.devtools.apptest import EnvBasedTC
-
-
 class ApplicationTC(EnvBasedTC):
 
     def publish(self, req, path='view'):
--- a/web/test/unittest_form.py	Mon Aug 03 15:57:05 2009 +0200
+++ b/web/test/unittest_form.py	Mon Aug 03 16:31:30 2009 +0200
@@ -91,7 +91,7 @@
         e.req = self.req
         geid = self.execute('CWGroup X WHERE X name "users"')[0][0]
         self.req.form['__linkto'] = 'in_group:%s:subject' % geid
-        form = self.vreg.select('forms', 'edition', self.req, entity=e)
+        form = self.vreg['forms'].select('edition', self.req, entity=e)
         form.content_type = 'text/html'
         pageinfo = self._check_html(form.form_render(), form, template=None)
         inputs = pageinfo.find_tag('select', False)
@@ -101,8 +101,8 @@
 
     def test_reledit_composite_field(self):
         rset = self.execute('INSERT BlogEntry X: X title "cubicweb.org", X content "hop"')
-        form = self.vreg.select_object('views', 'reledit', self.request(),
-                                       rset=rset, row=0, rtype='content')
+        form = self.vreg['views'].select('reledit', self.request(),
+                                         rset=rset, row=0, rtype='content')
         data = form.render(row=0, rtype='content')
         self.failUnless('edits-content' in data)
         self.failUnless('edits-content_format' in data)
--- a/web/test/unittest_magicsearch.py	Mon Aug 03 15:57:05 2009 +0200
+++ b/web/test/unittest_magicsearch.py	Mon Aug 03 16:31:30 2009 +0200
@@ -44,7 +44,7 @@
         super(QueryTranslatorTC, self).setUp()
         self.req = self.env.create_request()
         self.vreg.config.translations = {'en': _translate}
-        proc = self.vreg.select('components', 'magicsearch', self.req)
+        proc = self.vreg['components'].select('magicsearch', self.req)
         self.proc = [p for p in proc.processors if isinstance(p, QueryTranslator)][0]
 
     def test_basic_translations(self):
@@ -69,7 +69,7 @@
         super(QSPreProcessorTC, self).setUp()
         self.vreg.config.translations = {'en': _translate}
         self.req = self.request()
-        proc = self.vreg.select('components', 'magicsearch', self.req)
+        proc = self.vreg['components'].select('magicsearch', self.req)
         self.proc = [p for p in proc.processors if isinstance(p, QSPreProcessor)][0]
         self.proc.req = self.req
 
@@ -187,7 +187,7 @@
         super(ProcessorChainTC, self).setUp()
         self.vreg.config.translations = {'en': _translate}
         self.req = self.request()
-        self.proc = self.vreg.select('components', 'magicsearch', self.req)
+        self.proc = self.vreg['components'].select('magicsearch', self.req)
 
     def test_main_preprocessor_chain(self):
         """tests QUERY_PROCESSOR"""
--- a/web/test/unittest_views_basecontrollers.py	Mon Aug 03 15:57:05 2009 +0200
+++ b/web/test/unittest_views_basecontrollers.py	Mon Aug 03 16:31:30 2009 +0200
@@ -496,7 +496,7 @@
         # updated (which is what happened before this test)
         req = self.request()
         req.form['url'] = 'http://intranet.logilab.fr/'
-        controller = self.vreg.select('controllers', 'embed', req)
+        controller = self.vreg['controllers'].select('embed', req)
         result = controller.publish(rset=None)
 
 
@@ -504,7 +504,7 @@
 
     def test_usable_by_guets(self):
         req = self.request()
-        self.vreg.select('controllers', 'reportbug', req)
+        self.vreg['controllers'].select('reportbug', req)
 
 
 class SendMailControllerTC(EnvBasedTC):
@@ -512,7 +512,7 @@
     def test_not_usable_by_guets(self):
         self.login('anon')
         req = self.request()
-        self.assertRaises(NoSelectableObject, self.env.vreg.select, 'controllers', 'sendmail', req)
+        self.assertRaises(NoSelectableObject, self.env.vreg['controllers'].select, 'sendmail', req)
 
 
 
@@ -520,7 +520,7 @@
 
     def ctrl(self, req=None):
         req = req or self.request(url='http://whatever.fr/')
-        return self.vreg.select('controllers', 'json', req)
+        return self.vreg['controllers'].select('json', req)
 
     def setup_database(self):
         self.pytag = self.add_entity('Tag', name=u'python')
--- a/web/test/unittest_views_editforms.py	Mon Aug 03 15:57:05 2009 +0200
+++ b/web/test/unittest_views_editforms.py	Mon Aug 03 16:31:30 2009 +0200
@@ -18,8 +18,8 @@
     def test_custom_widget(self):
         AEF.rfields_kwargs.tag_subject_of(('CWUser', 'login', '*'),
                                           {'widget': AutoCompletionWidget(autocomplete_initfunc='get_logins')})
-        form = self.vreg.select('forms', 'edition', self.request(),
-                                entity=self.user())
+        form = self.vreg['forms'].select('edition', self.request(),
+                                         entity=self.user())
         field = form.field_by_name('login')
         self.assertIsInstance(field.widget, AutoCompletionWidget)
         AEF.rfields_kwargs.del_rtag('CWUser', 'login', '*', 'subject')
@@ -116,10 +116,10 @@
 
     def test_edition_form(self):
         rset = self.execute('CWUser X LIMIT 1')
-        form = self.vreg.select('forms', 'edition', rset.req, rset=rset,
+        form = self.vreg['forms'].select('edition', rset.req, rset=rset,
                                 row=0, col=0)
         # should be also selectable by specifying entity
-        self.vreg.select('forms', 'edition', rset.req,
+        self.vreg['forms'].select('edition', rset.req,
                          entity=rset.get_entity(0, 0))
         self.failIf(any(f for f in form.fields if f is None))
 
--- a/web/test/unittest_views_navigation.py	Mon Aug 03 15:57:05 2009 +0200
+++ b/web/test/unittest_views_navigation.py	Mon Aug 03 16:31:30 2009 +0200
@@ -19,31 +19,31 @@
     def test_navigation_selection(self):
         rset = self.execute('Any X,N WHERE X name N')
         req = self.request()
-        navcomp = self.vreg.select('components', 'navigation', req, rset=rset)
+        navcomp = self.vreg['components'].select('navigation', req, rset=rset)
         self.assertIsInstance(navcomp, PageNavigation)
         req.set_search_state('W:X:Y:Z')
-        navcomp = self.vreg.select('components', 'navigation', req, rset=rset)
+        navcomp = self.vreg['components'].select('navigation', req, rset=rset)
         self.assertIsInstance(navcomp, PageNavigation)
         req.set_search_state('normal')
         rset = self.execute('Any X,N ORDERBY N WHERE X name N')
-        navcomp = self.vreg.select('components', 'navigation', req, rset=rset)
+        navcomp = self.vreg['components'].select('navigation', req, rset=rset)
         self.assertIsInstance(navcomp, SortedNavigation)
         req.set_search_state('W:X:Y:Z')
-        navcomp = self.vreg.select('components', 'navigation', req, rset=rset)
+        navcomp = self.vreg['components'].select('navigation', req, rset=rset)
         self.assertIsInstance(navcomp, SortedNavigation)
         req.set_search_state('normal')
         rset = self.execute('Any X,N LIMIT 10 WHERE X name N')
-        navcomp = self.vreg.select_object('components', 'navigation', req, rset=rset)
+        navcomp = self.vreg['components'].select_object('navigation', req, rset=rset)
         self.assertEquals(navcomp, None)
         req.set_search_state('W:X:Y:Z')
-        navcomp = self.vreg.select_object('components', 'navigation', req, rset=rset)
+        navcomp = self.vreg['components'].select_object('navigation', req, rset=rset)
         self.assertEquals(navcomp, None)
         req.set_search_state('normal')
         rset = self.execute('Any N, COUNT(RDEF) GROUPBY N ORDERBY N WHERE RDEF relation_type RT, RT name N')
-        navcomp = self.vreg.select('components', 'navigation', req, rset=rset)
+        navcomp = self.vreg['components'].select('navigation', req, rset=rset)
         self.assertIsInstance(navcomp, SortedNavigation)
         req.set_search_state('W:X:Y:Z')
-        navcomp = self.vreg.select('components', 'navigation', req, rset=rset)
+        navcomp = self.vreg['components'].select('navigation', req, rset=rset)
         self.assertIsInstance(navcomp, SortedNavigation)
 
 
@@ -51,22 +51,22 @@
         rset = self.execute('Any X,N ORDERBY N WHERE X name N')
         req = self.request()
         req.set_search_state('W:X:Y:Z')
-        navcomp = self.vreg.select('components', 'navigation', rset.req, rset=rset)
+        navcomp = self.vreg['components'].select('navigation', rset.req, rset=rset)
         html = navcomp.render()
         rset = self.execute('Any RDEF ORDERBY RT WHERE RDEF relation_type RT')
-        navcomp = self.vreg.select('components', 'navigation', req, rset=rset)
+        navcomp = self.vreg['components'].select('navigation', req, rset=rset)
         html = navcomp.render()
         rset = self.execute('Any RDEF ORDERBY RDEF WHERE RDEF relation_type RT')
-        navcomp = self.vreg.select('components', 'navigation', req, rset=rset)
+        navcomp = self.vreg['components'].select('navigation', req, rset=rset)
         html = navcomp.render()
         rset = self.execute('CWAttribute RDEF ORDERBY RDEF')
-        navcomp = self.vreg.select('components', 'navigation', req, rset=rset)
+        navcomp = self.vreg['components'].select('navigation', req, rset=rset)
         html = navcomp.render()
         rset = self.execute('Any RDEF ORDERBY N WHERE RDEF relation_type RT, RT name N')
-        navcomp = self.vreg.select('components', 'navigation', req, rset=rset)
+        navcomp = self.vreg['components'].select('navigation', req, rset=rset)
         html = navcomp.render()
         rset = self.execute('Any N, COUNT(RDEF) GROUPBY N ORDERBY N WHERE RDEF relation_type RT, RT name N')
-        navcomp = self.vreg.select('components', 'navigation', rset.req, rset=rset)
+        navcomp = self.vreg['components'].select('navigation', rset.req, rset=rset)
         html = navcomp.render()
 
 
--- a/web/views/editforms.py	Mon Aug 03 15:57:05 2009 +0200
+++ b/web/views/editforms.py	Mon Aug 03 16:31:30 2009 +0200
@@ -308,7 +308,7 @@
         """creation view for an entity"""
         etype = kwargs.pop('etype', self.req.form.get('etype'))
         try:
-            entity = self.vreg.etype_class(etype)(self.req)
+            entity = self.vreg['etypes'].etype_class(etype)(self.req)
         except:
             self.w(self.req._('no such entity type %s') % etype)
         else:
@@ -497,7 +497,7 @@
         :param role: the role played by the `peid` in the relation
         """
         try:
-            entity = self.vreg.etype_class(etype)(self.req, None, None)
+            entity = self.vreg['etypes'].etype_class(etype)(self.req, None, None)
         except:
             self.w(self.req._('no such entity type %s') % etype)
             return
--- a/web/views/massmailing.py	Mon Aug 03 15:57:05 2009 +0200
+++ b/web/views/massmailing.py	Mon Aug 03 16:31:30 2009 +0200
@@ -126,6 +126,6 @@
         req.add_js('cubicweb.widgets.js', 'cubicweb.massmailing.js')
         req.add_css('cubicweb.mailform.css')
         from_addr = '%s <%s>' % (req.user.dc_title(), req.user.get_email())
-        form = self.vreg.select('forms', 'massmailing', self.req, rset=self.rset,
+        form = self.vreg['forms'].select('massmailing', self.req, rset=self.rset,
                                 action='sendmail', domid='sendmail')
         self.w(form.form_render(sender=from_addr))