From 176d0f48670af951fdad9379aaac5bb9b23a9022 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 16 Feb 2017 11:07:26 +0000 Subject: [PATCH] Fix error message when recipient column missing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When your CSV file is missing the recipient column (eg ‘phone number’ or ‘email address’) we give you a helpful error message telling you that this is the case. When we changed the recipient column to be columns, plural, we didn’t update the code that generated the error message. So you would get errors that looked this like this: > Your file needs to have a column called ‘’ This commit fixes the error message. --- app/templates/views/check.html | 6 +++++- tests/app/main/views/test_send.py | 33 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/app/templates/views/check.html b/app/templates/views/check.html index 4ec08c537..e0f891f7d 100644 --- a/app/templates/views/check.html +++ b/app/templates/views/check.html @@ -41,7 +41,11 @@
{% call banner_wrapper(type='dangerous') %}

- Your file needs to have a column called ‘{{ recipients.recipient_column_header }}’ + Your file needs to have {{ formatted_list( + recipients.recipient_column_headers, + prefix='a column called', + prefix_plural='columns called' + ) }}

Your file has {{ formatted_list( diff --git a/tests/app/main/views/test_send.py b/tests/app/main/views/test_send.py index 1306b819d..3cdb64788 100644 --- a/tests/app/main/views/test_send.py +++ b/tests/app/main/views/test_send.py @@ -115,6 +115,39 @@ def test_upload_csvfile_with_errors_shows_check_page_with_errors( assert 'Re-upload your file' in content +def test_upload_csvfile_with_no_recipient_column_shows_error( + logged_in_client, + mocker, + mock_get_service_template_with_placeholders, + mock_s3_upload, + mock_get_users_by_service, + mock_get_detailed_service_for_today, + fake_uuid, +): + + mocker.patch( + 'app.main.views.send.s3download', + return_value=""" + telephone,name + +447700900986 + """ + ) + + response = logged_in_client.post( + url_for('main.send_messages', service_id=fake_uuid, template_id=fake_uuid), + data={'file': (BytesIO(''.encode('utf-8')), 'invalid.csv')}, + follow_redirects=True, + ) + + assert response.status_code == 200 + page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') + assert ' '.join(page.select('.banner-dangerous')[0].text.split()) == ( + 'Your file needs to have a column called ‘phone number’ ' + 'Your file has columns called ‘telephone’ and ‘name’. ' + 'Skip to file contents' + ) + + def test_upload_csv_invalid_extension( logged_in_client, api_user_active,