From e0de65cd81a166e01e2a63ded676ce6d0858f6d2 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 26 May 2020 13:25:40 +0100 Subject: [PATCH] Call mock rather than using fixture MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Our get_notifications fixture tries to be too clever and work out which fields to return based on what arguments it’s called with. This is very indirect and makes the tests less specific. In other places we call the mocking code directly with arguments that make it more explicit what the mocked response should be. This commit does this for tests that we’d otherwise have to make changes to the fixture for, because postage can no longer be `None` for letter notifications. --- tests/__init__.py | 3 ++- tests/app/main/views/test_jobs.py | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index dba3573c1..f1a8d6626 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -443,7 +443,8 @@ def notification_json( if status is None: status = 'delivered' links = {} - postage = postage or 'second' + if template_type == 'letter': + postage = postage or 'second' if with_links: links = { diff --git a/tests/app/main/views/test_jobs.py b/tests/app/main/views/test_jobs.py index 8a81153b4..996d77dcc 100644 --- a/tests/app/main/views/test_jobs.py +++ b/tests/app/main/views/test_jobs.py @@ -349,13 +349,17 @@ def test_should_show_letter_job( @freeze_time("2016-01-01 11:09:00") def test_should_show_letter_job_with_banner_after_sending_before_1730( + mocker, client_request, mock_get_service_letter_template, mock_get_letter_job, - mock_get_notifications, mock_get_service_data_retention, fake_uuid, ): + mocker.patch( + 'app.notification_api_client.get_notifications_for_service', + return_value=create_notifications(template_type='letter', postage='second') + ) page = client_request.get( 'main.view_job', @@ -373,13 +377,17 @@ def test_should_show_letter_job_with_banner_after_sending_before_1730( @freeze_time("2016-01-01 11:09:00") def test_should_show_letter_job_with_banner_when_there_are_multiple_CSV_rows( + mocker, client_request, mock_get_service_letter_template, mock_get_letter_job_in_progress, - mock_get_notifications, mock_get_service_data_retention, fake_uuid, ): + mocker.patch( + 'app.notification_api_client.get_notifications_for_service', + return_value=create_notifications(template_type='letter', postage='second') + ) page = client_request.get( 'main.view_job', @@ -396,13 +404,17 @@ def test_should_show_letter_job_with_banner_when_there_are_multiple_CSV_rows( @freeze_time("2016-01-01 18:09:00") def test_should_show_letter_job_with_banner_after_sending_after_1730( + mocker, client_request, mock_get_service_letter_template, mock_get_letter_job, - mock_get_notifications, mock_get_service_data_retention, fake_uuid, ): + mocker.patch( + 'app.notification_api_client.get_notifications_for_service', + return_value=create_notifications(template_type='letter', postage='second') + ) page = client_request.get( 'main.view_job',