mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-26 19:48:32 -04:00
Archive, don’t delete contact lists
So we keep a record of who first uploaded a list it’s better to archive a list than completely delete it. The list in the database doesn’t contain any recipient info so this isn’t a change to what data we’re retaining. This means updating the endpoints that get contact lists to exclude ones that are archived.
This commit is contained in:
@@ -4,6 +4,11 @@ from tests.app.db import create_service_contact_list
|
||||
|
||||
def test_dao_get_contact_lists(notify_db_session):
|
||||
contact_list = create_service_contact_list()
|
||||
create_service_contact_list(
|
||||
service=contact_list.service,
|
||||
archived=True,
|
||||
)
|
||||
|
||||
fetched_list = dao_get_contact_lists(contact_list.service_id)
|
||||
|
||||
assert len(fetched_list) == 1
|
||||
|
||||
@@ -976,7 +976,8 @@ def create_service_contact_list(
|
||||
original_file_name='EmergencyContactList.xls',
|
||||
row_count=100,
|
||||
template_type='email',
|
||||
created_by_id=None
|
||||
created_by_id=None,
|
||||
archived=False,
|
||||
):
|
||||
if not service:
|
||||
service = create_service(service_name='service for contact list', user=create_user())
|
||||
@@ -988,6 +989,7 @@ def create_service_contact_list(
|
||||
template_type=template_type,
|
||||
created_by_id=created_by_id or service.users[0].id,
|
||||
created_at=datetime.utcnow(),
|
||||
archived=archived,
|
||||
)
|
||||
db.session.add(contact_list)
|
||||
db.session.commit()
|
||||
|
||||
@@ -238,12 +238,21 @@ def test_create_scheduled_job(client, sample_template, mocker, fake_uuid):
|
||||
assert resp_json['data']['notification_count'] == 1
|
||||
|
||||
|
||||
def test_create_job_with_contact_list_id(client, mocker, sample_template, fake_uuid):
|
||||
@pytest.mark.parametrize('contact_list_archived', (
|
||||
True, False,
|
||||
))
|
||||
def test_create_job_with_contact_list_id(
|
||||
client,
|
||||
mocker,
|
||||
sample_template,
|
||||
fake_uuid,
|
||||
contact_list_archived,
|
||||
):
|
||||
mocker.patch('app.celery.tasks.process_job.apply_async')
|
||||
mocker.patch('app.job.rest.get_job_metadata_from_s3', return_value={
|
||||
'template_id': str(sample_template.id)
|
||||
})
|
||||
contact_list = create_service_contact_list()
|
||||
contact_list = create_service_contact_list(archived=contact_list_archived)
|
||||
data = {
|
||||
'id': fake_uuid,
|
||||
'valid': 'True',
|
||||
|
||||
@@ -75,6 +75,7 @@ def test_get_contact_list_returns_for_service(admin_request, notify_db_session):
|
||||
expected_list_2 = create_service_contact_list(service=service_1)
|
||||
# not included in results
|
||||
create_service_contact_list(service=service_2)
|
||||
create_service_contact_list(service=service_1, archived=True)
|
||||
|
||||
response = admin_request.get(
|
||||
'service.get_contact_list',
|
||||
@@ -101,6 +102,16 @@ def test_dao_get_contact_list_by_id(admin_request, sample_service):
|
||||
assert response == expected_list_1.serialize()
|
||||
|
||||
|
||||
def test_dao_get_archived_contact_list_by_id(admin_request):
|
||||
contact_list = create_service_contact_list(archived=True)
|
||||
admin_request.get(
|
||||
'service.get_contact_list_by_id',
|
||||
service_id=contact_list.service.id,
|
||||
contact_list_id=contact_list.id,
|
||||
_expected_status=404,
|
||||
)
|
||||
|
||||
|
||||
def test_dao_get_contact_list_by_id_does_not_return_if_contact_list_id_for_another_service(
|
||||
admin_request, sample_service
|
||||
):
|
||||
@@ -120,7 +131,7 @@ def test_dao_get_contact_list_by_id_does_not_return_if_contact_list_id_for_anoth
|
||||
assert response['message'] == "No result found"
|
||||
|
||||
|
||||
def test_dao_delete_contact_list_by_id(mocker, admin_request, sample_service):
|
||||
def test_archive_contact_list_by_id(mocker, admin_request, sample_service):
|
||||
mock_s3 = mocker.patch('app.service.rest.s3.remove_contact_list_from_s3')
|
||||
service_1 = create_service(service_name='Service under test')
|
||||
template_1 = create_template(service=service_1)
|
||||
@@ -137,8 +148,12 @@ def test_dao_delete_contact_list_by_id(mocker, admin_request, sample_service):
|
||||
contact_list_id=expected_list.id,
|
||||
)
|
||||
|
||||
assert job_1.contact_list_id is None
|
||||
assert job_1.contact_list_id == expected_list.id
|
||||
assert expected_list.archived is True
|
||||
|
||||
assert job_2.contact_list_id == other_list.id
|
||||
assert other_list.archived is False
|
||||
|
||||
assert job_3.contact_list_id is None
|
||||
|
||||
mock_s3.assert_called_once_with(
|
||||
@@ -147,7 +162,7 @@ def test_dao_delete_contact_list_by_id(mocker, admin_request, sample_service):
|
||||
)
|
||||
|
||||
|
||||
def test_dao_delete_contact_list_when_unused(mocker, admin_request, sample_service):
|
||||
def test_archive_contact_list_when_unused(mocker, admin_request, sample_service):
|
||||
mock_s3 = mocker.patch('app.service.rest.s3.remove_contact_list_from_s3')
|
||||
service = create_service(service_name='Service under test')
|
||||
expected_list = create_service_contact_list(service=service)
|
||||
@@ -160,7 +175,8 @@ def test_dao_delete_contact_list_when_unused(mocker, admin_request, sample_servi
|
||||
contact_list_id=expected_list.id
|
||||
)
|
||||
|
||||
assert ServiceContactList.query.count() == 0
|
||||
assert ServiceContactList.query.count() == 1
|
||||
assert expected_list.archived is True
|
||||
|
||||
mock_s3.assert_called_once_with(
|
||||
expected_list.service.id,
|
||||
@@ -168,7 +184,7 @@ def test_dao_delete_contact_list_when_unused(mocker, admin_request, sample_servi
|
||||
)
|
||||
|
||||
|
||||
def test_dao_delete_contact_list_by_id_for_different_service(mocker, admin_request, sample_service):
|
||||
def test_archive_contact_list_by_id_for_different_service(mocker, admin_request, sample_service):
|
||||
|
||||
mock_s3 = mocker.patch('app.service.rest.s3.remove_contact_list_from_s3')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user