Ticket #8402: 8402.add_password_change_tests_and_update_default_template_to_newforms.diff
File 8402.add_password_change_tests_and_update_default_template_to_newforms.diff, 6.2 KB (added by , 16 years ago) |
---|
-
django/contrib/admin/templates/registration/password_change_form.html
13 13 14 14 <form action="" method="post"> 15 15 16 {% if form.old_password.errors %}{{ form.old_password. html_error_list}}{% endif %}16 {% if form.old_password.errors %}{{ form.old_password.errors }}{% endif %} 17 17 <p class="aligned wide"><label for="id_old_password">{% trans 'Old password:' %}</label>{{ form.old_password }}</p> 18 {% if form.new_password1.errors %}{{ form.new_password1. html_error_list}}{% endif %}18 {% if form.new_password1.errors %}{{ form.new_password1.errors }}{% endif %} 19 19 <p class="aligned wide"><label for="id_new_password1">{% trans 'New password:' %}</label>{{ form.new_password1 }}</p> 20 {% if form.new_password2.errors %}{{ form.new_password2. html_error_list}}{% endif %}20 {% if form.new_password2.errors %}{{ form.new_password2.errors }}{% endif %} 21 21 <p class="aligned wide"><label for="id_new_password2">{% trans 'Confirm password:' %}</label>{{ form.new_password2 }}</p> 22 22 23 23 <p><input type="submit" value="{% trans 'Change my password' %}" /></p> -
django/contrib/auth/tests/views.py
1 1 2 import os 2 3 import re 4 5 from django.conf import settings 3 6 from django.contrib.auth.models import User 4 7 from django.test import TestCase 5 8 from django.core import mail … … 86 89 self.assertEquals(response.status_code, 200) 87 90 self.assert_("The two password fields didn't match" in response.content) 88 91 92 93 class ChangePasswordTest(TestCase): 94 fixtures = ['authtestdata.json'] 95 urls = 'django.contrib.auth.urls' 96 97 def setUp(self): 98 self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS 99 settings.TEMPLATE_DIRS = ( 100 os.path.join( 101 os.path.dirname(__file__), 102 'templates' 103 ) 104 ,) 105 106 def tearDown(self): 107 settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS 108 109 def login(self, password='password'): 110 response = self.client.post('/login/', { 111 'username': 'testclient', 112 'password': password 113 } 114 ) 115 self.assertEquals(response.status_code, 302) 116 self.assert_(response['Location'].endswith('/accounts/profile/')) 117 118 def fail_login(self, password='password'): 119 response = self.client.post('/login/', { 120 'username': 'testclient', 121 'password': password 122 } 123 ) 124 self.assertEquals(response.status_code, 200) 125 self.assert_("Please enter a correct username and password. Note that both fields are case-sensitive." in response.content) 126 127 def logout(self): 128 response = self.client.get('/logout/') 129 130 def test_password_change_fails_with_invalid_old_password(self): 131 self.login() 132 response = self.client.post('/password_change/', { 133 'old_password': 'donuts', 134 'new_password1': 'password1', 135 'new_password2': 'password1', 136 } 137 ) 138 self.assertEquals(response.status_code, 200) 139 self.assert_("Your old password was entered incorrectly. Please enter it again." in response.content) 140 141 def test_password_change_fails_with_mismatched_passwords(self): 142 self.login() 143 response = self.client.post('/password_change/', { 144 'old_password': 'password', 145 'new_password1': 'password1', 146 'new_password2': 'donuts', 147 } 148 ) 149 self.assertEquals(response.status_code, 200) 150 self.assert_("The two password fields didn't match." in response.content) 151 152 def test_password_change_succeeds(self): 153 self.login() 154 response = self.client.post('/password_change/', { 155 'old_password': 'password', 156 'new_password1': 'password1', 157 'new_password2': 'password1', 158 } 159 ) 160 self.assertEquals(response.status_code, 302) 161 self.assert_(response['Location'].endswith('/password_change/done/')) 162 self.fail_login() 163 self.login(password='password1') 164 -
django/contrib/auth/tests/__init__.py
1 1 from django.contrib.auth.tests.basic import BASIC_TESTS 2 from django.contrib.auth.tests.views import PasswordResetTest 2 from django.contrib.auth.tests.views import PasswordResetTest, ChangePasswordTest 3 3 from django.contrib.auth.tests.forms import FORM_TESTS 4 4 from django.contrib.auth.tests.tokens import TOKEN_GENERATOR_TESTS 5 5 6 # The password for the fixture data users is 'password' 7 6 8 __test__ = { 7 9 'BASIC_TESTS': BASIC_TESTS, 8 10 'PASSWORDRESET_TESTS': PasswordResetTest, 9 11 'FORM_TESTS': FORM_TESTS, 10 'TOKEN_GENERATOR_TESTS': TOKEN_GENERATOR_TESTS 12 'TOKEN_GENERATOR_TESTS': TOKEN_GENERATOR_TESTS, 13 'CHANGEPASSWORD_TESTS': ChangePasswordTest, 11 14 } -
django/contrib/auth/tests/templates/registration/login.html
1 {{ form.as_ul }} 2 No newline at end of file -
django/contrib/auth/urls.py
5 5 from django.conf.urls.defaults import * 6 6 7 7 urlpatterns = patterns('', 8 (r'^login/$', 'django.contrib.auth.views.login'), 8 9 (r'^logout/$', 'django.contrib.auth.views.logout'), 9 10 (r'^password_change/$', 'django.contrib.auth.views.password_change'), 10 11 (r'^password_change/done/$', 'django.contrib.auth.views.password_change_done'),