Update error message about commas in placeholders

We call the yellow things ‘double brackets’ on the frontend, not fields
or placeholders. This error message was a bit out of date.

Also refactored it to use the `Field` class; this code was probably
written before `Field` was factored out of `Template`.
This commit is contained in:
Chris Hill-Scott
2017-12-05 14:48:36 +00:00
parent 72dd0b369f
commit 242a216c1b
2 changed files with 4 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
from wtforms import ValidationError
from notifications_utils.template import Template
from notifications_utils.field import Field
from notifications_utils.gsm import get_non_gsm_compatible_characters
from app import formatted_list
@@ -45,11 +45,11 @@ class ValidGovEmail:
class NoCommasInPlaceHolders:
def __init__(self, message='You cant have commas in your fields'):
def __init__(self, message='You cant put commas inbetween double brackets'):
self.message = message
def __call__(self, form, field):
if ',' in ''.join(Template({'content': field.data}).placeholders):
if ',' in ''.join(Field(field.data).placeholders):
raise ValidationError(self.message)

View File

@@ -149,7 +149,7 @@ def test_for_commas_in_placeholders(
):
with pytest.raises(ValidationError) as error:
NoCommasInPlaceHolders()(None, _gen_mock_field('Hello ((name,date))'))
assert str(error.value) == 'You cant have commas in your fields'
assert str(error.value) == 'You cant put commas inbetween double brackets'
NoCommasInPlaceHolders()(None, _gen_mock_field('Hello ((name))'))