mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 13:39:41 -04:00
Remove contact-list references from code
This commit is contained in:
@@ -6,13 +6,11 @@ from io import BytesIO
|
||||
from itertools import repeat
|
||||
from os import path
|
||||
from random import randbytes
|
||||
from unittest.mock import ANY
|
||||
from uuid import uuid4
|
||||
from zipfile import BadZipFile
|
||||
|
||||
import pytest
|
||||
from flask import url_for
|
||||
from freezegun import freeze_time
|
||||
from notifications_python_client.errors import HTTPError
|
||||
from notifications_utils.recipients import RecipientCSV
|
||||
from notifications_utils.template import SMSPreviewTemplate
|
||||
@@ -1034,7 +1032,6 @@ def test_send_one_off_step_redirects_to_start_if_session_not_setup(
|
||||
mock_get_service_statistics,
|
||||
mock_get_users_by_service,
|
||||
mock_has_no_jobs,
|
||||
mock_get_no_contact_lists,
|
||||
fake_uuid,
|
||||
template_type,
|
||||
):
|
||||
@@ -1093,7 +1090,6 @@ def test_send_one_off_has_correct_page_title(
|
||||
client_request,
|
||||
service_one,
|
||||
mock_has_no_jobs,
|
||||
mock_get_no_contact_lists,
|
||||
fake_uuid,
|
||||
mocker,
|
||||
user,
|
||||
@@ -1135,7 +1131,6 @@ def test_send_one_off_shows_placeholders_in_correct_order(
|
||||
client_request,
|
||||
fake_uuid,
|
||||
mock_has_no_jobs,
|
||||
mock_get_no_contact_lists,
|
||||
mock_get_service_template_with_multiple_placeholders,
|
||||
step_index,
|
||||
prefilled,
|
||||
@@ -1180,7 +1175,6 @@ def test_send_one_off_has_skip_link(
|
||||
fake_uuid,
|
||||
mock_get_service_email_template,
|
||||
mock_has_no_jobs,
|
||||
mock_get_no_contact_lists,
|
||||
mocker,
|
||||
template_type,
|
||||
expected_link_text,
|
||||
@@ -1221,7 +1215,6 @@ def test_send_one_off_has_sticky_header_for_email(
|
||||
client_request,
|
||||
fake_uuid,
|
||||
mock_has_no_jobs,
|
||||
mock_get_no_contact_lists,
|
||||
template_type,
|
||||
expected_sticky,
|
||||
):
|
||||
@@ -1249,7 +1242,6 @@ def test_skip_link_will_not_show_on_sms_one_off_if_service_has_no_mobile_number(
|
||||
fake_uuid,
|
||||
mock_get_service_template,
|
||||
mock_has_no_jobs,
|
||||
mock_get_no_contact_lists,
|
||||
mocker,
|
||||
user,
|
||||
):
|
||||
@@ -1279,7 +1271,6 @@ def test_send_one_off_offers_link_to_upload(
|
||||
fake_uuid,
|
||||
mock_get_service_template,
|
||||
mock_has_jobs,
|
||||
mock_get_no_contact_lists,
|
||||
user,
|
||||
):
|
||||
client_request.login(user)
|
||||
@@ -1307,7 +1298,6 @@ def test_send_one_off_has_link_to_use_existing_list(
|
||||
client_request,
|
||||
mock_get_service_template,
|
||||
mock_has_jobs,
|
||||
mock_get_contact_lists,
|
||||
fake_uuid,
|
||||
):
|
||||
page = client_request.get(
|
||||
@@ -1328,14 +1318,6 @@ def test_send_one_off_has_link_to_use_existing_list(
|
||||
template_id=fake_uuid,
|
||||
),
|
||||
),
|
||||
(
|
||||
'Use an emergency list',
|
||||
url_for(
|
||||
'main.choose_from_contact_list',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
template_id=fake_uuid,
|
||||
),
|
||||
),
|
||||
(
|
||||
'Use my phone number',
|
||||
url_for(
|
||||
@@ -1347,33 +1329,6 @@ def test_send_one_off_has_link_to_use_existing_list(
|
||||
]
|
||||
|
||||
|
||||
def test_no_link_to_use_existing_list_for_service_without_lists(
|
||||
mocker,
|
||||
client_request,
|
||||
mock_get_service_template,
|
||||
mock_has_jobs,
|
||||
platform_admin_user,
|
||||
fake_uuid,
|
||||
):
|
||||
mocker.patch(
|
||||
'app.models.contact_list.ContactLists.client_method',
|
||||
return_value=[],
|
||||
)
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'main.send_one_off',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
template_id=fake_uuid,
|
||||
_follow_redirects=True,
|
||||
)
|
||||
assert [
|
||||
link.text for link in page.select('form a')
|
||||
] == [
|
||||
'Upload a list of phone numbers',
|
||||
'Use my phone number',
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('user', (
|
||||
create_active_user_with_permissions(),
|
||||
create_active_caseworking_user(),
|
||||
@@ -1590,7 +1545,6 @@ def test_send_one_off_step_0_back_link(
|
||||
mock_get_service,
|
||||
mock_get_service_template_with_placeholders,
|
||||
mock_has_no_jobs,
|
||||
mock_get_contact_lists,
|
||||
permissions,
|
||||
expected_back_link_endpoint,
|
||||
extra_args,
|
||||
@@ -1671,7 +1625,6 @@ def test_send_one_off_sms_message_puts_submitted_data_in_session(
|
||||
mock_get_service_template_with_placeholders,
|
||||
mock_get_users_by_service,
|
||||
mock_get_service_statistics,
|
||||
mock_get_contact_lists,
|
||||
fake_uuid,
|
||||
):
|
||||
with client_request.session_transaction() as session:
|
||||
@@ -1847,32 +1800,6 @@ def test_upload_csvfile_with_international_validates(
|
||||
assert mock_recipients.call_args[1]['allow_international_sms'] == should_allow_international
|
||||
|
||||
|
||||
def test_job_from_contact_list_knows_where_its_come_from(
|
||||
client_request,
|
||||
mocker,
|
||||
service_one,
|
||||
mock_get_service_template,
|
||||
mock_s3_download,
|
||||
mock_get_users_by_service,
|
||||
mock_get_service_statistics,
|
||||
mock_get_job_doesnt_exist,
|
||||
mock_get_jobs,
|
||||
mock_s3_get_metadata,
|
||||
mock_s3_set_metadata,
|
||||
fake_uuid
|
||||
):
|
||||
page = client_request.get(
|
||||
'main.check_messages',
|
||||
service_id=service_one['id'],
|
||||
upload_id=fake_uuid,
|
||||
template_id=fake_uuid,
|
||||
contact_list_id=unchanging_fake_uuid,
|
||||
)
|
||||
assert page.select_one(
|
||||
'form input[type=hidden][name=contact_list_id]'
|
||||
)['value'] == str(unchanging_fake_uuid)
|
||||
|
||||
|
||||
def test_test_message_can_only_be_sent_now(
|
||||
client_request,
|
||||
mocker,
|
||||
@@ -1932,9 +1859,6 @@ def test_send_button_is_correctly_labelled(
|
||||
@pytest.mark.parametrize('when', [
|
||||
'', '2016-08-25T13:04:21.767198'
|
||||
])
|
||||
@pytest.mark.parametrize('contact_list_id', [
|
||||
'', unchanging_fake_uuid,
|
||||
])
|
||||
def test_create_job_should_call_api(
|
||||
client_request,
|
||||
mock_create_job,
|
||||
@@ -1945,7 +1869,6 @@ def test_create_job_should_call_api(
|
||||
mocker,
|
||||
fake_uuid,
|
||||
when,
|
||||
contact_list_id,
|
||||
):
|
||||
data = mock_get_job(SERVICE_ONE_ID, fake_uuid)['data']
|
||||
job_id = data['id']
|
||||
@@ -1968,7 +1891,6 @@ def test_create_job_should_call_api(
|
||||
original_file_name=original_file_name,
|
||||
_data={
|
||||
'scheduled_for': when,
|
||||
'contact_list_id': contact_list_id,
|
||||
},
|
||||
_follow_redirects=True,
|
||||
_expected_status=200,
|
||||
@@ -1980,7 +1902,6 @@ def test_create_job_should_call_api(
|
||||
job_id,
|
||||
SERVICE_ONE_ID,
|
||||
scheduled_for=when,
|
||||
contact_list_id=str(contact_list_id),
|
||||
)
|
||||
|
||||
|
||||
@@ -2724,7 +2645,6 @@ def test_reply_to_is_previewed_if_chosen(
|
||||
mock_get_service_statistics,
|
||||
mock_get_job_doesnt_exist,
|
||||
mock_get_jobs,
|
||||
mock_get_no_contact_lists,
|
||||
get_default_reply_to_email_address,
|
||||
fake_uuid,
|
||||
endpoint,
|
||||
@@ -2777,7 +2697,6 @@ def test_sms_sender_is_previewed(
|
||||
mock_get_service_statistics,
|
||||
mock_get_job_doesnt_exist,
|
||||
mock_get_jobs,
|
||||
mock_get_no_contact_lists,
|
||||
get_default_sms_sender,
|
||||
fake_uuid,
|
||||
endpoint,
|
||||
@@ -2838,163 +2757,6 @@ def test_redirects_to_template_if_job_exists_already(
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize((
|
||||
'template_type, '
|
||||
'expected_list_id, '
|
||||
'expected_filenames, '
|
||||
'expected_time, '
|
||||
'expected_count'
|
||||
), (
|
||||
(
|
||||
'email',
|
||||
'6ce466d0-fd6a-11e5-82f5-e0accb9d11a6',
|
||||
['EmergencyContactList.xls'],
|
||||
'Uploaded today at 5:59am',
|
||||
'100 email addresses',
|
||||
),
|
||||
(
|
||||
'sms',
|
||||
'd7b0bd1a-d1c7-4621-be5c-3c1b4278a2ad',
|
||||
['phone number list.csv', 'UnusedList.tsv'],
|
||||
'Uploaded today at 8:00am',
|
||||
'123 phone numbers',
|
||||
),
|
||||
))
|
||||
@freeze_time('2020-06-13 13:00')
|
||||
def test_choose_from_contact_list(
|
||||
mocker,
|
||||
client_request,
|
||||
mock_get_contact_lists,
|
||||
fake_uuid,
|
||||
template_type,
|
||||
expected_list_id,
|
||||
expected_filenames,
|
||||
expected_time,
|
||||
expected_count,
|
||||
):
|
||||
template = create_template(template_type=template_type)
|
||||
mocker.patch(
|
||||
'app.service_api_client.get_service_template',
|
||||
return_value={'data': template},
|
||||
)
|
||||
page = client_request.get(
|
||||
'main.choose_from_contact_list',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
template_id=fake_uuid,
|
||||
)
|
||||
assert [
|
||||
normalize_spaces(filename.text)
|
||||
for filename in page.select('.file-list-filename-large')
|
||||
] == expected_filenames
|
||||
|
||||
assert page.select_one('a.file-list-filename-large')['href'] == url_for(
|
||||
'main.send_from_contact_list',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
template_id=template['id'],
|
||||
contact_list_id=expected_list_id,
|
||||
)
|
||||
assert normalize_spaces(page.select_one('.file-list-hint-large').text) == (
|
||||
expected_time
|
||||
)
|
||||
assert normalize_spaces(page.select_one('.big-number-smallest').text) == (
|
||||
expected_count
|
||||
)
|
||||
|
||||
|
||||
def test_choose_from_contact_list_with_personalised_template(
|
||||
mocker,
|
||||
client_request,
|
||||
mock_get_contact_lists,
|
||||
fake_uuid,
|
||||
):
|
||||
template = create_template(
|
||||
content="Hey ((name)) ((thing)) is happening"
|
||||
)
|
||||
mocker.patch(
|
||||
'app.service_api_client.get_service_template',
|
||||
return_value={'data': template},
|
||||
)
|
||||
page = client_request.get(
|
||||
'main.choose_from_contact_list',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
template_id=fake_uuid,
|
||||
)
|
||||
assert [
|
||||
normalize_spaces(p.text) for p in page.select('main p')
|
||||
] == [
|
||||
'You cannot use an emergency contact list with this template because '
|
||||
'it is personalized with ((name)) and ((thing)).',
|
||||
'Emergency contact lists can only include email addresses or phone numbers.',
|
||||
]
|
||||
assert not page.select('table')
|
||||
|
||||
|
||||
def test_choose_from_contact_list_with_no_lists(
|
||||
mocker,
|
||||
client_request,
|
||||
mock_get_service_template,
|
||||
fake_uuid,
|
||||
):
|
||||
mocker.patch(
|
||||
'app.models.contact_list.ContactLists.client_method',
|
||||
return_value=[],
|
||||
)
|
||||
page = client_request.get(
|
||||
'main.choose_from_contact_list',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
template_id=fake_uuid,
|
||||
)
|
||||
assert [
|
||||
normalize_spaces(p.text) for p in page.select('main p')
|
||||
] == [
|
||||
'You have not saved any lists of phone numbers yet.',
|
||||
'To upload and save an emergency contact list, go to the uploads page.',
|
||||
]
|
||||
assert page.select_one('main p a')['href'] == url_for(
|
||||
'main.uploads',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
)
|
||||
assert not page.select('table')
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="Need to figure out how to handle cross-bucket copies.")
|
||||
def test_send_from_contact_list(
|
||||
mocker,
|
||||
client_request,
|
||||
fake_uuid,
|
||||
mock_get_contact_list,
|
||||
):
|
||||
new_uuid = uuid.uuid4()
|
||||
mock_download = mocker.patch('app.models.contact_list.get_s3_contents', return_value='contents')
|
||||
mock_get_metadata = mocker.patch('app.models.contact_list.get_s3_metadata', return_value={
|
||||
'example_key': 'example value',
|
||||
})
|
||||
mock_upload = mocker.patch('app.models.contact_list.s3upload', return_value=new_uuid)
|
||||
mock_set_metadata = mocker.patch('app.models.contact_list.set_metadata_on_csv_upload')
|
||||
client_request.get(
|
||||
'main.send_from_contact_list',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
template_id=fake_uuid,
|
||||
contact_list_id=fake_uuid,
|
||||
_expected_status=302,
|
||||
_expected_redirect=url_for(
|
||||
'main.check_messages',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
template_id=fake_uuid,
|
||||
upload_id=new_uuid,
|
||||
contact_list_id=fake_uuid,
|
||||
)
|
||||
)
|
||||
mock_download.assert_called_once()
|
||||
mock_get_metadata.assert_called_once()
|
||||
mock_upload.assert_called_once_with(
|
||||
SERVICE_ONE_ID, {'data': 'contents'}, ANY
|
||||
)
|
||||
mock_set_metadata.assert_called_once_with(
|
||||
SERVICE_ONE_ID, new_uuid, example_key='example value'
|
||||
)
|
||||
|
||||
|
||||
def test_send_to_myself_sets_placeholder_and_redirects_for_email(
|
||||
mocker, client_request, fake_uuid, mock_get_service_email_template
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user