From f550699daffc318d7747e96da9da9a74d150dd5b Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Wed, 15 Feb 2017 16:21:14 +0000 Subject: [PATCH] fix non-gsm error message Use `it`/`they` depending on how many different characters you've used Also don't wrap the message with quotes, as it looks confusing and potentialy implies that you can't use apostrophes --- app/main/validators.py | 5 +++-- tests/app/main/test_validators.py | 25 +++++++++++++++++++------ tests/app/main/views/test_templates.py | 4 ++-- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/app/main/validators.py b/app/main/validators.py index 6b1b60374..42cd29c8d 100644 --- a/app/main/validators.py +++ b/app/main/validators.py @@ -58,7 +58,8 @@ class OnlyGSMCharacters: non_gsm_characters = sorted(list(get_non_gsm_compatible_characters(field.data))) if non_gsm_characters: raise ValidationError( - 'You can’t use {} in text messages. They won’t show up properly on everyone’s phones.'.format( - formatted_list(non_gsm_characters, conjunction='or') + 'You can’t use {} in text messages. {} won’t show up properly on everyone’s phones.'.format( + formatted_list(non_gsm_characters, conjunction='or', before_each='', after_each=''), + ('It' if len(non_gsm_characters) == 1 else 'They') ) ) diff --git a/tests/app/main/test_validators.py b/tests/app/main/test_validators.py index 432d73aac..93b007337 100644 --- a/tests/app/main/test_validators.py +++ b/tests/app/main/test_validators.py @@ -146,14 +146,27 @@ def test_gsm_character_validation(client, msg): OnlyGSMCharacters()(None, _gen_mock_field(msg)) -def test_non_gsm_character_validation(client): +@pytest.mark.parametrize('data, err_msg', [ + ( + '∆ abc 📲 def 📵 ghi', + ( + 'You can’t use ∆, 📲 or 📵 in text messages. ' + 'They won’t show up properly on everyone’s phones.' + ) + ), + ( + '📵', + ( + 'You can’t use 📵 in text messages. ' + 'It won’t show up properly on everyone’s phones.' + ) + ), +]) +def test_non_gsm_character_validation(data, err_msg, client): with pytest.raises(ValidationError) as error: - OnlyGSMCharacters()(None, _gen_mock_field('∆ abc 📲 def 📵 ghi')) + OnlyGSMCharacters()(None, _gen_mock_field(data)) - assert str(error.value) == ( - 'You can’t use ‘∆’, ‘📲’ or ‘📵’ in text messages. ' - 'They won’t show up properly on everyone’s phones.' - ) + assert str(error.value) == err_msg def test_sms_sender_form_validation( diff --git a/tests/app/main/views/test_templates.py b/tests/app/main/views/test_templates.py index 69c5eaf3b..29b9173ee 100644 --- a/tests/app/main/views/test_templates.py +++ b/tests/app/main/views/test_templates.py @@ -670,7 +670,7 @@ def test_should_not_create_sms_template_with_emoji( ), data=data) assert resp.status_code == 200 - assert "You can’t use ‘🍜’ in text messages." in resp.get_data(as_text=True) + assert "You can’t use 🍜 in text messages." in resp.get_data(as_text=True) def test_should_not_update_sms_template_with_emoji( @@ -694,7 +694,7 @@ def test_should_not_update_sms_template_with_emoji( template_id=fake_uuid), data=data) assert resp.status_code == 200 - assert "You can’t use ‘🍔’ in text messages." in resp.get_data(as_text=True) + assert "You can’t use 🍔 in text messages." in resp.get_data(as_text=True) def test_should_create_sms_template_without_downgrading_unicode_characters(