示例#1
0
    def test_post_creates_no_activations_when_validation_fails(
            self, activation_model, invalid_form, pyramid_request):
        controller = views.ForgotPasswordController(pyramid_request)
        controller.form = invalid_form()

        controller.post()

        assert activation_model.call_count == 0
示例#2
0
    def test_post_returns_form_when_validation_fails(self, invalid_form,
                                                     pyramid_request):
        controller = views.ForgotPasswordController(pyramid_request)
        controller.form = invalid_form()

        result = controller.post()

        assert result == {'form': 'invalid form'}
示例#3
0
    def test_post_redirects_on_success(self, factories, form_validating_to,
                                       pyramid_request):
        pyramid_request.registry.password_reset_serializer = FakeSerializer()
        user = factories.User(username='******', email='*****@*****.**')
        controller = views.ForgotPasswordController(pyramid_request)
        controller.form = form_validating_to({"user": user})

        result = controller.post()

        assert isinstance(result, httpexceptions.HTTPRedirection)
示例#4
0
    def test_post_generates_reset_link(self, reset_link, factories,
                                       form_validating_to, pyramid_request):
        pyramid_request.registry.password_reset_serializer = FakeSerializer()
        user = factories.User(username='******', email='*****@*****.**')
        controller = views.ForgotPasswordController(pyramid_request)
        controller.form = form_validating_to({"user": user})

        controller.post()

        reset_link.assert_called_with(pyramid_request, "faketoken")
示例#5
0
    def test_post_sends_mail(self, reset_password_email, factories,
                             form_validating_to, mailer, pyramid_request):
        pyramid_request.registry.password_reset_serializer = FakeSerializer()
        user = factories.User(username='******', email='*****@*****.**')
        controller = views.ForgotPasswordController(pyramid_request)
        controller.form = form_validating_to({"user": user})

        controller.post()

        mailer.send.delay.assert_called_once_with(['*****@*****.**'],
                                                  'Reset yer passwor!',
                                                  'HTML output', 'Text output')
示例#6
0
    def test_post_generates_mail(self, reset_password_email, activation_model,
                                 factories, form_validating_to,
                                 pyramid_request):
        pyramid_request.registry.password_reset_serializer = FakeSerializer()
        user = factories.User(username='******', email='*****@*****.**')
        controller = views.ForgotPasswordController(pyramid_request)
        controller.form = form_validating_to({"user": user})

        controller.post()

        reset_password_email.generate.assert_called_once_with(
            pyramid_request, user)
示例#7
0
    def test_post_generates_mail(self, reset_link, reset_mail,
                                 activation_model, factories,
                                 form_validating_to, pyramid_request):
        pyramid_request.registry.password_reset_serializer = FakeSerializer()
        user = factories.User(username='******', email='*****@*****.**')
        controller = views.ForgotPasswordController(pyramid_request)
        controller.form = form_validating_to({"user": user})
        reset_link.return_value = "http://example.com"
        reset_mail.return_value = {'recipients': [], 'subject': '', 'body': ''}

        controller.post()

        reset_mail.assert_called_with(user, "faketoken", "http://example.com")
示例#8
0
    def test_post_sends_mail(self, reset_mail, factories, form_validating_to,
                             mailer, pyramid_request):
        pyramid_request.registry.password_reset_serializer = FakeSerializer()
        user = factories.User(username='******', email='*****@*****.**')
        controller = views.ForgotPasswordController(pyramid_request)
        controller.form = form_validating_to({"user": user})
        reset_mail.return_value = {
            'recipients': ['*****@*****.**'],
            'subject': 'subject',
            'body': 'body'
        }

        controller.post()

        mailer.send.delay.assert_called_once_with(
            recipients=['*****@*****.**'], subject='subject', body='body')
示例#9
0
    def test_post_sends_mail(
        self,
        factories,
        form_validating_to,
        mailer,
        pyramid_request,
    ):
        pyramid_request.registry.password_reset_serializer = FakeSerializer()
        user = factories.User(username="******", email="*****@*****.**")
        controller = views.ForgotPasswordController(pyramid_request)
        controller.form = form_validating_to({"user": user})

        controller.post()

        mailer.send.delay.assert_called_once_with(["*****@*****.**"],
                                                  "Reset yer passwor!",
                                                  "HTML output", "Text output")
示例#10
0
    def test_get_redirects_when_logged_in(self, pyramid_config,
                                          pyramid_request):
        pyramid_config.testing_securitypolicy("acct:[email protected]")

        with pytest.raises(httpexceptions.HTTPFound):
            views.ForgotPasswordController(pyramid_request).get()