From 724e8d1838a59e77f437ec941dad9203c7cd0bf3 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 1 Jul 2020 17:43:30 +0100 Subject: [PATCH] Make it possible to preview a broadcast template MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At the moment this won’t look like much, but it will let us do an end-to-end run of adding a broadcast template. At the moment all you can do with a broadcast template is edit it, so there’s no ‘Send’ link on the page. --- app/templates/views/templates/_template.html | 8 +++++ app/utils.py | 5 +++ requirements-app.txt | 2 +- requirements.txt | 6 ++-- tests/app/main/views/test_templates.py | 36 ++++++++++++++++++++ tests/conftest.py | 20 +++++++++++ 6 files changed, 73 insertions(+), 4 deletions(-) diff --git a/app/templates/views/templates/_template.html b/app/templates/views/templates/_template.html index 0b1c39e77..e5913d5d6 100644 --- a/app/templates/views/templates/_template.html +++ b/app/templates/views/templates/_template.html @@ -28,6 +28,14 @@ {% endif %} + {% elif template.template_type == 'broadcast' %} + {% if current_user.has_permissions('manage_templates') %} +
+ + Edit + +
+ {% endif %} {% else %} {% if current_user.has_permissions('send_messages', restrict_admin_usage=True) %}
diff --git a/app/utils.py b/app/utils.py index 370ff57fd..80b53d59b 100644 --- a/app/utils.py +++ b/app/utils.py @@ -37,6 +37,7 @@ from notifications_utils.postal_address import PostalAddress from notifications_utils.recipients import RecipientCSV from notifications_utils.take import Take from notifications_utils.template import ( + BroadcastPreviewTemplate, EmailPreviewTemplate, LetterImageTemplate, LetterPreviewTemplate, @@ -437,6 +438,10 @@ def get_template( admin_base_url=current_app.config['ADMIN_BASE_URL'], redact_missing_personalisation=redact_missing_personalisation, ) + if 'broadcast' == template['template_type']: + return BroadcastPreviewTemplate( + template, + ) def get_current_financial_year(): diff --git a/requirements-app.txt b/requirements-app.txt index 0a936f986..b36f81ef3 100644 --- a/requirements-app.txt +++ b/requirements-app.txt @@ -23,5 +23,5 @@ notifications-python-client==5.6.0 awscli-cwlogs>=1.4,<1.5 itsdangerous==1.1.0 -git+https://github.com/alphagov/notifications-utils.git@39.7.0#egg=notifications-utils==39.7.0 +git+https://github.com/alphagov/notifications-utils.git@40.1.0#egg=notifications-utils==40.1.0 git+https://github.com/alphagov/govuk-frontend-jinja.git@v0.5.1-alpha#egg=govuk-frontend-jinja==0.5.1-alpha diff --git a/requirements.txt b/requirements.txt index ec8040212..2f806003b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,14 +25,14 @@ notifications-python-client==5.6.0 awscli-cwlogs>=1.4,<1.5 itsdangerous==1.1.0 -git+https://github.com/alphagov/notifications-utils.git@39.7.0#egg=notifications-utils==39.7.0 +git+https://github.com/alphagov/notifications-utils.git@40.1.0#egg=notifications-utils==40.1.0 git+https://github.com/alphagov/govuk-frontend-jinja.git@v0.5.1-alpha#egg=govuk-frontend-jinja==0.5.1-alpha ## The following requirements were added by pip freeze: -awscli==1.18.90 +awscli==1.18.91 bleach==3.1.4 boto3==1.10.38 -botocore==1.17.13 +botocore==1.17.14 cachetools==4.1.0 certifi==2020.6.20 chardet==3.0.4 diff --git a/tests/app/main/views/test_templates.py b/tests/app/main/views/test_templates.py index d65795284..4ae05c466 100644 --- a/tests/app/main/views/test_templates.py +++ b/tests/app/main/views/test_templates.py @@ -674,6 +674,42 @@ def test_should_be_able_to_view_a_template_with_links( ) +def test_view_broadcast_template( + client_request, + service_one, + mock_get_broadcast_template, + mock_get_template_folders, + active_user_with_permissions, + fake_uuid, +): + service_one['permissions'] + page = client_request.get( + '.view_template', + service_id=SERVICE_ONE_ID, + template_id=fake_uuid, + _test_page_title=False, + ) + + assert [ + (link.text.strip(), link['href']) + for link in page.select('.pill-separate-item') + ] == [ + ('Edit', url_for( + '.edit_service_template', + service_id=SERVICE_ONE_ID, + template_id=fake_uuid, + )), + ] + + assert ( + normalize_spaces(page.select_one('.template-container').text) + ) == ( + normalize_spaces(page.select_one('.broadcast-message-wrapper').text) + ) == ( + 'This is a test' + ) + + def test_should_show_template_id_on_template_page( client_request, mock_get_service_template, diff --git a/tests/conftest.py b/tests/conftest.py index daaeec0cb..13bdcb397 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -841,6 +841,26 @@ def mock_get_service_email_template(mocker): 'app.service_api_client.get_service_template', side_effect=_get) +@pytest.fixture(scope='function') +def mock_get_broadcast_template(mocker): + def _get(service_id, template_id, version=None): + template = template_json( + service_id, + template_id, + 'Test alert', + 'broadcast', + 'This is a test', + ) + if version: + template.update({'version': version}) + return {'data': template} + + return mocker.patch( + 'app.service_api_client.get_service_template', + side_effect=_get + ) + + @pytest.fixture(scope='function') def mock_get_service_email_template_without_placeholders(mocker): def _get(service_id, template_id, version=None):