Эх сурвалжийг харах

[raz] Raise 503 exception for no SAS token and cleaner tests

Harshg999 4 жил өмнө
parent
commit
c99497114d

+ 9 - 0
desktop/core/src/desktop/lib/rest/raz_http_client.py

@@ -15,10 +15,17 @@
 # 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
+from desktop.lib.exceptions_renderable import PopupException
+
+if sys.version_info[0] > 2:
+  from django.utils.translation import gettext as _
+else:
+  from django.utils.translation import ugettext as _
 
 
 LOG = logging.getLogger(__name__)
@@ -48,6 +55,8 @@ class RazHttpClient(HttpClient):
     signed_url = url
     if response.get('token'):
       signed_url += ('?' if '?' not in url else '&') + response.get('token')
+    else:
+      raise PopupException(_('No SAS token in response'), error_code=503)
 
     # Required because `self._make_url` is called in base class execute method also
     signed_path = path + signed_url.partition(path)[2]

+ 8 - 17
desktop/core/src/desktop/lib/rest/raz_http_client_test.py

@@ -16,9 +16,10 @@
 
 import sys
 
-from nose.tools import assert_equal, assert_false, assert_true
+from nose.tools import assert_equal, assert_false, assert_true, assert_raises
 
 from desktop.lib.rest.raz_http_client import RazHttpClient
+from desktop.lib.exceptions_renderable import PopupException
 
 
 if sys.version_info[0] > 2:
@@ -56,20 +57,10 @@ class TestRazHttpClient():
             timeout=120
         )
 
-        # When there is no SAS token in response
-        raz_get_url.return_value = {}
-        client = RazHttpClient(username='test', base_url='https://gethue.blob.core.windows.net')
-        f = client.execute(http_method='GET', path='/gethue/data/customer.csv', params={'action': 'getStatus'})
 
-        raz_http_execute.assert_called_with(
-            http_method='GET',
-            path='/gethue/data/customer.csv?action=getStatus',
-            data=None,
-            headers=None,
-            allow_redirects=False,
-            urlencode=False,
-            files=None,
-            stream=False,
-            clear_cookies=False,
-            timeout=120
-        )
+  def test_no_sas_token_in_response(self):
+    with patch('desktop.lib.rest.raz_http_client.AdlsRazClient.get_url') as raz_get_url:
+      raz_get_url.return_value = {}
+      client = RazHttpClient(username='test', base_url='https://gethue.blob.core.windows.net')
+
+      assert_raises(PopupException, client.execute, http_method='GET', path='/gethue/data/customer.csv', params={'action': 'getStatus'})