allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jetm...@apache.org
Subject [12/14] allura git commit: [#7878] ticket:771 Convert args in test app to plain string
Date Wed, 20 May 2015 11:14:15 GMT
[#7878] ticket:771 Convert args in test app to plain string

WebTest==1.4.0 which we are using does not handle unicode well. For example
methods to send GET/POST/etc request raise exception if url is unicode or some
of the parameters are.

Seems like newer versions (2.0.18) supports it better, but we can't use it,
because it depends on WebOb>=1.2 which conflicts with TurboGears which depends
on WebOb==1.0.8.  That is why manual fix for now.


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/785c254f
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/785c254f
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/785c254f

Branch: refs/heads/ib/7878
Commit: 785c254fcd475e7ed78e00a34cc3adfec7d270a6
Parents: 9b1623e
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Tue May 19 11:38:18 2015 +0000
Committer: Igor Bondarenko <jetmind2@gmail.com>
Committed: Tue May 19 11:38:18 2015 +0000

----------------------------------------------------------------------
 AlluraTest/alluratest/validation.py | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/785c254f/AlluraTest/alluratest/validation.py
----------------------------------------------------------------------
diff --git a/AlluraTest/alluratest/validation.py b/AlluraTest/alluratest/validation.py
index bd55608..5696df7 100644
--- a/AlluraTest/alluratest/validation.py
+++ b/AlluraTest/alluratest/validation.py
@@ -306,7 +306,26 @@ class ValidatingTestApp(PostParamCheckingTestApp):
             params[k] = kw.pop(k, False)
         return params, kw
 
+    def convert_dict(self, d):
+        return {str(k): str(v) for k, v in d.iteritems()}
+
+    def convert_args(self, args, kw):
+        """
+        Convert args to plain string, because webtest.TestApp.get/post/etc does
+        not work with unicode.
+        """
+        url = str(args[0])
+        args = (url,) + args[1:]
+        params = kw.pop('params', None)
+        extra_environ = kw.pop('extra_environ', None)
+        if params:
+            kw['params'] = self.convert_dict(params)
+        if extra_environ:
+            kw['extra_environ'] = self.convert_dict(extra_environ)
+        return args, kw
+
     def get(self, *args, **kw):
+        args, kw = self.convert_args(args, kw)
         val_params, kw = self._get_validation_params(kw)
         resp = super(ValidatingTestApp, self).get(*args, **kw)
         if not self.validate_skip and not val_params['validate_skip']:
@@ -314,6 +333,7 @@ class ValidatingTestApp(PostParamCheckingTestApp):
         return resp
 
     def post(self, *args, **kw):
+        args, kw = self.convert_args(args, kw)
         val_params, kw = self._get_validation_params(kw)
         resp = super(ValidatingTestApp, self).post(*args, **kw)
         if not self.validate_skip and not val_params['validate_skip']:
@@ -321,6 +341,7 @@ class ValidatingTestApp(PostParamCheckingTestApp):
         return resp
 
     def delete(self, *args, **kw):
+        args, kw = self.convert_args(args, kw)
         val_params, kw = self._get_validation_params(kw)
         resp = super(ValidatingTestApp, self).delete(*args, **kw)
         if not self.validate_skip and not val_params['validate_skip']:


Mime
View raw message