Stop checking query string for filename if uploading contact list

The code was looking for `original_file_name` in the metadata for a
contact list, or the query string if it wasn't in the metadata. Now that
the change to use the metadata for the file name has been deployed for a
while e can stop looking in the query string for the
`original_file_name`.
This commit is contained in:
Katie Smith
2020-10-27 10:35:24 +00:00
parent cebdf7afa1
commit 18e4e86565
2 changed files with 2 additions and 71 deletions

View File

@@ -427,20 +427,13 @@ def check_contact_list(service_id, upload_id):
contents = ContactList.download(service_id, upload_id)
first_row = contents.splitlines()[0].strip().rstrip(',') if contents else ''
metadata = ContactList.get_metadata(service_id, upload_id)
original_file_name = ContactList.get_metadata(service_id, upload_id).get('original_file_name', '')
template_type = {
'emailaddress': 'email',
'phonenumber': 'sms',
}.get(Columns.make_key(first_row))
# TODO: stop looking in the query string for metadata once we are sure all uploaded
# contact lists now have original_file_name in the metadata
original_file_name = metadata.get(
'original_file_name',
SanitiseASCII.encode(request.args.get('original_file_name', ''))
)
recipients = RecipientCSV(
contents,
template=get_sample_template(template_type or 'sms'),
@@ -493,10 +486,7 @@ def check_contact_list(service_id, upload_id):
metadata_kwargs = {
'row_count': len(recipients),
'valid': True,
'original_file_name': unicode_truncate(
original_file_name,
1600,
),
'original_file_name': original_file_name,
'template_type': template_type
}

View File

@@ -394,65 +394,6 @@ def test_upload_csv_shows_ok_page(
)
def test_upload_csv_shows_ok_page_when_filename_is_in_query_string(
client_request,
mock_get_live_service,
mock_get_users_by_service,
mock_get_job_doesnt_exist,
fake_uuid,
mocker
):
mocker.patch('app.models.contact_list.s3download', return_value='\n'.join(
['email address'] + ['test@example.com'] * 51
))
mocker.patch('app.models.contact_list.get_csv_metadata', return_value={})
mock_metadata_set = mocker.patch('app.models.contact_list.set_metadata_on_csv_upload')
page = client_request.get(
'main.check_contact_list',
service_id=SERVICE_ONE_ID,
upload_id=fake_uuid,
original_file_name='good times.xlsx',
_test_page_title=False,
)
mock_metadata_set.assert_called_once_with(
SERVICE_ONE_ID,
fake_uuid,
bucket='test-contact-list',
row_count=51,
original_file_name='good times.xlsx',
template_type='email',
valid=True,
)
assert normalize_spaces(page.select_one('h1').text) == (
'good times.xlsx'
)
assert normalize_spaces(page.select_one('main p').text) == (
'51 email addresses found'
)
assert page.select_one('form')['action'] == url_for(
'main.save_contact_list',
service_id=SERVICE_ONE_ID,
upload_id=fake_uuid,
)
assert normalize_spaces(page.select_one('form [type=submit]').text) == (
'Save contact list'
)
assert normalize_spaces(page.select_one('thead').text) == (
'Row in file 1 email address'
)
assert len(page.select('tbody tr')) == 50
assert normalize_spaces(page.select_one('tbody tr').text) == (
'2 test@example.com'
)
assert normalize_spaces(page.select_one('.table-show-more-link').text) == (
'Only showing the first 50 rows'
)
def test_save_contact_list(
mocker,
client_request,