diff --git a/django/contrib/auth/decorators.py b/django/contrib/auth/decorators.py
index f3f7f53..d1d69cd 100644
|
a
|
b
|
|
| 1 | 1 | from django.contrib.auth import REDIRECT_FIELD_NAME |
| 2 | | from django.http import HttpResponseRedirect |
| | 2 | from django.http import HttpResponseRedirect, HttpResponseForbidden |
| 3 | 3 | from django.utils.http import urlquote |
| 4 | 4 | |
| 5 | 5 | def user_passes_test(test_func, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME): |
| … |
… |
class _CheckLogin(object):
|
| 60 | 60 | def __call__(self, request, *args, **kwargs): |
| 61 | 61 | if self.test_func(request.user): |
| 62 | 62 | return self.view_func(request, *args, **kwargs) |
| 63 | | path = urlquote(request.get_full_path()) |
| 64 | | tup = self.login_url, self.redirect_field_name, path |
| 65 | | return HttpResponseRedirect('%s?%s=%s' % tup) |
| | 63 | elif not request.user.is_authenticated(): |
| | 64 | path = urlquote(request.get_full_path()) |
| | 65 | tup = self.login_url, self.redirect_field_name, path |
| | 66 | return HttpResponseRedirect('%s?%s=%s' % tup) |
| | 67 | else: |
| | 68 | return HttpResponseForbidden('<h1>Permission denied</h1>') |
| | 69 | |
diff --git a/django/test/testcases.py b/django/test/testcases.py
index 1d65ee1..04246af 100644
|
a
|
b
|
class TestCase(unittest.TestCase):
|
| 101 | 101 | " (expected %d)") % |
| 102 | 102 | (path, redirect_response.status_code, target_status_code)) |
| 103 | 103 | |
| | 104 | def assertStatusCode(self, response, status_code): |
| | 105 | """Asserts that a response had a scecific status code.""" |
| | 106 | self.assertEqual(response.status_code, status_code, |
| | 107 | ("Wrong status code: Response code was %d" |
| | 108 | " (expected %d)" % (response.status_code, status_code))) |
| | 109 | |
| 104 | 110 | def assertContains(self, response, text, count=None, status_code=200): |
| 105 | 111 | """ |
| 106 | 112 | Asserts that a response indicates that a page was retreived |
diff --git a/tests/modeltests/test_client/models.py b/tests/modeltests/test_client/models.py
index 1a6e1bd..fb48e52 100644
|
a
|
b
|
class ClientTest(TestCase):
|
| 325 | 325 | login = self.client.login(username='testclient', password='password') |
| 326 | 326 | self.failUnless(login, 'Could not log in') |
| 327 | 327 | |
| 328 | | # Log in with wrong permissions. Should result in 302. |
| | 328 | # Log in with wrong permissions. Should result in 403 (Forbidden). |
| 329 | 329 | response = self.client.get('/test_client/permission_protected_view/') |
| 330 | | self.assertRedirects(response, 'http://testserver/accounts/login/?next=/test_client/permission_protected_view/') |
| | 330 | self.assertStatusCode(response, 403) |
| 331 | 331 | |
| 332 | 332 | # TODO: Log in with right permissions and request the page again |
| 333 | 333 | |
| … |
… |
class ClientTest(TestCase):
|
| 342 | 342 | login = self.client.login(username='testclient', password='password') |
| 343 | 343 | self.failUnless(login, 'Could not log in') |
| 344 | 344 | |
| 345 | | # Log in with wrong permissions. Should result in 302. |
| | 345 | # Log in with wrong permissions. Should result in 403 (Forbidden). |
| 346 | 346 | response = self.client.get('/test_client/permission_protected_method_view/') |
| 347 | | self.assertRedirects(response, 'http://testserver/accounts/login/?next=/test_client/permission_protected_method_view/') |
| | 347 | self.assertStatusCode(response, 403) |
| 348 | 348 | |
| 349 | 349 | # TODO: Log in with right permissions and request the page again |
| 350 | 350 | |