Fix unexpected req.relative_path() when calling CWTC.app_handle_request with path argument
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 04 Nov 2016 11:19:11 +0100
changeset 11800 3cd5ac8d43ed
parent 11799 1bdfe9d4ab83
child 11801 7a7ce3da28fb
Fix unexpected req.relative_path() when calling CWTC.app_handle_request with path argument The _deprecated_path_arg decorator can not be used in this case, since it won't ensure backward compat if path value has been specified and is not similar as req's path (which is generally the case). This problem has been introduced by 904ee9cd0cf9.
cubicweb/devtools/testlib.py
cubicweb/web/application.py
cubicweb/web/test/unittest_application.py
--- a/cubicweb/devtools/testlib.py	Fri Nov 04 13:12:10 2016 +0100
+++ b/cubicweb/devtools/testlib.py	Fri Nov 04 11:19:11 2016 +0100
@@ -27,6 +27,7 @@
 from contextlib import contextmanager
 from inspect import isgeneratorfunction
 from itertools import chain
+from warnings import warn
 import tempfile
 
 from six import text_type, string_types, reraise
@@ -725,8 +726,12 @@
             ctrl = self.vreg['controllers'].select('ajax', req)
             yield ctrl.publish(), req
 
-    @application._deprecated_path_arg
-    def app_handle_request(self, req):
+    def app_handle_request(self, req, path=None):
+        if path is not None:
+            warn('[3.24] path argument got removed from app_handle_request parameters, '
+                 'give it to the request constructor', DeprecationWarning)
+            if req.relative_path(False) != path:
+                req._url = path
         return self.app.core_handle(req)
 
     @deprecated("[3.15] app_handle_request is the new and better way"
--- a/cubicweb/web/application.py	Fri Nov 04 13:12:10 2016 +0100
+++ b/cubicweb/web/application.py	Fri Nov 04 11:19:11 2016 +0100
@@ -55,6 +55,9 @@
             func_name = func.func_name if PY2 else func.__name__
             warn('[3.24] path argument got removed from "%s" parameters' % func_name,
                  DeprecationWarning)
+            path = args[0] if args else kwargs['path']
+            assert path == req.relative_path(False), \
+                'mismatching path, {0} vs {1}'.format(path, req.relative_path(False))
         return func(self, req)
     return wrapper
 
--- a/cubicweb/web/test/unittest_application.py	Fri Nov 04 13:12:10 2016 +0100
+++ b/cubicweb/web/test/unittest_application.py	Fri Nov 04 11:19:11 2016 +0100
@@ -762,7 +762,7 @@
 
     def test_handle_deprecation(self):
         """Test deprecation warning for *_handle methods."""
-        with self.admin_access.web_request(url='nothing') as req:
+        with self.admin_access.web_request(url='foo') as req:
             with self.assertWarns(DeprecationWarning) as cm:
                 self.app.core_handle(req, 'foo')
             self.assertIn('path argument got removed from "core_handle"',