Stop checking query string for filename when sending a job

We look for `original_file_name` in the metadata now. Initially we were
still checking the query string too, but now that the change to add the
filename to the metadata has been deployed for a while there shouldn't
be any cases of the filename still being in a query string.

Since the `original_file_name` is not being added to the metadata in
`.check_messages` (it has happened earlier in the process) a few tests
are no longer needed.
This commit is contained in:
Katie Smith
2020-10-27 10:52:16 +00:00
parent 18e4e86565
commit 247e7c2d93
2 changed files with 2 additions and 147 deletions

View File

@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
import sys
import uuid
from functools import partial
from glob import glob
@@ -1108,142 +1107,6 @@ def test_upload_valid_csv_only_sets_meta_if_filename_known(
assert len(mock_s3_set_metadata.call_args_list) == 0
def test_file_name_truncated_to_fit_in_s3_metadata(
client_request,
mocker,
mock_get_live_service,
mock_get_service_template_with_placeholders,
mock_get_users_by_service,
mock_get_service_statistics,
mock_get_job_doesnt_exist,
mock_get_jobs,
mock_s3_set_metadata,
fake_uuid,
):
with client_request.session_transaction() as session:
session['file_uploads'] = {
fake_uuid: {'template_id': fake_uuid}
}
mocker.patch('app.main.views.send.s3download', return_value="""
phone number,name,thing,thing,thing
07700900001, A, foo, foo, foo
""")
file_name = 'ü😁' * 2000
mocker.patch(
'app.main.views.send.get_csv_metadata',
return_value={'original_file_name': file_name},
)
client_request.get(
'main.check_messages',
service_id=SERVICE_ONE_ID,
template_id=fake_uuid,
upload_id=fake_uuid,
)
assert sys.getsizeof(
file_name.encode('utf-8')
) > 2000
assert sys.getsizeof(''.join((
'{}{}'.format(key, value) for key, value in
mock_s3_set_metadata.call_args_list[0][1].items()
)).encode('utf-8')) == 1726
def test_file_name_is_taken_from_query_string_if_not_in_metadata(
client_request,
mocker,
mock_get_live_service,
mock_get_service_template_with_placeholders,
mock_get_users_by_service,
mock_get_service_statistics,
mock_get_job_doesnt_exist,
mock_get_jobs,
mock_s3_set_metadata,
fake_uuid,
):
with client_request.session_transaction() as session:
session['file_uploads'] = {
fake_uuid: {'template_id': fake_uuid}
}
mocker.patch('app.main.views.send.s3download', return_value="""
phone number,name,thing,thing,thing
07700900001, A, foo, foo, foo
""")
mocker.patch(
'app.main.views.send.get_csv_metadata',
return_value={},
)
client_request.get(
'main.check_messages',
service_id=SERVICE_ONE_ID,
template_id=fake_uuid,
upload_id=fake_uuid,
original_file_name='example.csv',
)
mock_s3_set_metadata.assert_called_once_with(
SERVICE_ONE_ID,
fake_uuid,
notification_count=1,
template_id=fake_uuid,
valid=True,
original_file_name='example.csv',
)
def test_check_messages_replaces_invalid_characters_in_file_name(
client_request,
mocker,
mock_get_live_service,
mock_get_service_template_with_placeholders,
mock_get_users_by_service,
mock_get_service_statistics,
mock_get_job_doesnt_exist,
mock_get_jobs,
mock_s3_set_metadata,
fake_uuid,
):
with client_request.session_transaction() as session:
session['file_uploads'] = {
fake_uuid: {'template_id': fake_uuid}
}
mocker.patch('app.main.views.send.s3download', return_value="""
phone number,name,thing,thing,thing
07700900001, A, foo, foo, foo
""")
file_name = 'ü😁’€'
mocker.patch(
'app.main.views.send.get_csv_metadata',
return_value={'original_file_name': file_name},
)
client_request.get(
'main.check_messages',
service_id=SERVICE_ONE_ID,
template_id=fake_uuid,
upload_id=fake_uuid,
)
mock_s3_set_metadata.assert_called_once_with(
SERVICE_ONE_ID,
fake_uuid,
notification_count=1,
original_file_name="u?'?",
template_id=fake_uuid,
valid=True
)
def test_show_all_columns_if_there_are_duplicate_recipient_columns(
client_request,
mocker,