Correct testing of password set

This commit is contained in:
Oliver Falk
2018-05-14 12:12:31 +02:00
parent 5e0134244f
commit 87664d0ea8
2 changed files with 16 additions and 7 deletions

View File

@@ -11,7 +11,7 @@ from ivatar import settings
from ivatar.ivataraccount.forms import MAX_NUM_UNCONFIRMED_EMAILS_DEFAULT
from django.contrib.auth.models import User
from django.contrib.auth import authenticate
from ivatar.utils import random_string
from ivatar.ivataraccount.models import Photo
@@ -92,12 +92,23 @@ class Tester(TestCase):
self.password = random_string()
response = self.client.post(
reverse('password_set'), {
'password1': self.password,
'password2': self.password,
'new_password1': self.password,
'new_password2': self.password,
},
follow=True,
)
self.assertEqual(response.status_code, 200, 'cannot change password?')
self.assertEqual(str(list(response.context[0]['messages'])[0]),
'password changed successfully - please login again', 'password change not successful?')
self.assertIsNotNone(authenticate(
username=self.username,
password=self.password,
), 'cannot authenticate with new password!?')
self.login()
response = self.client.get(reverse('profile'))
self.assertEqual(response.context[0]['user'].is_anonymous, False)
def test_add_email(self):

View File

@@ -43,15 +43,13 @@ class CreateView(SuccessMessageMixin, FormView):
login(self.request, user)
return HttpResponseRedirect(reverse_lazy('profile'))
else:
return HttpResponseRedirect(reverse_lazy('login'))
return super().form_valid(form)
return HttpResponseRedirect(reverse_lazy('login')) # noqa
@method_decorator(login_required, name='dispatch')
class PasswordSetView(SuccessMessageMixin, FormView):
template_name = 'password_change.html'
form_class = SetPasswordForm
success_message = _('password changed successfully')
success_message = _('password changed successfully - please login again')
success_url = reverse_lazy('profile')
def get_form_kwargs(self):