def test_post_password_form_with_invalid_data_does_not_change_password( self, invalid_form, pyramid_request, user_password_service): controller = views.AccountController(pyramid_request) controller.forms['password'] = invalid_form() controller.post_password_form() assert not user_password_service.update_password.called
def test_get_returns_empty_string_if_email_not_set(self, pyramid_request): pyramid_request.user = mock.Mock() pyramid_request.create_form.return_value = mock.Mock() user = pyramid_request.user user.email = None result = views.AccountController(pyramid_request).get() assert result["email"] == ""
def test_get_returns_email_if_set(self, pyramid_request): pyramid_request.user = mock.Mock() pyramid_request.create_form.return_value = mock.Mock() user = pyramid_request.user user.email = "*****@*****.**" result = views.AccountController(pyramid_request).get() assert result["email"] == "*****@*****.**"
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
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'
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.user.email == "new_email_address"
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')
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')
def test_post_password_form_with_valid_data_changes_password( self, form_validating_to, pyramid_request, user_password_service): controller = views.AccountController(pyramid_request) controller.forms['password'] = form_validating_to( {'new_password': '******'}) controller.post_password_form() user_password_service.update_password.assert_called_once_with( pyramid_request.user, 'my_new_password')
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(), }
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.user.email, "email_form": controller.forms["email"].render(), "password_form": controller.forms["password"].render(), }