Ejemplo n.º 1
0
 def test_blank_data():
     form = ResetPasswordForm(data={})
     assert not form.is_valid()
     assert form.errors == {
         'password1': [_('This field is required.')],
         'password2': [_('This field is required.')],
     }
Ejemplo n.º 2
0
    def post(self, request, token, **kwargs):
        """Processes password reset."""
        context = {}
        try:
            pending_action = PendingAction.objects.get(
                token=token, category=ActionCategory.RESET_PASSWORD.value,
            )

            context['pending_action'] = pending_action
            user = pending_action.user

            form = ResetPasswordForm(data=request.POST)
            context['form'] = form

            if form.is_valid():
                password = form.cleaned_data['password1']
                user.set_password(password)
                user.save()
                pending_action.delete()
                return render(request, 'transactions/reset_password_done.html', context)

        except PendingAction.DoesNotExist:
            context['pending_action'] = None

        return render(request, 'transactions/reset_password.html', context)
Ejemplo n.º 3
0
 def test_valid_data():
     data = {
         'password1': 'anything',
         'password2': 'anything'
     }
     form = ResetPasswordForm(data=data)
     assert form.is_valid()
Ejemplo n.º 4
0
 def test_invalid_data():
     data = {
         'password1': 'anything',
         'password2': 'another_thing'
     }
     form = ResetPasswordForm(data=data)
     assert not form.is_valid()
     assert form.errors == {'password2': [_('Passwords Mismatch')]}