summaryrefslogtreecommitdiffstats
path: root/pharos-dashboard/src/account
diff options
context:
space:
mode:
authormaxbr <maxbr@mi.fu-berlin.de>2016-10-17 14:56:11 +0200
committermaxbr <maxbr@mi.fu-berlin.de>2016-10-17 14:56:11 +0200
commit61f00f4110b1d33827e3bd19ffef34f10be8273a (patch)
tree2c24ca2a8414eb1f40d5363e03d3c2b21e1fec32 /pharos-dashboard/src/account
parentadafb09cb1f221259970d16886ea0e03169899a5 (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 'pharos-dashboard/src/account')
-rw-r--r--pharos-dashboard/src/account/jira_util.py3
-rw-r--r--pharos-dashboard/src/account/models.py5
-rw-r--r--pharos-dashboard/src/account/tests/test_general.py10
-rw-r--r--pharos-dashboard/src/account/views.py22
4 files changed, 30 insertions, 10 deletions
diff --git a/pharos-dashboard/src/account/jira_util.py b/pharos-dashboard/src/account/jira_util.py
index c333f8c..fdb87f7 100644
--- a/pharos-dashboard/src/account/jira_util.py
+++ b/pharos-dashboard/src/account/jira_util.py
@@ -12,11 +12,10 @@ import base64
import os
import oauth2 as oauth
+from django.conf import settings
from jira import JIRA
from tlslite.utils import keyfactory
-from django.conf import settings
-
class SignatureMethod_RSA_SHA1(oauth.SignatureMethod):
name = 'RSA-SHA1'
diff --git a/pharos-dashboard/src/account/models.py b/pharos-dashboard/src/account/models.py
index d87ee18..c2e9902 100644
--- a/pharos-dashboard/src/account/models.py
+++ b/pharos-dashboard/src/account/models.py
@@ -8,12 +8,9 @@
##############################################################################
-from django.db import models
-
from django.contrib.auth.models import User
-from rest_framework.authtoken.models import Token
+from django.db import models
-from dashboard.models import Resource
def upload_to(object, filename):
return object.user.username + '/' + filename
diff --git a/pharos-dashboard/src/account/tests/test_general.py b/pharos-dashboard/src/account/tests/test_general.py
index 72e7ea1..e8f483b 100644
--- a/pharos-dashboard/src/account/tests/test_general.py
+++ b/pharos-dashboard/src/account/tests/test_general.py
@@ -48,3 +48,13 @@ class AccountMiddlewareTestCase(TestCase):
self.user1profile.save()
self.client.get(url)
self.assertEqual(timezone.get_current_timezone_name(), 'Etc/Greenwich')
+
+ # if there is no profile for a user, it should be created
+ user2 = User.objects.create(username='user2')
+ user2.set_password('user2')
+ user2.save()
+ self.client.login(username='user2', password='user2')
+ self.client.get(url)
+ self.assertTrue(user2.userprofile)
+
+
diff --git a/pharos-dashboard/src/account/views.py b/pharos-dashboard/src/account/views.py
index ac973f5..17fbdc3 100644
--- a/pharos-dashboard/src/account/views.py
+++ b/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"