Test for old but unused contact lists

Old contact lists can be:
- never used
- used, but so long ago we no longer have data about the jobs due to
  retention settings

We show different messages in each of these cases. This commit
parametrizes the tests to ensure that both cases are covered.

Also makes the job a bit older so that both cases are logically possible
with the test data.
This commit is contained in:
Chris Hill-Scott
2020-11-30 14:20:53 +00:00
parent 94c713e1b4
commit a9783f7907

View File

@@ -452,6 +452,10 @@ def test_cant_save_bad_contact_list(
assert mock_create_contact_list.called is False
@pytest.mark.parametrize('has_jobs, expected_empty_message', [
(False, 'Not used yet.'),
(True, 'Not used in the last 7 days.'),
])
@freeze_time('2020-03-13 16:51:56')
def test_view_contact_list(
mocker,
@@ -460,7 +464,23 @@ def test_view_contact_list(
mock_get_no_jobs,
mock_get_service_data_retention,
fake_uuid,
has_jobs,
expected_empty_message,
):
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',
},
)
mocker.patch('app.models.contact_list.s3download', return_value='\n'.join(
['email address'] + [
f'test-{i}@example.com' for i in range(51)
@@ -475,10 +495,10 @@ def test_view_contact_list(
'EmergencyContactList.xls'
)
assert normalize_spaces(page.select('main p')[0].text) == (
'Uploaded by Test User today at 10:59am.'
'Uploaded by Test User on 3 March at 12:12pm.'
)
assert normalize_spaces(page.select('main p')[1].text) == (
'Not used in the last 7 days.'
expected_empty_message
)
assert normalize_spaces(page.select_one('main h2').text) == (
'51 saved email addresses'