From 8f40cbd2bbaf31e29e218554bb1dc89f03d06501 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 8 Aug 2017 10:01:44 +0100 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20let=20users=20in=20trial=20mode?= =?UTF-8?q?=20send=20letters?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Users in trial mode haven’t signed the MOU. This means that they haven’t agreed to pay for any costs they incur. Unlike text messages and emails, we don’t give you any free allowance of letters. Sending _any_ letters will cost the user money. Therefore we shouldn’t let users who haven’t agreed that they will pay for the service to incur costs by sending letters. The pattern used for this is roughly the same as other trial mode errors that we have already, ie a red box that says you’re not allowed. Not sure if this is exactly right because it’s not exactly an error so the pattern might feel too heavy-handed. Getting this in place means we can turn letters on for users in trial mode without worrying that they’ll accidentally send real letters, which would result in: - us having to absorb those costs - some awkward conversations --- app/main/views/send.py | 7 ++- app/templates/views/check/column-errors.html | 11 +++++ tests/app/main/views/test_send.py | 48 ++++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/app/main/views/send.py b/app/main/views/send.py index 557faf0ba..b806af7c5 100644 --- a/app/main/views/send.py +++ b/app/main/views/send.py @@ -439,7 +439,10 @@ def _check_messages(service_id, template_type, upload_id, letters_as_pdf=False): remaining_messages=remaining_messages, choose_time_form=choose_time_form, back_link=back_link, - help=get_help_argument() + help=get_help_argument(), + trying_to_send_letters_in_trial_mode=bool( + current_service['restricted'] and template.template_type == 'letter' + ), ) @@ -461,7 +464,7 @@ def check_messages(service_id, template_type, upload_id): if data['row_errors']: return render_template('views/check/row-errors.html', **data) - if data['errors']: + if data['errors'] or data['trying_to_send_letters_in_trial_mode']: return render_template('views/check/column-errors.html', **data) return render_template('views/check/ok.html', **data) diff --git a/app/templates/views/check/column-errors.html b/app/templates/views/check/column-errors.html index 5beaeb529..9dbd9a548 100644 --- a/app/templates/views/check/column-errors.html +++ b/app/templates/views/check/column-errors.html @@ -87,6 +87,17 @@ {% include "partials/check/too-many-messages.html" %} + {% elif trying_to_send_letters_in_trial_mode %} + +

+ You can’t send + {{ 'this letter' if count_of_recipients == 1 else 'these letters' }} +

+

+ In trial mode you + can only preview how your letters will look +

+ {% endif %} {{ skip_to_file_contents() }} diff --git a/tests/app/main/views/test_send.py b/tests/app/main/views/test_send.py index b323237a2..ad6ef2254 100644 --- a/tests/app/main/views/test_send.py +++ b/tests/app/main/views/test_send.py @@ -24,6 +24,8 @@ from tests.conftest import ( mock_get_service_email_template, normalize_spaces, SERVICE_ONE_ID, + mock_get_service, + mock_get_live_service, ) template_types = ['email', 'sms'] @@ -1577,6 +1579,52 @@ def test_check_messages_shows_trial_mode_error( ) +@pytest.mark.parametrize('service_mock, error_should_be_shown', [ + (mock_get_service, True), + (mock_get_live_service, False), +]) +def test_check_messages_shows_trial_mode_error_for_letters( + client_request, + api_user_active, + mock_get_service_letter_template, + mock_has_permissions, + mock_get_users_by_service, + mock_get_detailed_service_for_today, + mocker, + service_mock, + error_should_be_shown, +): + + service_mock(mocker, api_user_active) + + mocker.patch('app.main.views.send.s3download', return_value=''' + address_line_1,address_line_2,postcode, + First Last, 123 Street, SW1 1AA + ''') + + with client_request.session_transaction() as session: + session['upload_data'] = {'template_id': ''} + + page = client_request.get( + 'main.check_messages', + service_id=SERVICE_ONE_ID, + template_type='letter', + upload_id=uuid.uuid4(), + _test_page_title=False, + ) + + error = page.select('.banner-dangerous') + + if error_should_be_shown: + assert normalize_spaces(error[0].text) == ( + 'You can’t send this letter ' + 'In trial mode you can only preview how your letters will look ' + 'Skip to file contents' + ) + else: + assert not error + + def test_check_messages_shows_over_max_row_error( logged_in_client, api_user_active,