summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIsmael Carnales <icarnales@gmail.com>2009-12-02 02:22:44 +0100
committerIsmael Carnales <icarnales@gmail.com>2009-12-02 02:26:14 +0100
commit3f8fe75d36f6fbf58ab1df81cb38abe108ab1b6b (patch)
tree95c96535eda0a07c3145753863aecf97cd15ab9e
parente0506afaf1b876d672e5cb40ad13702f0c6f0e01 (diff)
downloadarchweb-3f8fe75d36f6fbf58ab1df81cb38abe108ab1b6b.tar.gz
archweb-3f8fe75d36f6fbf58ab1df81cb38abe108ab1b6b.tar.xz
Add credential requirements tests to devel app
* Add models.py required file to app * Use user_passes_test instead of custom superuser checking in new_user_form as it implements the same "next" redirection as login_required Signed-off-by: Ismael Carnales <icarnales@gmail.com>
-rw-r--r--devel/models.py0
-rw-r--r--devel/tests.py39
-rw-r--r--devel/views.py6
3 files changed, 41 insertions, 4 deletions
diff --git a/devel/models.py b/devel/models.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/devel/models.py
diff --git a/devel/tests.py b/devel/tests.py
new file mode 100644
index 0000000..682f3d9
--- /dev/null
+++ b/devel/tests.py
@@ -0,0 +1,39 @@
+from django.test import TestCase
+
+
+class DevelTest(TestCase):
+
+ def test_index(self):
+ response = self.client.get('/devel/')
+ self.assertEqual(response.status_code, 302)
+ self.assertEqual(response.has_header('Location'), True)
+ self.assertEqual(response['location'],
+ 'http://testserver/login/?next=/devel/')
+
+ def test_notify(self):
+ response = self.client.get('/devel/notify/')
+ self.assertEqual(response.status_code, 302)
+ self.assertEqual(response.has_header('Location'), True)
+ self.assertEqual(response['location'],
+ 'http://testserver/login/?next=/devel/notify/')
+
+ def test_profile(self):
+ response = self.client.get('/devel/profile/')
+ self.assertEqual(response.status_code, 302)
+ self.assertEqual(response.has_header('Location'), True)
+ self.assertEqual(response['location'],
+ 'http://testserver/login/?next=/devel/profile/')
+
+ def test_newuser(self):
+ response = self.client.get('/devel/newuser/')
+ self.assertEqual(response.status_code, 302)
+ self.assertEqual(response.has_header('Location'), True)
+ self.assertEqual(response['location'],
+ 'http://testserver/login/?next=/devel/newuser/')
+
+ def test_mirrors(self):
+ response = self.client.get('/mirrors/')
+ self.assertEqual(response.status_code, 302)
+ self.assertEqual(response.has_header('Location'), True)
+ self.assertEqual(response['location'],
+ 'http://testserver/login/?next=/mirrors/')
diff --git a/devel/views.py b/devel/views.py
index 4d0a0cc..7e5f79a 100644
--- a/devel/views.py
+++ b/devel/views.py
@@ -1,6 +1,6 @@
from django import forms
from django.http import HttpResponseRedirect
-from django.contrib.auth.decorators import login_required
+from django.contrib.auth.decorators import login_required, user_passes_test
from django.contrib.auth.models import User
from django.shortcuts import render_to_response
from django.template import RequestContext
@@ -105,10 +105,8 @@ Password: %s""" % (user.username, pw),
[user.email],
fail_silently=False)
+@user_passes_test(lambda u: u.is_superuser)
def new_user_form(request):
- if not request.user.is_superuser:
- return HttpResponseRedirect('/login/')
-
if request.POST:
form = NewUserForm(request.POST)
if form.is_valid():