1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 15:21:13 +03:00

presume 401 from insights means invalid credential

* Tell the user about the invalid credentials
This commit is contained in:
Chris Meyers 2017-08-14 16:09:18 -04:00
parent 5ad29c9081
commit 90ea9b8bde
2 changed files with 11 additions and 1 deletions

View File

@ -2116,7 +2116,9 @@ class HostInsights(GenericAPIView):
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
return (dict(error=_('Unkown exception {} while trying to GET {}').format(e, url)), status.HTTP_502_BAD_GATEWAY) return (dict(error=_('Unkown exception {} while trying to GET {}').format(e, url)), status.HTTP_502_BAD_GATEWAY)
if res.status_code != 200: if res.status_code == 401:
return (dict(error=_('Unauthorized access. Please check your Insights Credential username and password.')), status.HTTP_502_BAD_GATEWAY)
elif res.status_code != 200:
return (dict(error=_('Failed to gather reports and maintenance plans from Insights API at URL {}. Server responded with {} status code and message {}').format(url, res.status_code, res.content)), status.HTTP_502_BAD_GATEWAY) return (dict(error=_('Failed to gather reports and maintenance plans from Insights API at URL {}. Server responded with {} status code and message {}').format(url, res.status_code, res.content)), status.HTTP_502_BAD_GATEWAY)
try: try:

View File

@ -158,6 +158,14 @@ class TestHostInsights():
(msg, code) = view.get_insights('https://myexample.com/whocares/me/', 'ignore', 'ignore') (msg, code) = view.get_insights('https://myexample.com/whocares/me/', 'ignore', 'ignore')
assert msg['error'] == 'Failed to gather reports and maintenance plans from Insights API at URL https://myexample.com/whocares/me/. Server responded with 500 status code and message mock 500 err msg' assert msg['error'] == 'Failed to gather reports and maintenance plans from Insights API at URL https://myexample.com/whocares/me/. Server responded with 500 status code and message mock 500 err msg'
def test_get_insights_401(self, patch_parent, mocker):
view = HostInsights()
Response = namedtuple('Response', 'status_code content')
mocker.patch.object(view, '_get_insights', return_value=Response(401, ''))
(msg, code) = view.get_insights('https://myexample.com/whocares/me/', 'ignore', 'ignore')
assert msg['error'] == 'Unauthorized access. Please check your Insights Credential username and password.'
def test_get_insights_malformed_json_content(self, patch_parent, mocker): def test_get_insights_malformed_json_content(self, patch_parent, mocker):
view = HostInsights() view = HostInsights()