Skip to content

Commit

Permalink
[raz] Raise 503 exception for no SAS token and cleaner tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Harshg999 authored and romainr committed Aug 25, 2021
1 parent c5478f9 commit c994971
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
9 changes: 9 additions & 0 deletions desktop/core/src/desktop/lib/rest/raz_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -48,6 +55,8 @@ def execute(self, http_method, path, params=None, data=None, headers=None, allow
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]
Expand Down
25 changes: 8 additions & 17 deletions desktop/core/src/desktop/lib/rest/raz_http_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -56,20 +57,10 @@ def test_get_file(self):
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'})

0 comments on commit c994971

Please sign in to comment.