mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-20 14:29:51 -04:00
Use the correct bucket for storing contact lists
We don’t want to muddy them up with the normal CSV uploads. I’ve tried to reuse the existing S3 code where possible because it’s well tested. Buckets have already been created.
This commit is contained in:
@@ -885,9 +885,14 @@ def test_upload_csv_file_shows_error_banner(
|
||||
expected_thead,
|
||||
expected_tbody,
|
||||
):
|
||||
|
||||
mock_upload = mocker.patch('app.main.views.uploads.s3upload', return_value=fake_uuid)
|
||||
mock_download = mocker.patch('app.main.views.uploads.s3download', return_value=file_contents)
|
||||
mock_upload = mocker.patch(
|
||||
'app.models.contact_list.s3upload',
|
||||
return_value=fake_uuid,
|
||||
)
|
||||
mock_download = mocker.patch(
|
||||
'app.models.contact_list.s3download',
|
||||
return_value=file_contents,
|
||||
)
|
||||
|
||||
page = client_request.post(
|
||||
'main.upload_contact_list',
|
||||
@@ -896,9 +901,16 @@ def test_upload_csv_file_shows_error_banner(
|
||||
_follow_redirects=True,
|
||||
)
|
||||
mock_upload.assert_called_once_with(
|
||||
SERVICE_ONE_ID, {'data': '', 'file_name': 'invalid.csv'}, ANY,
|
||||
SERVICE_ONE_ID,
|
||||
{'data': '', 'file_name': 'invalid.csv'},
|
||||
ANY,
|
||||
bucket='test-contact-list',
|
||||
)
|
||||
mock_download.assert_called_once_with(
|
||||
SERVICE_ONE_ID,
|
||||
fake_uuid,
|
||||
bucket='test-contact-list',
|
||||
)
|
||||
mock_download.assert_called_once_with(SERVICE_ONE_ID, fake_uuid)
|
||||
|
||||
assert normalize_spaces(page.select_one('.banner-dangerous').text) == expected_error
|
||||
|
||||
@@ -920,9 +932,8 @@ def test_upload_csv_file_shows_error_banner_for_too_many_rows(
|
||||
mock_get_users_by_service,
|
||||
fake_uuid,
|
||||
):
|
||||
|
||||
mocker.patch('app.main.views.uploads.s3upload', return_value=fake_uuid)
|
||||
mocker.patch('app.main.views.uploads.s3download', return_value='\n'.join(
|
||||
mocker.patch('app.models.contact_list.s3upload', return_value=fake_uuid)
|
||||
mocker.patch('app.models.contact_list.s3download', return_value='\n'.join(
|
||||
['phone number'] + (['07700900986'] * 50001)
|
||||
))
|
||||
|
||||
@@ -952,8 +963,8 @@ def test_upload_csv_shows_trial_mode_error(
|
||||
fake_uuid,
|
||||
mocker
|
||||
):
|
||||
mocker.patch('app.main.views.uploads.s3upload', return_value=fake_uuid)
|
||||
mocker.patch('app.main.views.uploads.s3download', return_value=(
|
||||
mocker.patch('app.models.contact_list.s3upload', return_value=fake_uuid)
|
||||
mocker.patch('app.models.contact_list.s3download', return_value=(
|
||||
'phone number\n'
|
||||
'07900900321' # Not in team
|
||||
))
|
||||
@@ -983,10 +994,10 @@ def test_upload_csv_shows_ok_page(
|
||||
fake_uuid,
|
||||
mocker
|
||||
):
|
||||
mocker.patch('app.main.views.uploads.s3download', return_value='\n'.join(
|
||||
mocker.patch('app.models.contact_list.s3download', return_value='\n'.join(
|
||||
['email address'] + ['test@example.com'] * 51
|
||||
))
|
||||
mock_metadata_set = mocker.patch('app.main.views.uploads.set_metadata_on_csv_upload')
|
||||
mock_metadata_set = mocker.patch('app.models.contact_list.set_metadata_on_csv_upload')
|
||||
|
||||
page = client_request.get(
|
||||
'main.check_contact_list',
|
||||
@@ -999,6 +1010,7 @@ def test_upload_csv_shows_ok_page(
|
||||
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',
|
||||
@@ -1038,7 +1050,7 @@ def test_save_contact_list(
|
||||
fake_uuid,
|
||||
mock_create_contact_list,
|
||||
):
|
||||
mocker.patch('app.models.contact_list.get_csv_metadata', return_value={
|
||||
mock_get_metadata = mocker.patch('app.models.contact_list.get_csv_metadata', return_value={
|
||||
'row_count': 999,
|
||||
'valid': True,
|
||||
'original_file_name': 'example.csv',
|
||||
@@ -1056,6 +1068,11 @@ def test_save_contact_list(
|
||||
_external=True,
|
||||
)
|
||||
)
|
||||
mock_get_metadata.assert_called_once_with(
|
||||
SERVICE_ONE_ID,
|
||||
fake_uuid,
|
||||
bucket='test-contact-list',
|
||||
)
|
||||
mock_create_contact_list.assert_called_once_with(
|
||||
service_id=SERVICE_ONE_ID,
|
||||
upload_id=fake_uuid,
|
||||
|
||||
@@ -12,7 +12,7 @@ def test_sets_metadata(client, mocker):
|
||||
|
||||
set_metadata_on_csv_upload('1234', '5678', foo='bar', baz=True)
|
||||
|
||||
mocked_get_s3_object.assert_called_once_with('1234', '5678')
|
||||
mocked_get_s3_object.assert_called_once_with('1234', '5678', bucket=None)
|
||||
mocked_s3_object.copy_from.assert_called_once_with(
|
||||
CopySource='test-notifications-csv-upload/service-1234-notify/5678.csv',
|
||||
Metadata={'baz': 'True', 'foo': 'bar'},
|
||||
|
||||
Reference in New Issue
Block a user