From 45ac0d7812a0208d5e1e724ef9cd4ce2748f63e8 Mon Sep 17 00:00:00 2001 From: Pea Tyczynska Date: Mon, 13 May 2019 10:17:20 +0100 Subject: [PATCH] Waiting page shows correct messages --- app/config.py | 2 ++ app/main/views/service_settings.py | 13 ++++++- .../email-reply-to/verify.html | 35 +++++++++++++++++++ tests/app/main/views/test_service_settings.py | 24 +++++++++++-- tests/conftest.py | 2 +- 5 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 app/templates/views/service-settings/email-reply-to/verify.html diff --git a/app/config.py b/app/config.py index 47620b253..2baf45576 100644 --- a/app/config.py +++ b/app/config.py @@ -77,6 +77,8 @@ class Config(object): ASSET_DOMAIN = '' ASSET_PATH = '/static/' + NOTIFY_SERVICE_ID = 'd6aa2c68-a2d9-4437-ab19-3ae8eb202553' + class Development(Config): NOTIFY_LOG_PATH = 'application.log' diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index d892c18b5..c4497aa05 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -422,8 +422,19 @@ def service_add_email_reply_to(service_id): @login_required @user_has_permissions('manage_service') def verify_reply_to_address(service_id, notification_id): + notification = notification_api_client.get_notification(current_app.config["NOTIFY_SERVICE_ID"], notification_id) + verification_status = "pending" + if notification["status"] == "delivered": + verification_status = "success" + if notification["status"] in ["failed", "permanent-failure", "technical-failure", "temporary-failure"]: + verification_status = "failure" + # also include condition for when lots of time passes return render_template( - 'views/service-settings/email-reply-to/verify.html' + 'views/service-settings/email-reply-to/verify.html', + reply_to_email_address=notification["to"], + service_id=service_id, + notification_id=notification_id, + verification_status=verification_status ) diff --git a/app/templates/views/service-settings/email-reply-to/verify.html b/app/templates/views/service-settings/email-reply-to/verify.html new file mode 100644 index 000000000..d9060de68 --- /dev/null +++ b/app/templates/views/service-settings/email-reply-to/verify.html @@ -0,0 +1,35 @@ +{% extends "withnav_template.html" %} +{% from "components/textbox.html" import textbox %} +{% from "components/checkbox.html" import checkbox %} +{% from "components/page-header.html" import page_header %} +{% from "components/page-footer.html" import page_footer %} +{% from "components/form.html" import form_wrapper %} + +{% block service_page_title %} + Verifying your reply-to email address +{% endblock %} + +{% block maincolumn_content %} + + {{ page_header( + 'Verifying your reply-to email address', + back_link=url_for('main.service_email_reply_to', service_id=current_service.id) + ) }} + {% if verification_status == "pending" %} +

+ We have sent a notification to {{ reply_to_email_address }} to check if it's a working email address. + +

+

+ Once we receive a delivery confirmation, we will update your list of reply-to email addresses. +

+ +

+ Refresh +

+ {% elif verification_status == "success" %} + {{ banner("Yay success! Your new reply-to email has been added ^__^", type='message', with_tick=True) }} + {% elif verification_status == "failure" %} + {{ banner("Sorry dawg, this email address doesn't seem to be working :d", type='dangerous') }} + {% endif %} +{% endblock %} diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index 6d7832204..9751efe32 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -30,6 +30,7 @@ from tests.conftest import ( get_non_default_letter_contact_block, get_non_default_reply_to_email_address, get_non_default_sms_sender, + mock_get_notification, mock_get_service_organisation, multiple_letter_contact_blocks, multiple_reply_to_email_addresses, @@ -2055,8 +2056,27 @@ def test_add_reply_to_email_address_sends_test_notification( mock_verify.assert_called_once_with("test@example.com") -def test_add_reply_to_email_address_waiting_page(): - pass +@pytest.mark.parametrize("status,expected_failure,expected_success", [ + ("delivered", 0, 1), + ("pending", 0, 0), + ("permanent-failure", 1, 0), +]) +def test_add_reply_to_email_address_waiting_page( + mocker, client_request, fake_uuid, status, expected_failure, expected_success +): + notification_id = fake_uuid + mock_get_notification( + mocker, notification_id=notification_id, notification_status=status + ) + + page = client_request.get( + 'main.verify_reply_to_address', + service_id=SERVICE_ONE_ID, + notification_id=notification_id + ) + assert page.find('h1').text == 'Verifying your reply-to email address' + assert len(page.find_all('div', class_='banner-dangerous')) == expected_failure + assert len(page.find_all('div', class_='banner-message-with-tick')) == expected_success def test_add_reply_to_email_address_success(): diff --git a/tests/conftest.py b/tests/conftest.py index 84a9d5da4..3ad74ad31 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2748,7 +2748,7 @@ def mock_reset_failed_login_count(mocker): @pytest.fixture def mock_get_notification( mocker, - fake_uuid, + notification_id=fake_uuid, notification_status='delivered', redact_personalisation=False, template_type=None,