Skip to content

Commit

Permalink
Simplify and shorten validation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
eloquence committed Jul 16, 2020
1 parent fbacfad commit cbd233a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
10 changes: 4 additions & 6 deletions securedrop/journalist_app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@ def otp_secret_validation(form, field):
def minimum_length_validation(form, field):
if len(field.data) < Journalist.MIN_USERNAME_LEN:
raise ValidationError(
gettext('Field must be at least {min_chars} '
'characters long but only got '
'{num_chars}.'.format(
min_chars=Journalist.MIN_USERNAME_LEN,
num_chars=len(field.data))))
gettext('Must be at least {min_chars} '
'characters long.'
.format(min_chars=Journalist.MIN_USERNAME_LEN)))


def name_length_validation(form, field):
if len(field.data) > Journalist.MAX_NAME_LEN:
raise ValidationError(gettext(
'Field can not be more than {max_chars} characters.'
'Cannot be longer than {max_chars} characters.'
.format(max_chars=Journalist.MAX_NAME_LEN)))


Expand Down
6 changes: 3 additions & 3 deletions securedrop/tests/test_journalist.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ def test_admin_add_user_first_name_too_long_warning(journalist_app, test_admin):
password=VALID_PASSWORD,
is_admin=None))
text = resp.data.decode('utf-8')
assert 'Field can not be more than' in text
assert 'Cannot be longer than' in text


def test_admin_add_user_last_name_too_long_warning(journalist_app, test_admin):
Expand All @@ -795,7 +795,7 @@ def test_admin_add_user_last_name_too_long_warning(journalist_app, test_admin):
password=VALID_PASSWORD,
is_admin=None))
text = resp.data.decode('utf-8')
assert 'Field can not be more than' in text
assert 'Cannot be longer than' in text


def test_admin_edits_user_invalid_username(
Expand Down Expand Up @@ -1244,7 +1244,7 @@ def test_admin_add_user_too_short_username(journalist_app, test_admin):
password='pentagonpapers',
password_again='pentagonpapers',
is_admin=None))
msg = 'Field must be at least {} characters long'
msg = 'Must be at least {} characters long'
assert (msg.format(Journalist.MIN_USERNAME_LEN) in resp.data.decode('utf-8'))


Expand Down

0 comments on commit cbd233a

Please sign in to comment.