Fixed #16789 -- Added names to URLs in convenience contrib.auth urls.py.

Thanks wim AT go2people DOT nl for the report, cmheisel for the patch and
fcurella for reviewing it.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16901 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Ramiro Morales 2011-09-24 19:48:27 +00:00
parent ce9e3b4e97
commit 4c457bca85
4 changed files with 68 additions and 14 deletions

View File

@ -13,7 +13,7 @@ from django.contrib.auth.tests.management import GetDefaultUsernameTestCase
from django.contrib.auth.tests.models import ProfileTestCase from django.contrib.auth.tests.models import ProfileTestCase
from django.contrib.auth.tests.signals import SignalTestCase from django.contrib.auth.tests.signals import SignalTestCase
from django.contrib.auth.tests.tokens import TokenGeneratorTest from django.contrib.auth.tests.tokens import TokenGeneratorTest
from django.contrib.auth.tests.views import (PasswordResetTest, from django.contrib.auth.tests.views import (AuthViewNamedURLTests, PasswordResetTest,
ChangePasswordTest, LoginTest, LogoutTest, LoginURLSettings) ChangePasswordTest, LoginTest, LogoutTest, LoginURLSettings)
# The password for the fixture data users is 'password' # The password for the fixture data users is 'password'

View File

@ -8,11 +8,13 @@ from django.contrib.auth import SESSION_KEY, REDIRECT_FIELD_NAME
from django.contrib.auth.forms import AuthenticationForm from django.contrib.auth.forms import AuthenticationForm
from django.contrib.sites.models import Site, RequestSite from django.contrib.sites.models import Site, RequestSite
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.urlresolvers import NoReverseMatch
from django.test import TestCase from django.test import TestCase
from django.core import mail from django.core import mail
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.http import QueryDict from django.http import QueryDict
class AuthViewsTestCase(TestCase): class AuthViewsTestCase(TestCase):
""" """
Helper base class for all the follow test cases. Helper base class for all the follow test cases.
@ -45,6 +47,32 @@ class AuthViewsTestCase(TestCase):
self.assertTrue(response['Location'].endswith(settings.LOGIN_REDIRECT_URL)) self.assertTrue(response['Location'].endswith(settings.LOGIN_REDIRECT_URL))
self.assertTrue(SESSION_KEY in self.client.session) self.assertTrue(SESSION_KEY in self.client.session)
class AuthViewNamedURLTests(AuthViewsTestCase):
urls = 'django.contrib.auth.urls'
def test_named_urls(self):
"Named URLs should be reversible"
expected_named_urls = [
('login', [], {}),
('logout', [], {}),
('password_change', [], {}),
('password_change_done', [], {}),
('password_reset', [], {}),
('password_reset_done', [], {}),
('password_reset_confirm', [], {
'uidb36': 'aaaaaaa',
'token': '1111-aaaaa',
}),
('password_reset_complete', [], {}),
]
for name, args, kwargs in expected_named_urls:
try:
reverse(name, args=args, kwargs=kwargs)
except NoReverseMatch:
self.fail("Reversal of url named '%s' failed with NoReverseMatch" % name)
class PasswordResetTest(AuthViewsTestCase): class PasswordResetTest(AuthViewsTestCase):
def test_email_not_found(self): def test_email_not_found(self):

View File

@ -1,17 +1,19 @@
# These URLs are normally mapped to /admin/urls.py. This URLs file is # The views used below are normally mapped in django.contrib.admin.urls.py
# provided as a convenience to those who want to deploy these URLs elsewhere. # This URLs file is used to provide a reliable view deployment for test purposes.
# This file is also used to provide a reliable view deployment for test purposes. # It is also provided as a convenience to those who want to deploy these URLs
# elsewhere.
from django.conf.urls import patterns from django.conf.urls import patterns, url
urlpatterns = patterns('', urlpatterns = patterns('',
(r'^login/$', 'django.contrib.auth.views.login'), url(r'^login/$', 'django.contrib.auth.views.login', name='login'),
(r'^logout/$', 'django.contrib.auth.views.logout'), url(r'^logout/$', 'django.contrib.auth.views.logout', name='logout'),
(r'^password_change/$', 'django.contrib.auth.views.password_change'), url(r'^password_change/$', 'django.contrib.auth.views.password_change', name='password_change'),
(r'^password_change/done/$', 'django.contrib.auth.views.password_change_done'), url(r'^password_change/done/$', 'django.contrib.auth.views.password_change_done', name='password_change_done'),
(r'^password_reset/$', 'django.contrib.auth.views.password_reset'), url(r'^password_reset/$', 'django.contrib.auth.views.password_reset', name='password_reset'),
(r'^password_reset/done/$', 'django.contrib.auth.views.password_reset_done'), url(r'^password_reset/done/$', 'django.contrib.auth.views.password_reset_done', name='password_reset_done'),
(r'^reset/(?P<uidb36>[0-9A-Za-z]{1,13})-(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', 'django.contrib.auth.views.password_reset_confirm'), url(r'^reset/(?P<uidb36>[0-9A-Za-z]{1,13})-(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete'), 'django.contrib.auth.views.password_reset_confirm',
name='password_reset_confirm'),
url(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete', name='password_reset_complete'),
) )

View File

@ -823,6 +823,11 @@ The login_required decorator
.. function:: views.login(request, [template_name, redirect_field_name, authentication_form]) .. function:: views.login(request, [template_name, redirect_field_name, authentication_form])
**URL name:** ``login``
See :doc:`the URL documentation </topics/http/urls>` for details on using
named URL patterns.
Here's what ``django.contrib.auth.views.login`` does: Here's what ``django.contrib.auth.views.login`` does:
* If called via ``GET``, it displays a login form that POSTs to the * If called via ``GET``, it displays a login form that POSTs to the
@ -938,6 +943,11 @@ includes a few other useful built-in views located in
Logs a user out. Logs a user out.
**URL name:** ``logout``
See :doc:`the URL documentation </topics/http/urls>` for details on using
named URL patterns.
**Optional arguments:** **Optional arguments:**
* ``next_page``: The URL to redirect to after logout. * ``next_page``: The URL to redirect to after logout.
@ -970,6 +980,8 @@ includes a few other useful built-in views located in
Logs a user out, then redirects to the login page. Logs a user out, then redirects to the login page.
**URL name:** No default URL provided
**Optional arguments:** **Optional arguments:**
* ``login_url``: The URL of the login page to redirect to. * ``login_url``: The URL of the login page to redirect to.
@ -979,6 +991,8 @@ includes a few other useful built-in views located in
Allows a user to change their password. Allows a user to change their password.
**URL name:** ``password_change``
**Optional arguments:** **Optional arguments:**
* ``template_name``: The full name of a template to use for * ``template_name``: The full name of a template to use for
@ -1003,6 +1017,8 @@ includes a few other useful built-in views located in
The page shown after a user has changed their password. The page shown after a user has changed their password.
**URL name:** ``password_change_done``
**Optional arguments:** **Optional arguments:**
* ``template_name``: The full name of a template to use. * ``template_name``: The full name of a template to use.
@ -1024,6 +1040,8 @@ includes a few other useful built-in views located in
will not be able to request a password reset to prevent misuse will not be able to request a password reset to prevent misuse
when using an external authentication source like LDAP. when using an external authentication source like LDAP.
**URL name:** ``password_reset``
**Optional arguments:** **Optional arguments:**
* ``template_name``: The full name of a template to use for * ``template_name``: The full name of a template to use for
@ -1099,6 +1117,8 @@ includes a few other useful built-in views located in
password. This view is called by default if the :func:`password_reset` view password. This view is called by default if the :func:`password_reset` view
doesn't have an explicit ``post_reset_redirect`` URL set. doesn't have an explicit ``post_reset_redirect`` URL set.
**URL name:** ``password_reset_done``
**Optional arguments:** **Optional arguments:**
* ``template_name``: The full name of a template to use. * ``template_name``: The full name of a template to use.
@ -1109,6 +1129,8 @@ includes a few other useful built-in views located in
Presents a form for entering a new password. Presents a form for entering a new password.
**URL name:** ``password_reset_confirm``
**Optional arguments:** **Optional arguments:**
* ``uidb36``: The user's id encoded in base 36. Defaults to ``None``. * ``uidb36``: The user's id encoded in base 36. Defaults to ``None``.
@ -1142,6 +1164,8 @@ includes a few other useful built-in views located in
Presents a view which informs the user that the password has been Presents a view which informs the user that the password has been
successfully changed. successfully changed.
**URL name:** ``password_reset_complete``
**Optional arguments:** **Optional arguments:**
* ``template_name``: The full name of a template to display the view. * ``template_name``: The full name of a template to display the view.