Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 authored September 24, 2011
2  django/contrib/auth/tests/__init__.py
@@ -13,7 +13,7 @@
13 13
 from django.contrib.auth.tests.models import ProfileTestCase
14 14
 from django.contrib.auth.tests.signals import SignalTestCase
15 15
 from django.contrib.auth.tests.tokens import TokenGeneratorTest
16  
-from django.contrib.auth.tests.views import (PasswordResetTest,
  16
+from django.contrib.auth.tests.views import (AuthViewNamedURLTests, PasswordResetTest,
17 17
     ChangePasswordTest, LoginTest, LogoutTest, LoginURLSettings)
18 18
 
19 19
 # The password for the fixture data users is 'password'
28  django/contrib/auth/tests/views.py
@@ -8,11 +8,13 @@
8 8
 from django.contrib.auth.forms import AuthenticationForm
9 9
 from django.contrib.sites.models import Site, RequestSite
10 10
 from django.contrib.auth.models import User
  11
+from django.core.urlresolvers import NoReverseMatch
11 12
 from django.test import TestCase
12 13
 from django.core import mail
13 14
 from django.core.urlresolvers import reverse
14 15
 from django.http import QueryDict
15 16
 
  17
+
16 18
 class AuthViewsTestCase(TestCase):
17 19
     """
18 20
     Helper base class for all the follow test cases.
@@ -45,6 +47,32 @@ def login(self, password='password'):
45 47
         self.assertTrue(response['Location'].endswith(settings.LOGIN_REDIRECT_URL))
46 48
         self.assertTrue(SESSION_KEY in self.client.session)
47 49
 
  50
+
  51
+class AuthViewNamedURLTests(AuthViewsTestCase):
  52
+    urls = 'django.contrib.auth.urls'
  53
+
  54
+    def test_named_urls(self):
  55
+        "Named URLs should be reversible"
  56
+        expected_named_urls = [
  57
+            ('login', [], {}),
  58
+            ('logout', [], {}),
  59
+            ('password_change', [], {}),
  60
+            ('password_change_done', [], {}),
  61
+            ('password_reset', [], {}),
  62
+            ('password_reset_done', [], {}),
  63
+            ('password_reset_confirm', [], {
  64
+                'uidb36': 'aaaaaaa',
  65
+                'token': '1111-aaaaa',
  66
+            }),
  67
+            ('password_reset_complete', [], {}),
  68
+        ]
  69
+        for name, args, kwargs in expected_named_urls:
  70
+            try:
  71
+                reverse(name, args=args, kwargs=kwargs)
  72
+            except NoReverseMatch:
  73
+                self.fail("Reversal of url named '%s' failed with NoReverseMatch" % name)
  74
+
  75
+
48 76
 class PasswordResetTest(AuthViewsTestCase):
49 77
 
50 78
     def test_email_not_found(self):
28  django/contrib/auth/urls.py
... ...
@@ -1,17 +1,19 @@
1  
-# These URLs are normally mapped to /admin/urls.py. This URLs file is
2  
-# provided as a convenience to those who want to deploy these URLs elsewhere.
3  
-# This file is also used to provide a reliable view deployment for test purposes.
  1
+# The views used below are normally mapped in django.contrib.admin.urls.py
  2
+# This URLs file is used to provide a reliable view deployment for test purposes.
  3
+# It is also provided as a convenience to those who want to deploy these URLs
  4
+# elsewhere.
4 5
 
5  
-from django.conf.urls import patterns
  6
+from django.conf.urls import patterns, url
6 7
 
7 8
 urlpatterns = patterns('',
8  
-    (r'^login/$', 'django.contrib.auth.views.login'),
9  
-    (r'^logout/$', 'django.contrib.auth.views.logout'),
10  
-    (r'^password_change/$', 'django.contrib.auth.views.password_change'),
11  
-    (r'^password_change/done/$', 'django.contrib.auth.views.password_change_done'),
12  
-    (r'^password_reset/$', 'django.contrib.auth.views.password_reset'),
13  
-    (r'^password_reset/done/$', 'django.contrib.auth.views.password_reset_done'),
14  
-    (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'),
15  
-    (r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete'),
  9
+    url(r'^login/$', 'django.contrib.auth.views.login', name='login'),
  10
+    url(r'^logout/$', 'django.contrib.auth.views.logout', name='logout'),
  11
+    url(r'^password_change/$', 'django.contrib.auth.views.password_change', name='password_change'),
  12
+    url(r'^password_change/done/$', 'django.contrib.auth.views.password_change_done', name='password_change_done'),
  13
+    url(r'^password_reset/$', 'django.contrib.auth.views.password_reset', name='password_reset'),
  14
+    url(r'^password_reset/done/$', 'django.contrib.auth.views.password_reset_done', name='password_reset_done'),
  15
+    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})/$',
  16
+        'django.contrib.auth.views.password_reset_confirm',
  17
+        name='password_reset_confirm'),
  18
+    url(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete', name='password_reset_complete'),
16 19
 )
17  
-
24  docs/topics/auth.txt
@@ -823,6 +823,11 @@ The login_required decorator
823 823
 
824 824
 .. function:: views.login(request, [template_name, redirect_field_name, authentication_form])
825 825
 
  826
+    **URL name:** ``login``
  827
+
  828
+    See :doc:`the URL documentation </topics/http/urls>` for details on using
  829
+    named URL patterns.
  830
+
826 831
     Here's what ``django.contrib.auth.views.login`` does:
827 832
 
828 833
         * 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
938 943
 
939 944
     Logs a user out.
940 945
 
  946
+    **URL name:** ``logout``
  947
+
  948
+    See :doc:`the URL documentation </topics/http/urls>` for details on using
  949
+    named URL patterns.
  950
+
941 951
     **Optional arguments:**
942 952
 
943 953
         * ``next_page``: The URL to redirect to after logout.
@@ -970,6 +980,8 @@ includes a few other useful built-in views located in
970 980
 
971 981
     Logs a user out, then redirects to the login page.
972 982
 
  983
+    **URL name:** No default URL provided
  984
+
973 985
     **Optional arguments:**
974 986
 
975 987
         * ``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
979 991
 
980 992
     Allows a user to change their password.
981 993
 
  994
+    **URL name:** ``password_change``
  995
+
982 996
     **Optional arguments:**
983 997
 
984 998
         * ``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
1003 1017
 
1004 1018
     The page shown after a user has changed their password.
1005 1019
 
  1020
+    **URL name:** ``password_change_done``
  1021
+
1006 1022
     **Optional arguments:**
1007 1023
 
1008 1024
         * ``template_name``: The full name of a template to use.
@@ -1024,6 +1040,8 @@ includes a few other useful built-in views located in
1024 1040
         will not be able to request a password reset to prevent misuse
1025 1041
         when using an external authentication source like LDAP.
1026 1042
 
  1043
+    **URL name:** ``password_reset``
  1044
+
1027 1045
     **Optional arguments:**
1028 1046
 
1029 1047
         * ``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
1099 1117
     password. This view is called by default if the :func:`password_reset` view
1100 1118
     doesn't have an explicit ``post_reset_redirect`` URL set.
1101 1119
 
  1120
+    **URL name:** ``password_reset_done``
  1121
+
1102 1122
     **Optional arguments:**
1103 1123
 
1104 1124
         * ``template_name``: The full name of a template to use.
@@ -1109,6 +1129,8 @@ includes a few other useful built-in views located in
1109 1129
 
1110 1130
     Presents a form for entering a new password.
1111 1131
 
  1132
+    **URL name:** ``password_reset_confirm``
  1133
+
1112 1134
     **Optional arguments:**
1113 1135
 
1114 1136
         * ``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
1142 1164
    Presents a view which informs the user that the password has been
1143 1165
    successfully changed.
1144 1166
 
  1167
+   **URL name:** ``password_reset_complete``
  1168
+
1145 1169
    **Optional arguments:**
1146 1170
 
1147 1171
        * ``template_name``: The full name of a template to display the view.

0 notes on commit 4c457bc

Please sign in to comment.
Something went wrong with that request. Please try again.