示例#1
0
    def test_update_password_auth_backend(self):
        """Testing sandboxing of AuthBackend.update_password."""
        form = ChangePasswordForm(page=None, request=self.request,
                                  user=self.user)
        form.cleaned_data = {
            'old_password': self.user.password,
            'password1': 'password1',
            'password2': 'password1',
        }

        self.spy_on(SandboxAuthBackend.update_password)

        form.save()
        self.assertTrue(SandboxAuthBackend.update_password.called)
示例#2
0
    def test_authenticate_auth_backend(self):
        """Testing sandboxing of AuthBackend.authenticate."""
        form = ChangePasswordForm(page=None, request=self.request,
                                  user=self.user)
        form.cleaned_data = {
            'old_password': self.user.password,
        }

        self.spy_on(SandboxAuthBackend.authenticate)

        self.assertRaisesMessage(
            ValidationError,
            'Unexpected error when validating the password. '
            'Please contact the administrator.',
            lambda: form.clean_old_password())
        self.assertTrue(SandboxAuthBackend.authenticate.called)
示例#3
0
    def test_clean_old_password_with_error_in_backend(self):
        """Testing ChangePasswordForm.clean_old_password with error in
        auth_backend.authenticate
        """
        form = ChangePasswordForm(page=None, request=self.request,
                                  user=self.user)
        form.cleaned_data = {
            'old_password': self.user.password,
        }

        self.spy_on(SandboxAuthBackend.authenticate)

        message = (
            'Unexpected error when validating the password. Please contact '
            'the administrator.'
        )

        with self.assertRaisesMessage(ValidationError, message):
            form.clean_old_password()

        self.assertTrue(SandboxAuthBackend.authenticate.called)
    def test_clean_old_password_with_error_in_backend(self):
        """Testing ChangePasswordForm.clean_old_password with error in
        auth_backend.authenticate
        """
        form = ChangePasswordForm(page=None, request=self.request,
                                  user=self.user)
        form.cleaned_data = {
            'old_password': self.user.password,
        }

        self.spy_on(SandboxAuthBackend.authenticate)

        message = (
            'Unexpected error when validating the password. Please contact '
            'the administrator.'
        )

        with self.assertRaisesMessage(ValidationError, message):
            form.clean_old_password()

        self.assertTrue(SandboxAuthBackend.authenticate.called)