From e1f53760bf102e9218234b3cb0c509df46fb98cb Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 27 Feb 2017 12:06:16 +0000 Subject: [PATCH] Fix wrong error message if file is missing columns Accidentally got broken here: https://github.com/alphagov/notifications-admin/commit/41fa1586353374d611f7b7e7690b03c13b830880#diff-bff3df90be0231a1e33e033fc51ba7f7L78 This commit changes it back to how it was before (but keeping the new macro for formatting the list). --- app/templates/views/check.html | 2 +- tests/app/main/views/test_send.py | 43 +++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/app/templates/views/check.html b/app/templates/views/check.html index 6c4873a7d..e3ee1709e 100644 --- a/app/templates/views/check.html +++ b/app/templates/views/check.html @@ -70,7 +70,7 @@ ) }}.

- It doesn’t have {{ recipients.column_headers | formatted_list( + It doesn’t have {{ recipients.missing_column_headers | formatted_list( conjunction='or', prefix='a column called ', prefix_plural='columns called ' diff --git a/tests/app/main/views/test_send.py b/tests/app/main/views/test_send.py index b89eb6ae3..fc288bfff 100644 --- a/tests/app/main/views/test_send.py +++ b/tests/app/main/views/test_send.py @@ -115,7 +115,32 @@ 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( +@pytest.mark.parametrize('file_contents, expected_error,', [ + ( + """ + telephone,name + +447700900986 + """, + ( + 'Your file needs to have a column called ‘phone number’ ' + 'Your file has columns called ‘telephone’ and ‘name’. ' + 'Skip to file contents' + ) + ), + ( + """ + phone number + +447700900986 + """, + ( + 'The columns in your file need to match the double brackets in your template ' + 'Your file has one column, called ‘phone number’. ' + 'It doesn’t have a column called ‘name’. ' + 'Skip to file contents' + ) + ) +]) +def test_upload_csvfile_with_missing_columns_shows_error( logged_in_client, mocker, mock_get_service_template_with_placeholders, @@ -124,15 +149,11 @@ def test_upload_csvfile_with_no_recipient_column_shows_error( mock_get_detailed_service_for_today, service_one, fake_uuid, + file_contents, + expected_error, ): - mocker.patch( - 'app.main.views.send.s3download', - return_value=""" - telephone,name - +447700900986 - """ - ) + mocker.patch('app.main.views.send.s3download', return_value=file_contents) response = logged_in_client.post( url_for('main.send_messages', service_id=service_one['id'], template_id=fake_uuid), @@ -142,11 +163,7 @@ def test_upload_csvfile_with_no_recipient_column_shows_error( 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' - ) + assert ' '.join(page.select('.banner-dangerous')[0].text.split()) == expected_error def test_upload_csv_invalid_extension(