Merge pull request #985 from alphagov/over-50000

Error if a CSV file contains more than 50,000 rows
This commit is contained in:
Chris Hill-Scott
2016-10-17 09:24:50 +01:00
committed by GitHub
3 changed files with 58 additions and 3 deletions

View File

@@ -15,7 +15,22 @@
{% block maincolumn_content %}
{% if not recipients.has_recipient_column %}
{% if recipients.has_too_many_rows %}
<div class="bottom-gutter">
{% call banner_wrapper(type='dangerous') %}
<h1 class='banner-title'>
Your file has too many rows
</h1>
<p>
Notify can process up to
{{ "{:,}".format(recipients.max_rows) }} rows at once. Your
file has {{ "{:,}".format(recipients|length) }} rows.
</p>
{% endcall %}
</div>
{% elif not recipients.has_recipient_column %}
<div class="bottom-gutter">
{% 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='Cant show the contents of this file'
) %}
{{ index_field(item.index + 2) }}
{% for column in recipients.column_headers %}

View File

@@ -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

View File

@@ -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.'
)