diff --git a/tests/__init__.py b/tests/__init__.py index 8c9d5ad12..38ce75c29 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -716,3 +716,28 @@ def broadcast_message_json( 'approved_by_id': approved_by_id, 'cancelled_by_id': cancelled_by_id, } + + +def contact_list_json( + *, + id_=None, + created_at='2020-06-13T09:59:56.000000Z', + created_by='Test User', + service_id, + original_file_name='EmergencyContactList.xls', + row_count=100, + recent_job_count=0, + has_jobs=True, + template_type='email', +): + return { + 'id': id_ or sample_uuid(), + 'created_at': created_at, + 'created_by': created_by, + 'service_id': service_id, + 'original_file_name': original_file_name, + 'row_count': row_count, + 'recent_job_count': recent_job_count, + 'has_jobs': has_jobs, + 'template_type': template_type, + } diff --git a/tests/app/main/views/uploads/test_upload_contact_list.py b/tests/app/main/views/uploads/test_upload_contact_list.py index 96c0d3f37..40a0ee6bb 100644 --- a/tests/app/main/views/uploads/test_upload_contact_list.py +++ b/tests/app/main/views/uploads/test_upload_contact_list.py @@ -7,6 +7,7 @@ from flask import url_for from freezegun import freeze_time from app.formatters import normalize_spaces +from tests import contact_list_json from tests.conftest import SERVICE_ONE_ID @@ -471,17 +472,11 @@ def test_view_contact_list( ): mocker.patch( 'app.models.contact_list.contact_list_api_client.get_contact_list', - return_value={ - 'created_at': '2020-03-03 12:12:12', - 'created_by': 'Test User', - 'id': fake_uuid, - 'original_file_name': 'EmergencyContactList.xls', - 'row_count': 100, - 'recent_job_count': 0, - 'has_jobs': has_jobs, - 'service_id': SERVICE_ONE_ID, - 'template_type': 'email', - }, + return_value=contact_list_json( + created_at='2020-03-03T12:12:12.000000Z', + service_id=SERVICE_ONE_ID, + has_jobs=has_jobs + ) ) mocker.patch('app.models.contact_list.s3download', return_value='\n'.join( ['email address'] + [ diff --git a/tests/conftest.py b/tests/conftest.py index 7b9cf9159..f45a38919 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -20,6 +20,7 @@ from . import ( api_key_json, assert_url_expected, broadcast_message_json, + contact_list_json, generate_uuid, invite_json, job_json, @@ -1851,37 +1852,31 @@ def mock_create_contact_list(mocker, api_user_active): @pytest.fixture(scope='function') def mock_get_contact_lists(mocker, api_user_active, fake_uuid): def _get(service_id, template_type=None): - return [{ - 'created_at': '2020-06-13T09:59:56.000000Z', - 'created_by': 'Test User', - 'id': fake_uuid, - 'original_file_name': 'EmergencyContactList.xls', - 'row_count': 100, - 'recent_job_count': 0, - 'has_jobs': True, - 'service_id': service_id, - 'template_type': 'email', - }, { - 'created_at': '2020-06-13T12:00:00.000000Z', - 'created_by': 'Test User', - 'id': 'd7b0bd1a-d1c7-4621-be5c-3c1b4278a2ad', - 'original_file_name': 'phone number list.csv', - 'row_count': 123, - 'recent_job_count': 2, - 'has_jobs': True, - 'service_id': service_id, - 'template_type': 'sms', - }, { - 'created_at': '2020-05-02T01:00:00.000000Z', - 'created_by': 'Test User', - 'id': fake_uuid, - 'original_file_name': 'UnusedList.tsv', - 'row_count': 1, - 'recent_job_count': 0, - 'has_jobs': False, - 'service_id': service_id, - 'template_type': 'sms', - }] + return [ + contact_list_json( + id_=fake_uuid, + created_at='2020-06-13T09:59:56.000000Z', + service_id=service_id, + ), + contact_list_json( + id_='d7b0bd1a-d1c7-4621-be5c-3c1b4278a2ad', + created_at='2020-06-13T12:00:00.000000Z', + service_id=service_id, + original_file_name='phone number list.csv', + row_count=123, + recent_job_count=2, + template_type='sms', + ), + contact_list_json( + id_=fake_uuid, + created_at='2020-05-02T01:00:00.000000Z', + original_file_name='UnusedList.tsv', + row_count=1, + has_jobs=False, + service_id=service_id, + template_type='sms', + ) + ] return mocker.patch( 'app.models.contact_list.ContactLists.client_method', @@ -1892,17 +1887,11 @@ def mock_get_contact_lists(mocker, api_user_active, fake_uuid): @pytest.fixture(scope='function') def mock_get_contact_list(mocker, api_user_active, fake_uuid): def _get(*, service_id, contact_list_id): - return { - 'created_at': '2020-06-13T09:59:56.000000Z', - 'created_by': 'Test User', - 'id': fake_uuid, - 'original_file_name': 'EmergencyContactList.xls', - 'row_count': 100, - 'recent_job_count': 0, - 'has_jobs': True, - 'service_id': service_id, - 'template_type': 'email', - } + return contact_list_json( + id_=fake_uuid, + created_at='2020-06-13T09:59:56.000000Z', + service_id=service_id, + ) return mocker.patch( 'app.models.contact_list.contact_list_api_client.get_contact_list',