From a9783f790734d9d4990728d982401341b57dea87 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 30 Nov 2020 14:20:53 +0000 Subject: [PATCH] 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. --- .../views/uploads/test_upload_contact_list.py | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) 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 9b5afd112..e3bfd34cb 100644 --- a/tests/app/main/views/uploads/test_upload_contact_list.py +++ b/tests/app/main/views/uploads/test_upload_contact_list.py @@ -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'