From a32dcbf8e3165076a875b00087a0782ded66e46a Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 14 Oct 2016 10:44:28 +0100 Subject: [PATCH] Error if a CSV file contains more than 50,000 rows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We want to limit the number of rows someone can have in a job, because it gets too slow to process the file otherwise. This should be the first error that a user sees, because we can’t work out if there are other errors until they’ve got the file down to a processable size. This also means adding a message to say that the file can’t be displayed if it doesn’t contain any processed rows. *** https://www.pivotaltracker.com/story/show/129830161 --- app/templates/views/check.html | 20 ++++++++++++++-- requirements.txt | 2 +- tests/app/main/views/test_send.py | 39 +++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/app/templates/views/check.html b/app/templates/views/check.html index 4cb5e5e26..df6b7886a 100644 --- a/app/templates/views/check.html +++ b/app/templates/views/check.html @@ -15,7 +15,22 @@ {% block maincolumn_content %} - {% if not recipients.has_recipient_column %} + {% if recipients.has_too_many_rows %} + +
+ {% call banner_wrapper(type='dangerous') %} +

+ Your file has too many rows +

+

+ Notify can process up to + {{ "{:,}".format(recipients.max_rows) }} rows at once. Your + file has {{ "{:,}".format(recipients|length) }} rows. +

+ {% endcall %} +
+ + {% elif not recipients.has_recipient_column %}
{% call banner_wrapper(type='dangerous') %} @@ -159,7 +174,8 @@ {% call(item, row_number) list_table( recipients.initial_annotated_rows_with_errors if row_errors and not recipients.missing_column_headers else recipients.initial_annotated_rows, caption=original_file_name, - field_headings=['1'] + recipients.column_headers + field_headings=['1'] + recipients.column_headers, + empty_message='Can’t show the contents of this file' ) %} {{ index_field(item.index + 2) }} {% for column in recipients.column_headers %} diff --git a/requirements.txt b/requirements.txt index 15f42e3f5..09fb12758 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,4 +19,4 @@ pytz==2016.4 git+https://github.com/alphagov/notifications-python-client.git@1.3.0#egg=notifications-python-client==1.3.0 -git+https://github.com/alphagov/notifications-utils.git@9.0.6#egg=notifications-utils==9.0.6 +git+https://github.com/alphagov/notifications-utils.git@9.1.0#egg=notifications-utils==9.1.0 diff --git a/tests/app/main/views/test_send.py b/tests/app/main/views/test_send.py index abefc56fb..5aef8e117 100644 --- a/tests/app/main/views/test_send.py +++ b/tests/app/main/views/test_send.py @@ -776,3 +776,42 @@ def test_check_messages_shows_too_many_messages_errors( details = page.find('div', class_='banner-dangerous').findAll('p')[1] details = ' '.join([line.strip() for line in details.text.split('\n') if line.strip() != '']) assert details == expected_msg + + +def test_check_messages_shows_over_max_row_error( + client, + app_, + api_user_active, + mock_login, + mock_get_users_by_service, + mock_get_service, + mock_get_service_template_with_placeholders, + mock_has_permissions, + mock_get_detailed_service_for_today, + mock_s3_download, + fake_uuid, + mocker +): + mock_recipients = mocker.patch('app.main.views.send.RecipientCSV').return_value + mock_recipients.max_rows = 11111 + mock_recipients.__len__.return_value = 99999 + mock_recipients.has_too_many_rows.return_value = True + + client.login(api_user_active) + with client.session_transaction() as session: + session['upload_data'] = {'template_id': fake_uuid} + response = client.get(url_for( + 'main.check_messages', + service_id=fake_uuid, + template_type='sms', + upload_id=fake_uuid + )) + assert response.status_code == 200 + page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') + assert ' '.join( + page.find('div', class_='banner-dangerous').text.split() + ) == ( + 'Your file has too many rows ' + 'Notify can process up to 11,111 rows at once. ' + 'Your file has 99,999 rows.' + )