From c690434b1ff1ccae7054d3b3ac013abbaf77ccb4 Mon Sep 17 00:00:00 2001 From: Pea Tyczynska Date: Tue, 1 Oct 2019 14:31:36 +0100 Subject: [PATCH] One off letter flow does not allow to send letter longer than 10 pages --- app/main/views/send.py | 4 +- app/templates/views/notifications/check.html | 2 +- tests/app/main/views/test_send.py | 43 ++++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/app/main/views/send.py b/app/main/views/send.py index c6d720be1..1b42eca71 100644 --- a/app/main/views/send.py +++ b/app/main/views/send.py @@ -850,6 +850,7 @@ def _check_notification(service_id, template_id, exception=None): email_reply_to = get_email_reply_to_address_from_session() elif db_template['template_type'] == 'sms': sms_sender = get_sms_sender_from_session() + page_count = get_page_count_for_letter(db_template) template = get_template( db_template, current_service, @@ -862,7 +863,7 @@ def _check_notification(service_id, template_id, exception=None): template_id=template_id, filetype='png', ), - page_count=get_page_count_for_letter(db_template), + page_count=page_count, ) back_link = get_back_link(service_id, template, len(fields_to_fill_in(template))) @@ -881,6 +882,7 @@ def _check_notification(service_id, template_id, exception=None): template=template, back_link=back_link, help=get_help_argument(), + page_count=page_count, **(get_template_error_dict(exception) if exception else {}), ) diff --git a/app/templates/views/notifications/check.html b/app/templates/views/notifications/check.html index bdf55ecf4..b6ef62927 100644 --- a/app/templates/views/notifications/check.html +++ b/app/templates/views/notifications/check.html @@ -66,7 +66,7 @@ help='3' if help else 0 )}}" class='page-footer'> - {% if not error %} + {% if not error and page_count < 11 %} {% endif %} {% if template.template_type == 'letter' %} diff --git a/tests/app/main/views/test_send.py b/tests/app/main/views/test_send.py index c63c9fe29..1597495b3 100644 --- a/tests/app/main/views/test_send.py +++ b/tests/app/main/views/test_send.py @@ -3066,6 +3066,49 @@ def test_send_one_off_letter_errors_in_trial_mode( assert page.select_one('a[download]').text == 'Download as a PDF' +def test_send_one_off_letter_errors_if_letter_longer_than_10_pages( + client_request, + mocker, + mock_get_live_service, + mock_get_service_letter_template, + mock_has_permissions, + fake_uuid, + mock_get_users_by_service, + mock_get_service_statistics, + mock_get_job_doesnt_exist, + mock_s3_set_metadata, +): + + mocker.patch( + 'app.main.views.send.get_page_count_for_letter', + return_value=11, + ) + + with client_request.session_transaction() as session: + session['recipient'] = None + session['placeholders'] = { + 'address_line_1': 'First Last', + 'address_line_2': '123 Street', + 'postcode': 'SW1 1AA', + } + + page = client_request.get( + 'main.check_notification', + service_id=SERVICE_ONE_ID, + template_id=fake_uuid, + _test_page_title=False, + ) + + assert normalize_spaces(page.select('.banner-dangerous')) == normalize_spaces( + 'This letter is too long ' + 'Letters must be 10 pages or less' + ) + + assert len(page.select('.letter img')) == 10 + + assert not page.select('[type=submit]') + + def test_check_messages_shows_over_max_row_error( client_request, mock_get_users_by_service,