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
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'}
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)
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")
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')
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)
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")
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')
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")
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()