Example #1
0
    def test_post_email_form_with_invalid_data_does_not_change_email(
            self, invalid_form, pyramid_request):
        controller = views.AccountController(pyramid_request)
        controller.forms['email'] = invalid_form()
        original_email = pyramid_request.authenticated_user.email

        controller.post_email_form()

        assert pyramid_request.authenticated_user.email == original_email
Example #2
0
    def test_post_email_form_with_valid_data_changes_email(
            self, form_validating_to, pyramid_request):
        controller = views.AccountController(pyramid_request)
        controller.forms['email'] = form_validating_to(
            {'email': 'new_email_address'})

        controller.post_email_form()

        assert pyramid_request.authenticated_user.email == 'new_email_address'
Example #3
0
    def test_post_password_form_with_invalid_data_does_not_change_password(
            self, invalid_form, pyramid_request):
        user = pyramid_request.authenticated_user
        user.password = '******'
        controller = views.AccountController(pyramid_request)
        controller.forms['password'] = invalid_form()

        controller.post_password_form()

        assert user.check_password('original password')
Example #4
0
    def test_post_password_form_with_valid_data_changes_password(
            self, form_validating_to, pyramid_request):
        controller = views.AccountController(pyramid_request)
        controller.forms['password'] = form_validating_to(
            {'new_password': '******'})

        controller.post_password_form()

        assert pyramid_request.authenticated_user.check_password(
            'my_new_password')
Example #5
0
    def test_post_password_form_with_invalid_data_returns_template_data(
            self, invalid_form, pyramid_request):
        controller = views.AccountController(pyramid_request)
        controller.forms['password'] = invalid_form()

        result = controller.post_password_form()

        assert result == {
            'email': pyramid_request.authenticated_user.email,
            'email_form': controller.forms['email'].render(),
            'password_form': controller.forms['password'].render(),
        }