mirror of
https://git.linux-kernel.at/oliver/ivatar.git
synced 2025-11-15 20:48:02 +00:00
Correct testing of password set
This commit is contained in:
@@ -11,7 +11,7 @@ from ivatar import settings
|
|||||||
from ivatar.ivataraccount.forms import MAX_NUM_UNCONFIRMED_EMAILS_DEFAULT
|
from ivatar.ivataraccount.forms import MAX_NUM_UNCONFIRMED_EMAILS_DEFAULT
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
from django.contrib.auth import authenticate
|
||||||
from ivatar.utils import random_string
|
from ivatar.utils import random_string
|
||||||
from ivatar.ivataraccount.models import Photo
|
from ivatar.ivataraccount.models import Photo
|
||||||
|
|
||||||
@@ -92,12 +92,23 @@ class Tester(TestCase):
|
|||||||
self.password = random_string()
|
self.password = random_string()
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
reverse('password_set'), {
|
reverse('password_set'), {
|
||||||
'password1': self.password,
|
'new_password1': self.password,
|
||||||
'password2': self.password,
|
'new_password2': self.password,
|
||||||
},
|
},
|
||||||
follow=True,
|
follow=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 200, 'cannot change password?')
|
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)
|
self.assertEqual(response.context[0]['user'].is_anonymous, False)
|
||||||
|
|
||||||
def test_add_email(self):
|
def test_add_email(self):
|
||||||
|
|||||||
@@ -43,15 +43,13 @@ class CreateView(SuccessMessageMixin, FormView):
|
|||||||
login(self.request, user)
|
login(self.request, user)
|
||||||
return HttpResponseRedirect(reverse_lazy('profile'))
|
return HttpResponseRedirect(reverse_lazy('profile'))
|
||||||
else:
|
else:
|
||||||
return HttpResponseRedirect(reverse_lazy('login'))
|
return HttpResponseRedirect(reverse_lazy('login')) # noqa
|
||||||
|
|
||||||
return super().form_valid(form)
|
|
||||||
|
|
||||||
@method_decorator(login_required, name='dispatch')
|
@method_decorator(login_required, name='dispatch')
|
||||||
class PasswordSetView(SuccessMessageMixin, FormView):
|
class PasswordSetView(SuccessMessageMixin, FormView):
|
||||||
template_name = 'password_change.html'
|
template_name = 'password_change.html'
|
||||||
form_class = SetPasswordForm
|
form_class = SetPasswordForm
|
||||||
success_message = _('password changed successfully')
|
success_message = _('password changed successfully - please login again')
|
||||||
success_url = reverse_lazy('profile')
|
success_url = reverse_lazy('profile')
|
||||||
|
|
||||||
def get_form_kwargs(self):
|
def get_form_kwargs(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user