Pārlūkot izejas kodu

[lib] Disable auto URL quoting in RazHttpClient

Romain Rigaux 4 gadi atpakaļ
vecāks
revīzija
f6ad77498d

+ 3 - 3
desktop/core/src/desktop/lib/rest/http_client.py

@@ -200,7 +200,7 @@ class HttpClient(object):
     if urlencode:
       path = urllib_quote(smart_str(path))
 
-    url = self._make_url(path, params)
+    url = self._make_url(path, params, do_urlencode=urlencode)
 
     if http_method in ("GET", "DELETE"):
       if data is not None:
@@ -243,12 +243,12 @@ class HttpClient(object):
             exceptions.TooManyRedirects) as ex:
       raise self._exc_class(ex)
 
-  def _make_url(self, path, params):
+  def _make_url(self, path, params, do_urlencode=True):
     res = self._base_url
     if path:
       res += posixpath.normpath('/' + path.lstrip('/'))
     if params:
-      param_str = urlencode(params)
+      param_str = urlencode(params) if do_urlencode else '&'.join(['%s=%s' % (k, v) for k, v in params.items()])
       res += '?' + param_str
     return iri_to_uri(res)
 

+ 3 - 10
desktop/core/src/desktop/lib/rest/raz_http_client.py

@@ -15,19 +15,12 @@
 # limitations under the License.
 
 import logging
-import sys
 
 from desktop import conf
 from desktop.lib.raz.clients import AdlsRazClient
 from desktop.lib.rest.http_client import HttpClient
 
 
-if sys.version_info[0] > 2:
-  import urllib.request, urllib.error
-else:
-  from urllib import quote as urllib_quote
-
-
 LOG = logging.getLogger(__name__)
 
 
@@ -52,8 +45,8 @@ class RazHttpClient(HttpClient):
 
     token = raz_client.get_url(action=http_method, path=url, headers=headers)
 
-    signed_path = path + ('?' if '?' in url else '&') + token
-
+    signed_path = path + ('?' if '?' in url else '&') + token  # Same as using as params
+    print(111)
     return super(RazHttpClient, self).execute(
         http_method=http_method,
         path=signed_path,
@@ -61,7 +54,7 @@ class RazHttpClient(HttpClient):
         data=data,
         headers=headers,
         allow_redirects=allow_redirects,
-        urlencode=urlencode,
+        urlencode=False,
         files=files,
         stream=stream,
         clear_cookies=clear_cookies,

+ 9 - 11
desktop/core/src/desktop/lib/rest/raz_http_client_test.py

@@ -16,7 +16,6 @@
 
 import sys
 
-
 from nose.tools import assert_equal, assert_false, assert_true
 
 from desktop.lib.rest.raz_http_client import RazHttpClient
@@ -31,26 +30,25 @@ else:
 class TestRazHttpClient():
 
   def test_get_file(self):
-    with patch('desktop.lib.rest.raz_http_client.AdlsRazClient.get_url') as get_url:
-      with patch('desktop.lib.rest.raz_http_client.HttpClient.execute') as execute:
+    with patch('desktop.lib.rest.raz_http_client.AdlsRazClient.get_url') as raz_get_url:
+      with patch('desktop.lib.rest.raz_http_client.HttpClient.execute') as http_execute:
 
-        get_url.return_value = 'https://gethue.blob.core.windows.net/hue/data/customer.csv?sv=2014-02-14&sr=b&' + \
-          'sig=pJL%2FWyed41tptiwBM5ymYre4qF8wzrO05tS5MCjkutc%3D&st=2015-01-02T01%3A40%3A51Z&se=2015-01-02T02%3A00%3A51Z&sp=r'
-        execute.return_value = 'my file'
+        raz_get_url.return_value = 'sv=2014-02-14&sr=b&sig=pJL%2FWyed41tptiwBM5ymYre4qF8wzrO05tS5MCjkutc%3D&st=2015-01-02T01%3A40%3A51Z&se=2015-01-02T02%3A00%3A51Z&sp=r'
+        http_execute.return_value = 'my file content'
 
         client = RazHttpClient(username='test', base_url='https://gethue.blob.core.windows.net')
         f = client.execute(http_method='GET', path='/gethue/data/customer.csv')
 
-        assert_equal('my file', f)
-        get_url.assert_called_with(action='GET', path='https://gethue.blob.core.windows.net/gethue/data/customer.csv', headers=None)
-        execute.assert_called_with(
+        assert_equal('my file content', f)
+        raz_get_url.assert_called_with(action='GET', path='https://gethue.blob.core.windows.net/gethue/data/customer.csv', headers=None)
+        http_execute.assert_called_with(
             http_method='GET',
-            path='/gethue/data/customer.csv&https://gethue.blob.core.windows.net/hue/data/customer.csv?sv=2014-02-14&sr=b&sig=pJL%2FWyed41tptiwBM5ymYre4qF8wzrO05tS5MCjkutc%3D&st=2015-01-02T01%3A40%3A51Z&se=2015-01-02T02%3A00%3A51Z&sp=r',
+            path='/gethue/data/customer.csv&sv=2014-02-14&sr=b&sig=pJL%2FWyed41tptiwBM5ymYre4qF8wzrO05tS5MCjkutc%3D&st=2015-01-02T01%3A40%3A51Z&se=2015-01-02T02%3A00%3A51Z&sp=r',
             params=None,
             data=None,
             headers=None,
             allow_redirects=False,
-            urlencode=True,
+            urlencode=False,
             files=None,
             stream=False,
             clear_cookies=False,