[req] .view should not catch [Object|Registry]NotFound (which is a bug), only NoSelectableObject (closes #1973681) stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 29 Sep 2011 14:05:45 +0200
branchstable
changeset 7888 e257b4476454
parent 7887 42a0b7398d31
child 7890 68e8c81fa96d
[req] .view should not catch [Object|Registry]NotFound (which is a bug), only NoSelectableObject (closes #1973681)
req.py
test/unittest_req.py
--- a/req.py	Thu Sep 29 14:05:42 2011 +0200
+++ b/req.py	Thu Sep 29 14:05:45 2011 +0200
@@ -29,7 +29,7 @@
 from logilab.common.deprecation import deprecated
 from logilab.common.date import ustrftime, strptime, todate, todatetime
 
-from cubicweb import Unauthorized, RegistryException, typed_eid
+from cubicweb import Unauthorized, NoSelectableObject, typed_eid
 from cubicweb.rset import ResultSet
 
 ONESECOND = timedelta(0, 1, 0)
@@ -336,7 +336,7 @@
             initargs.update(kwargs)
         try:
             view =  self.vreg[__registry].select(__vid, self, rset=rset, **initargs)
-        except RegistryException:
+        except NoSelectableObject:
             if __fallback_oid is None:
                 raise
             view =  self.vreg[__registry].select(__fallback_oid, self,
--- a/test/unittest_req.py	Thu Sep 29 14:05:42 2011 +0200
+++ b/test/unittest_req.py	Thu Sep 29 14:05:45 2011 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -15,12 +15,14 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
+
 from logilab.common.testlib import TestCase, unittest_main
+from cubicweb import ObjectNotFound
 from cubicweb.req import RequestSessionBase
 from cubicweb.devtools.testlib import CubicWebTC
 from cubicweb import Unauthorized
 
-class RebuildURLTC(TestCase):
+class RequestTC(TestCase):
     def test_rebuild_url(self):
         rebuild_url = RequestSessionBase(None).rebuild_url
         self.assertEqual(rebuild_url('http://logilab.fr?__message=pouet', __message='hop'),
@@ -49,5 +51,13 @@
         self.assertRaises(Unauthorized, req.ensure_ro_rql, 'SET X login "toto" WHERE X is CWUser')
         self.assertRaises(Unauthorized, req.ensure_ro_rql, '   SET X login "toto" WHERE X is CWUser   ')
 
+
+class RequestCWTC(CubicWebTC):
+    def test_view_catch_ex(self):
+        req = self.request()
+        rset = self.execute('CWUser X WHERE X login "hop"')
+        self.assertEqual(req.view('oneline', rset, 'null'), '')
+        self.assertRaises(ObjectNotFound, req.view, 'onelinee', rset, 'null')
+
 if __name__ == '__main__':
     unittest_main()