From 4ff674158c8a2bce4bb30261ae718aee972df7b9 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 8 Aug 2017 10:31:09 +0100 Subject: [PATCH] Ensure trial mode error overrides too many rows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Telling users that they can’t send to more than 50 recipients in trial mode doesn’t apply for letters (they can’t send to _any_ recipients). So we should make sure that the error message about not being able to send to any recipients always comes up instead of the 50 recipients one, whether you’re trying to upload a file with 1 or 111 rows. --- app/main/views/send.py | 5 +++-- app/templates/views/check/column-errors.html | 8 ++++---- tests/app/main/views/test_send.py | 20 +++++++++++++------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/app/main/views/send.py b/app/main/views/send.py index b806af7c5..475e56798 100644 --- a/app/main/views/send.py +++ b/app/main/views/send.py @@ -457,14 +457,15 @@ def check_messages(service_id, template_type, upload_id): data['recipients'].too_many_rows or not data['count_of_recipients'] or not data['recipients'].has_recipient_columns or - data['recipients'].missing_column_headers + data['recipients'].missing_column_headers or + data['trying_to_send_letters_in_trial_mode'] ): return render_template('views/check/column-errors.html', **data) if data['row_errors']: return render_template('views/check/row-errors.html', **data) - if data['errors'] or data['trying_to_send_letters_in_trial_mode']: + if data['errors']: 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 9dbd9a548..491eade0f 100644 --- a/app/templates/views/check/column-errors.html +++ b/app/templates/views/check/column-errors.html @@ -83,10 +83,6 @@ {% include "partials/check/not-allowed-to-send-to.html" %} {% endwith %} - {% elif recipients.more_rows_than_can_send %} - - {% include "partials/check/too-many-messages.html" %} - {% elif trying_to_send_letters_in_trial_mode %}

@@ -98,6 +94,10 @@ can only preview how your letters will look

+ {% elif recipients.more_rows_than_can_send %} + + {% include "partials/check/too-many-messages.html" %} + {% endif %} {{ skip_to_file_contents() }} diff --git a/tests/app/main/views/test_send.py b/tests/app/main/views/test_send.py index ad6ef2254..906bfa66f 100644 --- a/tests/app/main/views/test_send.py +++ b/tests/app/main/views/test_send.py @@ -1583,6 +1583,10 @@ def test_check_messages_shows_trial_mode_error( (mock_get_service, True), (mock_get_live_service, False), ]) +@pytest.mark.parametrize('number_of_rows, expected_error_message', [ + (1, 'You can’t send this letter'), + (111, 'You can’t send these letters'), +]) def test_check_messages_shows_trial_mode_error_for_letters( client_request, api_user_active, @@ -1593,14 +1597,16 @@ def test_check_messages_shows_trial_mode_error_for_letters( mocker, service_mock, error_should_be_shown, + number_of_rows, + expected_error_message, ): 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 - ''') + mocker.patch('app.main.views.send.s3download', return_value='\n'.join( + ['address_line_1,address_line_2,postcode,'] + + ['First Last, 123 Street, SW1 1AA'] * number_of_rows + )) with client_request.session_transaction() as session: session['upload_data'] = {'template_id': ''} @@ -1617,10 +1623,10 @@ def test_check_messages_shows_trial_mode_error_for_letters( 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' - ) + ).format(expected_error_message) else: assert not error @@ -1668,7 +1674,7 @@ def test_non_ascii_characters_in_letter_recipients_file_shows_error( api_user_active, mock_login, mock_get_users_by_service, - mock_get_service, + mock_get_live_service, mock_has_permissions, mock_get_service_letter_template, mock_get_detailed_service_for_today,