2012-07-03 09:50:40 +00:00
|
|
|
from django.contrib.auth import authenticate
|
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django.contrib.auth.tokens import PasswordResetTokenGenerator
|
|
|
|
from django.contrib.auth.views import (
|
2015-01-28 12:35:27 +00:00
|
|
|
password_change, password_change_done, password_reset,
|
|
|
|
password_reset_complete, password_reset_confirm, password_reset_done,
|
2012-07-03 09:50:40 +00:00
|
|
|
)
|
2015-01-28 12:35:27 +00:00
|
|
|
from django.test import RequestFactory, TestCase, override_settings
|
2012-07-03 09:50:40 +00:00
|
|
|
from django.utils.encoding import force_bytes, force_text
|
|
|
|
from django.utils.http import urlsafe_base64_encode
|
|
|
|
|
|
|
|
|
2016-02-05 20:56:52 +00:00
|
|
|
@override_settings(ROOT_URLCONF='auth_tests.urls')
|
2012-07-03 09:50:40 +00:00
|
|
|
class AuthTemplateTests(TestCase):
|
|
|
|
|
|
|
|
def test_titles(self):
|
|
|
|
rf = RequestFactory()
|
|
|
|
user = User.objects.create_user('jsmith', 'jsmith@example.com', 'pass')
|
|
|
|
user = authenticate(username=user.username, password='pass')
|
|
|
|
request = rf.get('/somepath/')
|
|
|
|
request.user = user
|
|
|
|
|
|
|
|
response = password_reset(request, post_reset_redirect='dummy/')
|
|
|
|
self.assertContains(response, '<title>Password reset</title>')
|
|
|
|
self.assertContains(response, '<h1>Password reset</h1>')
|
|
|
|
|
|
|
|
response = password_reset_done(request)
|
2014-11-15 16:05:24 +00:00
|
|
|
self.assertContains(response, '<title>Password reset sent</title>')
|
|
|
|
self.assertContains(response, '<h1>Password reset sent</h1>')
|
2012-07-03 09:50:40 +00:00
|
|
|
|
|
|
|
# password_reset_confirm invalid token
|
|
|
|
response = password_reset_confirm(request, uidb64='Bad', token='Bad', post_reset_redirect='dummy/')
|
|
|
|
self.assertContains(response, '<title>Password reset unsuccessful</title>')
|
|
|
|
self.assertContains(response, '<h1>Password reset unsuccessful</h1>')
|
|
|
|
|
|
|
|
# password_reset_confirm valid token
|
|
|
|
default_token_generator = PasswordResetTokenGenerator()
|
|
|
|
token = default_token_generator.make_token(user)
|
|
|
|
uidb64 = force_text(urlsafe_base64_encode(force_bytes(user.pk)))
|
|
|
|
response = password_reset_confirm(request, uidb64, token, post_reset_redirect='dummy/')
|
|
|
|
self.assertContains(response, '<title>Enter new password</title>')
|
|
|
|
self.assertContains(response, '<h1>Enter new password</h1>')
|
|
|
|
|
|
|
|
response = password_reset_complete(request)
|
|
|
|
self.assertContains(response, '<title>Password reset complete</title>')
|
|
|
|
self.assertContains(response, '<h1>Password reset complete</h1>')
|
|
|
|
|
|
|
|
response = password_change(request, post_change_redirect='dummy/')
|
|
|
|
self.assertContains(response, '<title>Password change</title>')
|
|
|
|
self.assertContains(response, '<h1>Password change</h1>')
|
|
|
|
|
|
|
|
response = password_change_done(request)
|
|
|
|
self.assertContains(response, '<title>Password change successful</title>')
|
|
|
|
self.assertContains(response, '<h1>Password change successful</h1>')
|