Fix not showing errors for invalid contact uploads

This code should behave the same way as other CSV uploads [1],
but we had to write it in a hurry [2] and the way we show an
error with the upload field was based off that for PDF uploads,
where we show custom button text instead of an error [3].

This fixes the inconsistency, so that we see the same errors
for CSV uploads here as in other parts of the app.

[1]: 6b52735dac/app/templates/views/send.html (L25)
[2]: 1c02476ee7 (diff-aedd12af78c9737f1c3344d2afbb9c00878eccbcc754b2b3d9e6864c2ad2f7c3R32)
[3]: 3b3f74bbf0
This commit is contained in:
Ben Thorner
2021-12-01 16:59:30 +00:00
parent 6b52735dac
commit c0da7a27ed
2 changed files with 17 additions and 2 deletions

View File

@@ -40,8 +40,7 @@
{{ file_upload(
form.file,
allowed_file_extensions=allowed_file_extensions,
button_text='Upload your file again' if error else 'Choose file',
show_errors=False
button_text='Choose file',
)}}
</div>

View File

@@ -276,6 +276,22 @@ def test_upload_csv_file_shows_error_banner_for_too_many_rows(
)
def test_upload_csv_shows_error_with_invalid_extension(
client_request,
):
page = client_request.post(
'main.upload_contact_list',
service_id=SERVICE_ONE_ID,
_data={'file': (BytesIO(''.encode('utf-8')), 'invalid.txt')},
_follow_redirects=True,
)
assert normalize_spaces(page.select_one('.file-upload-label .error-message').text) == (
"invalid.txt is not a spreadsheet that Notify can read"
)
def test_upload_csv_file_sanitises_and_truncates_file_name_in_metadata(
client_request,
mocker,