From 242a216c1bfb45b58316f737a54fd6e8c1b0c30b Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 5 Dec 2017 14:48:36 +0000 Subject: [PATCH 1/2] Update error message about commas in placeholders MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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`. --- app/main/validators.py | 6 +++--- tests/app/main/test_validators.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/main/validators.py b/app/main/validators.py index e183f3d89..62b9c5501 100644 --- a/app/main/validators.py +++ b/app/main/validators.py @@ -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 can’t have commas in your fields'): + def __init__(self, message='You can’t 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) diff --git a/tests/app/main/test_validators.py b/tests/app/main/test_validators.py index 7c494312b..fec931640 100644 --- a/tests/app/main/test_validators.py +++ b/tests/app/main/test_validators.py @@ -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 can’t have commas in your fields' + assert str(error.value) == 'You can’t put commas inbetween double brackets' NoCommasInPlaceHolders()(None, _gen_mock_field('Hello ((name))')) From eef66b70de2efbdb0b9f84e751d3cad414c654aa Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 11 Dec 2017 10:50:55 +0000 Subject: [PATCH 2/2] =?UTF-8?q?Reword=20because=20=E2=80=98inbetween?= =?UTF-8?q?=E2=80=99=20isn=E2=80=99t=20a=20word?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/main/validators.py | 2 +- tests/app/main/test_validators.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/main/validators.py b/app/main/validators.py index 62b9c5501..709274dda 100644 --- a/app/main/validators.py +++ b/app/main/validators.py @@ -45,7 +45,7 @@ class ValidGovEmail: class NoCommasInPlaceHolders: - def __init__(self, message='You can’t put commas inbetween double brackets'): + def __init__(self, message='You can’t put commas between double brackets'): self.message = message def __call__(self, form, field): diff --git a/tests/app/main/test_validators.py b/tests/app/main/test_validators.py index fec931640..d2b5fe574 100644 --- a/tests/app/main/test_validators.py +++ b/tests/app/main/test_validators.py @@ -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 can’t put commas inbetween double brackets' + assert str(error.value) == 'You can’t put commas between double brackets' NoCommasInPlaceHolders()(None, _gen_mock_field('Hello ((name))'))