move contact list json to a constructor

reduces some duplication
This commit is contained in:
Leo Hemsted
2021-09-15 15:57:49 +01:00
parent 9e915703fd
commit 2494d6ce31
3 changed files with 62 additions and 53 deletions

View File

@@ -716,3 +716,28 @@ def broadcast_message_json(
'approved_by_id': approved_by_id, 'approved_by_id': approved_by_id,
'cancelled_by_id': cancelled_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,
}

View File

@@ -7,6 +7,7 @@ from flask import url_for
from freezegun import freeze_time from freezegun import freeze_time
from app.formatters import normalize_spaces from app.formatters import normalize_spaces
from tests import contact_list_json
from tests.conftest import SERVICE_ONE_ID from tests.conftest import SERVICE_ONE_ID
@@ -471,17 +472,11 @@ def test_view_contact_list(
): ):
mocker.patch( mocker.patch(
'app.models.contact_list.contact_list_api_client.get_contact_list', 'app.models.contact_list.contact_list_api_client.get_contact_list',
return_value={ return_value=contact_list_json(
'created_at': '2020-03-03 12:12:12', created_at='2020-03-03T12:12:12.000000Z',
'created_by': 'Test User', service_id=SERVICE_ONE_ID,
'id': fake_uuid, has_jobs=has_jobs
'original_file_name': 'EmergencyContactList.xls', )
'row_count': 100,
'recent_job_count': 0,
'has_jobs': has_jobs,
'service_id': SERVICE_ONE_ID,
'template_type': 'email',
},
) )
mocker.patch('app.models.contact_list.s3download', return_value='\n'.join( mocker.patch('app.models.contact_list.s3download', return_value='\n'.join(
['email address'] + [ ['email address'] + [

View File

@@ -20,6 +20,7 @@ from . import (
api_key_json, api_key_json,
assert_url_expected, assert_url_expected,
broadcast_message_json, broadcast_message_json,
contact_list_json,
generate_uuid, generate_uuid,
invite_json, invite_json,
job_json, job_json,
@@ -1851,37 +1852,31 @@ def mock_create_contact_list(mocker, api_user_active):
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
def mock_get_contact_lists(mocker, api_user_active, fake_uuid): def mock_get_contact_lists(mocker, api_user_active, fake_uuid):
def _get(service_id, template_type=None): def _get(service_id, template_type=None):
return [{ return [
'created_at': '2020-06-13T09:59:56.000000Z', contact_list_json(
'created_by': 'Test User', id_=fake_uuid,
'id': fake_uuid, created_at='2020-06-13T09:59:56.000000Z',
'original_file_name': 'EmergencyContactList.xls', service_id=service_id,
'row_count': 100, ),
'recent_job_count': 0, contact_list_json(
'has_jobs': True, id_='d7b0bd1a-d1c7-4621-be5c-3c1b4278a2ad',
'service_id': service_id, created_at='2020-06-13T12:00:00.000000Z',
'template_type': 'email', service_id=service_id,
}, { original_file_name='phone number list.csv',
'created_at': '2020-06-13T12:00:00.000000Z', row_count=123,
'created_by': 'Test User', recent_job_count=2,
'id': 'd7b0bd1a-d1c7-4621-be5c-3c1b4278a2ad', template_type='sms',
'original_file_name': 'phone number list.csv', ),
'row_count': 123, contact_list_json(
'recent_job_count': 2, id_=fake_uuid,
'has_jobs': True, created_at='2020-05-02T01:00:00.000000Z',
'service_id': service_id, original_file_name='UnusedList.tsv',
'template_type': 'sms', row_count=1,
}, { has_jobs=False,
'created_at': '2020-05-02T01:00:00.000000Z', service_id=service_id,
'created_by': 'Test User', template_type='sms',
'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 mocker.patch( return mocker.patch(
'app.models.contact_list.ContactLists.client_method', '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') @pytest.fixture(scope='function')
def mock_get_contact_list(mocker, api_user_active, fake_uuid): def mock_get_contact_list(mocker, api_user_active, fake_uuid):
def _get(*, service_id, contact_list_id): def _get(*, service_id, contact_list_id):
return { return contact_list_json(
'created_at': '2020-06-13T09:59:56.000000Z', id_=fake_uuid,
'created_by': 'Test User', created_at='2020-06-13T09:59:56.000000Z',
'id': fake_uuid, service_id=service_id,
'original_file_name': 'EmergencyContactList.xls', )
'row_count': 100,
'recent_job_count': 0,
'has_jobs': True,
'service_id': service_id,
'template_type': 'email',
}
return mocker.patch( return mocker.patch(
'app.models.contact_list.contact_list_api_client.get_contact_list', 'app.models.contact_list.contact_list_api_client.get_contact_list',