diff options
author | maxbr <maxbr@mi.fu-berlin.de> | 2016-10-17 14:56:11 +0200 |
---|---|---|
committer | maxbr <maxbr@mi.fu-berlin.de> | 2016-10-17 14:56:11 +0200 |
commit | af9b7ddeb637278a7705964ba98c8e6a2e7307f4 (patch) | |
tree | 503203445b0760bc5cd13c1e2d2347fe7fa069bf /tools/pharos-dashboard/src/account/views.py | |
parent | 7022542bc70c448f71fa56c06d90595e276d7dcc (diff) |
Add unit tests
JIRA: RELENG-12
This commit increases test statement coverage to 84%. It also fixes the bugs
that emerged while testing.
Change-Id: I696091f1a07f8b7647872c7cb15f4368a4690619
Signed-off-by: maxbr <maxbr@mi.fu-berlin.de>
Diffstat (limited to 'tools/pharos-dashboard/src/account/views.py')
-rw-r--r-- | tools/pharos-dashboard/src/account/views.py | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/tools/pharos-dashboard/src/account/views.py b/tools/pharos-dashboard/src/account/views.py index ac973f53..17fbdc3a 100644 --- a/tools/pharos-dashboard/src/account/views.py +++ b/tools/pharos-dashboard/src/account/views.py @@ -21,7 +21,6 @@ from django.contrib.auth.models import User from django.urls import reverse from django.utils.decorators import method_decorator from django.views.generic import RedirectView, TemplateView, UpdateView - from jira import JIRA from rest_framework.authtoken.models import Token @@ -58,9 +57,16 @@ class JiraLoginView(RedirectView): client.set_signature_method(SignatureMethod_RSA_SHA1()) # Step 1. Get a request token from Jira. - resp, content = client.request(settings.OAUTH_REQUEST_TOKEN_URL, "POST") + try: + resp, content = client.request(settings.OAUTH_REQUEST_TOKEN_URL, "POST") + except Exception as e: + messages.add_message(self.request, messages.ERROR, + 'Error: Connection to Jira failed. Please contact an Administrator') + return '/' if resp['status'] != '200': - raise Exception("Invalid response %s: %s" % (resp['status'], content)) + messages.add_message(self.request, messages.ERROR, + 'Error: Connection to Jira failed. Please contact an Administrator') + return '/' # Step 2. Store the request token in a session for later use. self.request.session['request_token'] = dict(urllib.parse.parse_qsl(content.decode())) @@ -87,8 +93,15 @@ class JiraAuthenticatedView(RedirectView): client.set_signature_method(SignatureMethod_RSA_SHA1()) # Step 2. Request the authorized access token from Jira. - resp, content = client.request(settings.OAUTH_ACCESS_TOKEN_URL, "POST") + try: + resp, content = client.request(settings.OAUTH_ACCESS_TOKEN_URL, "POST") + except Exception as e: + messages.add_message(self.request, messages.ERROR, + 'Error: Connection to Jira failed. Please contact an Administrator') + return '/' if resp['status'] != '200': + messages.add_message(self.request, messages.ERROR, + 'Error: Connection to Jira failed. Please contact an Administrator') return '/' access_token = dict(urllib.parse.parse_qsl(content.decode())) @@ -128,6 +141,7 @@ class JiraAuthenticatedView(RedirectView): # redirect user to settings page to complete profile return url + @method_decorator(login_required, name='dispatch') class UserListView(TemplateView): template_name = "account/user_list.html" |