Test for specific error messages

This commit:
- improves the tests to check for specific error messages, rather than just
  pass/fail
- makes the error messages more human, and more suggestive of what the user
  needs to do to fix the error
This commit is contained in:
Chris Hill-Scott
2016-01-12 20:55:46 +00:00
parent faa3b9ca7c
commit 791324588b
2 changed files with 54 additions and 47 deletions

View File

@@ -37,10 +37,10 @@ class UKMobileNumber(StringField):
if self.data.startswith('+'):
self.data = self.data[1:]
if not sum([
if not sum(
self.data.startswith(prefix) for prefix in ['07', '447', '4407', '00447']
]):
raise ValidationError('Must be a mobile number')
):
raise ValidationError('Must be a UK mobile number (eg 07700 900460)')
for digit in self.data:
try:
@@ -54,7 +54,7 @@ class UKMobileNumber(StringField):
raise ValidationError('Too many digits')
if len(self.data) < 9:
raise ValidationError('Too few digits')
raise ValidationError('Not enough digits')
def post_validate(self, form, validation_stopped):