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
This commit is contained in:
Leo Hemsted
2017-02-15 16:21:14 +00:00
parent 9046ec3bbc
commit f550699daf
3 changed files with 24 additions and 10 deletions

View File

@@ -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 cant use {} in text messages. They wont show up properly on everyones phones.'.format(
formatted_list(non_gsm_characters, conjunction='or')
'You cant use {} in text messages. {} wont show up properly on everyones phones.'.format(
formatted_list(non_gsm_characters, conjunction='or', before_each='', after_each=''),
('It' if len(non_gsm_characters) == 1 else 'They')
)
)

View File

@@ -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 cant use ∆, 📲 or 📵 in text messages. '
'They wont show up properly on everyones phones.'
)
),
(
'📵',
(
'You cant use 📵 in text messages. '
'It wont show up properly on everyones 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 cant use ‘∆’, ‘📲’ or ‘📵’ in text messages. '
'They wont show up properly on everyones phones.'
)
assert str(error.value) == err_msg
def test_sms_sender_form_validation(

View File

@@ -670,7 +670,7 @@ def test_should_not_create_sms_template_with_emoji(
), data=data)
assert resp.status_code == 200
assert "You cant use ‘🍜’ in text messages." in resp.get_data(as_text=True)
assert "You cant 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 cant use ‘🍔’ in text messages." in resp.get_data(as_text=True)
assert "You cant use 🍔 in text messages." in resp.get_data(as_text=True)
def test_should_create_sms_template_without_downgrading_unicode_characters(