# HG changeset patch
# User Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
# Date 1282911294 -7200
# Node ID fc47b4e06d944467d5ce15ec5de1297fe8cac4c2
# Parent  7da7c270bbbdd454612b6b1951fbe87b182e58b4
[devtools] add url_publish() method on CubicWebTC to test a full publishing process from the url_resolver to the html generation

diff -r 7da7c270bbbd -r fc47b4e06d94 devtools/testlib.py
--- a/devtools/testlib.py	Fri Aug 27 13:44:55 2010 +0200
+++ b/devtools/testlib.py	Fri Aug 27 14:14:54 2010 +0200
@@ -551,6 +551,30 @@
             raise
         return result
 
+    def req_from_url(self, url):
+        """parses `url` and builds the corresponding CW-web request
+
+        req.form will be setup using the url's query string
+        """
+        req = self.request()
+        if isinstance(url, unicode):
+            url = url.encode(req.encoding) # req.setup_params() expects encoded strings
+        querystring = urlparse.urlparse(url)[-2]
+        params = urlparse.parse_qs(querystring)
+        req.setup_params(params)
+        return req
+
+    def url_publish(self, url):
+        """takes `url`, uses application's app_resolver to find the
+        appropriate controller, and publishes the result.
+
+        This should pretty much correspond to what occurs in a real CW server
+        except the apache-rewriter component is not called.
+        """
+        req = self.req_from_url(url)
+        ctrlid, rset = self.app.url_resolver.process(req, req.relative_path(False))
+        return self.ctrl_publish(req, ctrlid)
+
     def expect_redirect(self, callback, req):
         """call the given callback with req as argument, expecting to get a
         Redirect exception