Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 4c457bca85b5410c47860ee4c5df0b47d48f2603 1 parent ce9e3b4
Ramiro Morales ramiro authored
2  django/contrib/auth/tests/__init__.py
View
@@ -13,7 +13,7 @@
from django.contrib.auth.tests.models import ProfileTestCase
from django.contrib.auth.tests.signals import SignalTestCase
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)
# The password for the fixture data users is 'password'
28 django/contrib/auth/tests/views.py
View
@@ -8,11 +8,13 @@
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.sites.models import Site, RequestSite
from django.contrib.auth.models import User
+from django.core.urlresolvers import NoReverseMatch
from django.test import TestCase
from django.core import mail
from django.core.urlresolvers import reverse
from django.http import QueryDict
+
class AuthViewsTestCase(TestCase):
"""
Helper base class for all the follow test cases.
@@ -45,6 +47,32 @@ def login(self, password='password'):
self.assertTrue(response['Location'].endswith(settings.LOGIN_REDIRECT_URL))
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):
def test_email_not_found(self):
28 django/contrib/auth/urls.py
View
@@ -1,17 +1,19 @@
-# These URLs are normally mapped to /admin/urls.py. This URLs file is
-# provided as a convenience to those who want to deploy these URLs elsewhere.
-# This file is also used to provide a reliable view deployment for test purposes.
+# The views used below are normally mapped in django.contrib.admin.urls.py
+# This URLs file is 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('',
- (r'^login/$', 'django.contrib.auth.views.login'),
- (r'^logout/$', 'django.contrib.auth.views.logout'),
- (r'^password_change/$', 'django.contrib.auth.views.password_change'),
- (r'^password_change/done/$', 'django.contrib.auth.views.password_change_done'),
- (r'^password_reset/$', 'django.contrib.auth.views.password_reset'),
- (r'^password_reset/done/$', 'django.contrib.auth.views.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'),
- (r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete'),
+ url(r'^login/$', 'django.contrib.auth.views.login', name='login'),
+ url(r'^logout/$', 'django.contrib.auth.views.logout', name='logout'),
+ url(r'^password_change/$', 'django.contrib.auth.views.password_change', name='password_change'),
+ url(r'^password_change/done/$', 'django.contrib.auth.views.password_change_done', name='password_change_done'),
+ url(r'^password_reset/$', 'django.contrib.auth.views.password_reset', name='password_reset'),
+ url(r'^password_reset/done/$', 'django.contrib.auth.views.password_reset_done', name='password_reset_done'),
+ 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})/$',
+ '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'),
)
-
24 docs/topics/auth.txt
View
@@ -823,6 +823,11 @@ The login_required decorator
.. 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:
* 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.
+ **URL name:** ``logout``
+
+ See :doc:`the URL documentation </topics/http/urls>` for details on using
+ named URL patterns.
+
**Optional arguments:**
* ``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.
+ **URL name:** No default URL provided
+
**Optional arguments:**
* ``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.
+ **URL name:** ``password_change``
+
**Optional arguments:**
* ``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.
+ **URL name:** ``password_change_done``
+
**Optional arguments:**
* ``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
when using an external authentication source like LDAP.
+ **URL name:** ``password_reset``
+
**Optional arguments:**
* ``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
doesn't have an explicit ``post_reset_redirect`` URL set.
+ **URL name:** ``password_reset_done``
+
**Optional arguments:**
* ``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.
+ **URL name:** ``password_reset_confirm``
+
**Optional arguments:**
* ``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
successfully changed.
+ **URL name:** ``password_reset_complete``
+
**Optional arguments:**
* ``template_name``: The full name of a template to display the view.
Please sign in to comment.
Something went wrong with that request. Please try again.