Fix and test redir to configurable view post change

This commit is contained in:
Eskil Heyn Olsen
2013-01-12 19:56:50 -08:00
parent 4f9e23e0bc
commit cca9298e74
4 changed files with 34 additions and 8 deletions
+1 -1
View File
@@ -200,7 +200,7 @@ class ResetPasswordForm(Form, NewPasswordFormMixin, PasswordConfirmFormMixin):
submit = SubmitField("Reset Password")
class ChangePasswordForm(Form, NextFormMixin, PasswordFormMixin):
class ChangePasswordForm(Form, PasswordFormMixin):
"""The default change password form"""
new_password = PasswordField("New Password",
@@ -6,7 +6,6 @@
{{ render_field_with_errors(change_password_form.password) }}
{{ render_field_with_errors(change_password_form.new_password) }}
{{ render_field_with_errors(change_password_form.new_password_confirm) }}
{{ render_field(change_password_form.next) }}
{{ render_field(change_password_form.submit) }}
</form>
+2
View File
@@ -296,6 +296,8 @@ def change_password():
change_user_password(current_user, form.new_password.data)
if request.json is None:
do_flash(*get_message('PASSWORD_CHANGE'))
return redirect(get_url(_security.post_change_view) or
get_url(_security.post_login_view))
if request.json:
return _render_json(form)
+31 -6
View File
@@ -321,8 +321,8 @@ class ExpiredResetPasswordTest(SecurityTest):
class ChangePasswordTest(SecurityTest):
AUTH_CONFIG = {
'SECURITY_RECOVERABLE': True,
'SECURITY_CHANGEABLE': True,
'SECURITY_POST_CHANGE_VIEW': '/',
}
def test_change_password(self):
@@ -362,12 +362,37 @@ class ChangePasswordTest(SecurityTest):
def test_change_password_success(self):
self.authenticate()
r = self.client.post('/change', data={
'password': 'password',
'new_password': 'newpassword',
'new_password_confirm': 'newpassword'
}, follow_redirects=True)
with self.app.extensions['mail'].record_messages() as outbox:
r = self.client.post('/change', data={
'password': 'password',
'new_password': 'newpassword',
'new_password_confirm': 'newpassword'
}, follow_redirects=True)
self.assertIn('You successfully changed your password', r.data)
self.assertIn('Home Page', r.data)
self.assertEqual(len(outbox), 1)
self.assertIn("Your password has been changed", outbox[0].html)
self.assertIn("/reset", outbox[0].html)
class ChangePasswordPostViewTest(SecurityTest):
AUTH_CONFIG = {
'SECURITY_CHANGEABLE': True,
'SECURITY_POST_CHANGE_VIEW': '/profile',
}
def test_change_password_success(self):
self.authenticate()
r = self.client.post('/change', data={
'password': 'password',
'new_password': 'newpassword',
'new_password_confirm': 'newpassword'
}, follow_redirects=True)
self.assertIn('Profile Page', r.data)
class TrackableTests(SecurityTest):