Make error message specific to template type

This commit is contained in:
Chris Hill-Scott
2020-07-03 15:46:00 +01:00
parent f3115c0cea
commit e832d18002
4 changed files with 42 additions and 11 deletions

View File

@@ -154,7 +154,7 @@ def test_for_commas_in_placeholders(
@pytest.mark.parametrize('msg', ['The quick brown fox', 'Thé “quick” bröwn fox\u200B'])
def test_sms_character_validation(client, msg):
OnlySMSCharacters()(None, _gen_mock_field(msg))
OnlySMSCharacters(template_type='sms')(None, _gen_mock_field(msg))
@pytest.mark.parametrize('data, err_msg', [
@@ -175,7 +175,7 @@ def test_sms_character_validation(client, msg):
])
def test_non_sms_character_validation(data, err_msg, client):
with pytest.raises(ValidationError) as error:
OnlySMSCharacters()(None, _gen_mock_field(data))
OnlySMSCharacters(template_type='sms')(None, _gen_mock_field(data))
assert str(error.value) == err_msg

View File

@@ -1994,14 +1994,20 @@ def test_can_create_email_template_with_emoji(
assert mock_create_service_template.called is True
@pytest.mark.parametrize('template_type', (
'sms', 'broadcast'
@pytest.mark.parametrize('template_type, expected_error', (
('sms', (
'You cannot use 🍜 in text messages.'
)),
('broadcast', (
'You cannot use 🍜 in broadcasts.'
)),
))
def test_should_not_create_sms_or_broadcast_template_with_emoji(
client_request,
service_one,
mock_create_service_template,
template_type,
expected_error,
):
service_one['permissions'] += [template_type]
page = client_request.post(
@@ -2017,22 +2023,37 @@ def test_should_not_create_sms_or_broadcast_template_with_emoji(
},
_expected_status=200,
)
assert "You cannot use 🍜 in text messages." in page.text
assert expected_error in page.text
assert mock_create_service_template.called is False
@pytest.mark.parametrize('template_type', (
'sms', 'broadcast'
@pytest.mark.parametrize('template_type, expected_error', (
('sms', (
'You cannot use 🍔 in text messages.'
)),
('broadcast', (
'You cannot use 🍔 in broadcasts.'
)),
))
def test_should_not_update_sms_template_with_emoji(
mocker,
client_request,
service_one,
mock_get_service_template,
mock_update_service_template,
fake_uuid,
template_type,
expected_error,
):
service_one['permissions'] += [template_type]
return mocker.patch(
'app.service_api_client.get_service_template',
return_value=template_json(
SERVICE_ONE_ID,
fake_uuid,
type_=template_type,
),
)
page = client_request.post(
'.edit_service_template',
service_id=SERVICE_ONE_ID,
@@ -2047,7 +2068,7 @@ def test_should_not_update_sms_template_with_emoji(
},
_expected_status=200,
)
assert "You cannot use 🍔 in text messages." in page.text
assert expected_error in page.text
assert mock_update_service_template.called is False