Merge pull request #1383 from alphagov/fix-one-off-errors

Fix error messages in one-off flow
This commit is contained in:
Chris Hill-Scott
2017-07-26 11:41:55 +01:00
committed by GitHub
2 changed files with 54 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
{% extends "withnav_template.html" %}
{% from "components/radios.html" import radio_select %}
{% from "components/banner.html" import banner_wrapper %}
{% from "components/message-count-label.html" import message_count_label %}
{% block service_page_title %}
@@ -8,17 +8,31 @@
{% block maincolumn_content %}
{% if error == 'not-allowed-to-send-to' %}
{% with
count_of_recipients=1,
template_type_label='phone number'
%}
{% include "partials/check/not-allowed-to-send-to.html" %}
{% endwith %}
<div class="bottom-gutter">
{% call banner_wrapper(type='dangerous') %}
{% with
count_of_recipients=1,
template_type_label=(
'phone number' if template.template_type == 'sms' else 'email address'
)
%}
{% include "partials/check/not-allowed-to-send-to.html" %}
{% endwith %}
{% endcall %}
</div>
{% elif error == 'too-many-messages' %}
{% include "partials/check/too-many-messages.html" %}
<div class="bottom-gutter">
{% call banner_wrapper(type='dangerous') %}
{% include "partials/check/too-many-messages.html" %}
{% endcall %}
</div>
{% elif error == 'message-too-long' %}
{# the only row_errors we can get when sending one off messages is that the message is too long #}
{% include "partials/check/message-too-long.html" %}
<div class="bottom-gutter">
{% call banner_wrapper(type='dangerous') %}
{% include "partials/check/message-too-long.html" %}
{% endcall %}
</div>
{% else %}
<h1 class="heading-large">
Preview of {{ template.name }}

View File

@@ -1937,6 +1937,35 @@ def test_send_notification_shows_error_if_400(
_expected_status=200
)
assert ' '.join(page.h1.text.split()) == expected_h1
assert ' '.join(page.h1.parent.p.text.split()) == expected_err_details
assert normalize_spaces(page.select('.banner-dangerous h1')[0].text) == expected_h1
assert normalize_spaces(page.select('.banner-dangerous p')[0].text) == expected_err_details
assert not page.find('input[type=submit]')
def test_send_notification_shows_email_error_in_trial_mode(
client_request,
fake_uuid,
mocker,
mock_get_service_email_template,
):
mocker.patch(
'app.notification_api_client.send_notification',
side_effect=HTTPError(response=Mock(status_code=400), message=TRIAL_MODE_MSG)
)
with client_request.session_transaction() as session:
session['recipient'] = 'test@example.com'
session['placeholders'] = {'date': 'foo', 'thing': 'bar'}
page = client_request.post(
'main.send_notification',
service_id=SERVICE_ONE_ID,
template_id=fake_uuid,
_expected_status=200,
)
assert normalize_spaces(page.select('.banner-dangerous h1')[0].text) == (
'You cant send to this email address'
)
assert normalize_spaces(page.select('.banner-dangerous p')[0].text) == (
'In trial mode you can only send to yourself and members of your team'
)