From 953be15d84ce2f71396a2310cacacd9dad6d4a48 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 4 Apr 2016 10:42:04 +0100 Subject: [PATCH] Make form error messages consistent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We were using a bunch of different styles for form error messages, including: - having the name of the field in the error, or not - can not/cannot/can’t (GDS content styleguide recommends using contractions) --- app/main/forms.py | 34 +++++++++++------------ tests/app/main/views/test_add_service.py | 2 +- tests/app/main/views/test_manage_users.py | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/app/main/forms.py b/app/main/forms.py index 9dd12c74a..9d400470b 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -21,7 +21,7 @@ from app.main.validators import (Blacklist, CsvFileValidator, ValidEmailDomainRe def email_address(label='Email address'): return EmailField(label, validators=[ Length(min=5, max=255), - DataRequired(message='Email cannot be empty'), + DataRequired(message='Can’t be empty'), Email(message='Enter a valid email address'), ValidEmailDomainRegex()]) @@ -37,35 +37,35 @@ class UKMobileNumber(TelField): def mobile_number(): return UKMobileNumber('Mobile phone number', - validators=[DataRequired(message='Cannot be empty')]) + validators=[DataRequired(message='Can’t be empty')]) def password(label='Create a password'): return PasswordField(label, - validators=[DataRequired(message='Password can not be empty'), - Length(10, 255, message='Password must be at least 10 characters'), + validators=[DataRequired(message='Can’t be empty'), + Length(10, 255, message='Must be at least 10 characters'), Blacklist(message='That password is blacklisted, too common')]) def sms_code(): verify_code = '^\d{5}$' return StringField('Text message code', - validators=[DataRequired(message='Text message confirmation code can not be empty'), + validators=[DataRequired(message='Can’t be empty'), Regexp(regex=verify_code, - message='Text message confirmation code must be 5 digits')]) + message='Must be 5 digits')]) def email_code(): verify_code = '^\d{5}$' return StringField("Email code", - validators=[DataRequired(message='Email confirmation code can not be empty'), - Regexp(regex=verify_code, message='Email confirmation code must be 5 digits')]) + validators=[DataRequired(message='Can’t be empty'), + Regexp(regex=verify_code, message='Must be 5 digits')]) class LoginForm(Form): email_address = StringField('Email address', validators=[ Length(min=5, max=255), - DataRequired(message='Email cannot be empty'), + DataRequired(message='Can’t be empty'), Email(message='Enter a valid email address') ]) password = PasswordField('Password', validators=[ @@ -76,7 +76,7 @@ class LoginForm(Form): class RegisterUserForm(Form): name = StringField('Full name', - validators=[DataRequired(message='Name can not be empty')]) + validators=[DataRequired(message='Can’t be empty')]) email_address = email_address() mobile_number = mobile_number() password = password() @@ -84,7 +84,7 @@ class RegisterUserForm(Form): class RegisterUserFromInviteForm(Form): name = StringField('Full name', - validators=[DataRequired(message='Name can not be empty')]) + validators=[DataRequired(message='Can’t be empty')]) mobile_number = mobile_number() password = password() service = HiddenField('service') @@ -108,7 +108,7 @@ class InviteUserForm(PermissionsForm): def validate_email_address(self, field): if field.data.lower() == self.invalid_email_address: - raise ValidationError("You can't send an invitation to yourself") + raise ValidationError("You can’t send an invitation to yourself") class TwoFactorForm(Form): @@ -149,7 +149,7 @@ class AddServiceForm(Form): name = StringField( 'Service name', validators=[ - DataRequired(message='Service name can’t be empty') + DataRequired(message='Can’t be empty') ] ) @@ -173,7 +173,7 @@ class ServiceNameForm(Form): name = StringField( u'New name', validators=[ - DataRequired(message='Service name can’t be empty') + DataRequired(message='Can’t be empty') ]) def validate_name(self, a): @@ -199,18 +199,18 @@ class ConfirmPasswordForm(Form): class SMSTemplateForm(Form): name = StringField( u'Template name', - validators=[DataRequired(message="Template name cannot be empty")]) + validators=[DataRequired(message="Can’t be empty")]) template_content = TextAreaField( u'Message content', - validators=[DataRequired(message="Template content cannot be empty")]) + validators=[DataRequired(message="Can’t be empty")]) class EmailTemplateForm(SMSTemplateForm): subject = StringField( u'Subject', - validators=[DataRequired(message="Subject cannot be empty")]) + validators=[DataRequired(message="Can’t be empty")]) class ForgotPasswordForm(Form): diff --git a/tests/app/main/views/test_add_service.py b/tests/app/main/views/test_add_service.py index d82fbd673..4162282fc 100644 --- a/tests/app/main/views/test_add_service.py +++ b/tests/app/main/views/test_add_service.py @@ -44,7 +44,7 @@ def test_should_return_form_errors_when_service_name_is_empty(app_, client.login(api_user_active, mocker) response = client.post(url_for('main.add_service'), data={}) assert response.status_code == 200 - assert 'Service name can’t be empty' in response.get_data(as_text=True) + assert 'Can’t be empty' in response.get_data(as_text=True) def test_should_return_form_errors_with_duplicate_service_name_regardless_of_case(app_, diff --git a/tests/app/main/views/test_manage_users.py b/tests/app/main/views/test_manage_users.py index 92c4f0686..a84169e3f 100644 --- a/tests/app/main/views/test_manage_users.py +++ b/tests/app/main/views/test_manage_users.py @@ -260,7 +260,7 @@ def test_user_cant_invite_themselves( page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') assert page.h1.string.strip() == 'Invite a team member' form_error = page.find('span', class_='error-message').string.strip() - assert form_error == "You can't send an invitation to yourself" + assert form_error == "You can’t send an invitation to yourself" assert not mock_create_invite.called