[devtools] add http_publish to CubicWebTC (closes #2565882)
authorJulien Cristau <julien.cristau@logilab.fr>
Fri, 22 Feb 2013 11:17:02 +0100
changeset 8721 b399c87df63c
parent 8720 d2f01aaae8c0
child 8724 1beab80aed23
[devtools] add http_publish to CubicWebTC (closes #2565882) Fakes a http request, without overriding the normal error handling. Returns the request object so the caller can check for errors.
devtools/testlib.py
--- a/devtools/testlib.py	Fri Jan 18 12:47:40 2013 +0100
+++ b/devtools/testlib.py	Fri Feb 22 11:17:02 2013 +0100
@@ -705,6 +705,20 @@
         ctrlid, rset = self.app.url_resolver.process(req, req.relative_path(False))
         return self.ctrl_publish(req, ctrlid, rset)
 
+    def http_publish(self, url, data=None):
+        """like `url_publish`, except this returns a http response, even in case of errors"""
+        req = self.req_from_url(url)
+        if data is not None:
+            req.form.update(data)
+        # remove the monkey patched error handler
+        fake_error_handler = self.app.error_handler
+        del self.app.error_handler
+        try:
+            result = self.app_handle_request(req, req.relative_path(False))
+        finally:
+            self.app.error_handler = fake_error_handler
+        return result, req
+
     @staticmethod
     def _parse_location(req, location):
         try: