Skip to content

Commit

Permalink
Fixed #13304 -- Updated auth decorators so they can be used with call…
Browse files Browse the repository at this point in the history
…able classes. Thanks to Horst Gutmann for the report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12938 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
freakboy3742 committed Apr 9, 2010
1 parent 736b751 commit 056c940
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
3 changes: 2 additions & 1 deletion django/contrib/auth/decorators.py
Expand Up @@ -5,6 +5,7 @@

from django.contrib.auth import REDIRECT_FIELD_NAME
from django.http import HttpResponseRedirect
from django.utils.decorators import available_attrs
from django.utils.http import urlquote


Expand All @@ -25,7 +26,7 @@ def _wrapped_view(request, *args, **kwargs):
path = urlquote(request.get_full_path())
tup = login_url, redirect_field_name, path
return HttpResponseRedirect('%s?%s=%s' % tup)
return wraps(view_func)(_wrapped_view)
return wraps(view_func, assigned=available_attrs(view_func))(_wrapped_view)
return decorator


Expand Down
9 changes: 5 additions & 4 deletions django/contrib/auth/tests/__init__.py
@@ -1,12 +1,13 @@
from django.contrib.auth.tests.auth_backends import BackendTest, RowlevelBackendTest, AnonymousUserBackendTest, NoAnonymousUserBackendTest
from django.contrib.auth.tests.basic import BASIC_TESTS
from django.contrib.auth.tests.views \
import PasswordResetTest, ChangePasswordTest, LoginTest, LogoutTest
from django.contrib.auth.tests.decorators import LoginRequiredTestCase
from django.contrib.auth.tests.forms import FORM_TESTS
from django.contrib.auth.tests.remote_user \
import RemoteUserTest, RemoteUserNoCreateTest, RemoteUserCustomTest
from django.contrib.auth.tests.auth_backends import BackendTest, RowlevelBackendTest, AnonymousUserBackendTest, NoAnonymousUserBackendTest
from django.contrib.auth.tests.tokens import TOKEN_GENERATOR_TESTS
from django.contrib.auth.tests.models import ProfileTestCase
from django.contrib.auth.tests.tokens import TOKEN_GENERATOR_TESTS
from django.contrib.auth.tests.views \
import PasswordResetTest, ChangePasswordTest, LoginTest, LogoutTest

# The password for the fixture data users is 'password'

Expand Down
25 changes: 25 additions & 0 deletions django/contrib/auth/tests/decorators.py
@@ -0,0 +1,25 @@
from unittest import TestCase

from django.contrib.auth.decorators import login_required


class LoginRequiredTestCase(TestCase):
"""
Tests the login_required decorators
"""
def testCallable(self):
"""
Check that login_required is assignable to callable objects.
"""
class CallableView(object):
def __call__(self, *args, **kwargs):
pass
login_required(CallableView())

def testView(self):
"""
Check that login_required is assignable to normal views.
"""
def normal_view(request):
pass
login_required(normal_view)

0 comments on commit 056c940

Please sign in to comment.