1
0
mirror of https://github.com/django/django.git synced 2025-10-30 09:06:13 +00:00

Fixed #4617 -- Added raise_exception option to permission_required decorator to be able to raise a PermissionDenied exception instead of redirecting to the login page.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16607 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel
2011-08-12 14:15:41 +00:00
parent 1ca6e9b9e2
commit 351d5da69b
5 changed files with 45 additions and 7 deletions

View File

@@ -370,6 +370,21 @@ class ClientTest(TestCase):
# TODO: Log in with right permissions and request the page again
def test_view_with_permissions_exception(self):
"Request a page that is protected with @permission_required but raises a exception"
# Get the page without logging in. Should result in 403.
response = self.client.get('/test_client/permission_protected_view_exception/')
self.assertEquals(response.status_code, 403)
# Log in
login = self.client.login(username='testclient', password='password')
self.assertTrue(login, 'Could not log in')
# Log in with wrong permissions. Should result in 403.
response = self.client.get('/test_client/permission_protected_view_exception/')
self.assertEquals(response.status_code, 403)
def test_view_with_method_permissions(self):
"Request a page that is protected with a @permission_required method"