From f93df53ed37c2bdefa460c968e04af65e47736ef Mon Sep 17 00:00:00 2001 From: Katie Smith Date: Mon, 6 Jan 2020 15:29:21 +0000 Subject: [PATCH] Stop calling more fixtures as functions This commits stops calling more fixtures as if they were functions in order to reduce the number of errors with Pytest 5. --- tests/app/main/views/test_dashboard.py | 42 ++++++++++++++------ tests/app/main/views/test_email_branding.py | 4 +- tests/app/main/views/test_send.py | 44 +++++++++++---------- tests/app/main/views/test_templates.py | 6 +-- 4 files changed, 58 insertions(+), 38 deletions(-) diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index 7d0ebc05c..a31f5bb89 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -27,8 +27,6 @@ from tests.conftest import ( SERVICE_ONE_ID, create_active_caseworking_user, create_active_user_view_permissions, - mock_get_inbound_sms_summary, - mock_get_inbound_sms_summary_with_no_messages, normalize_spaces, ) @@ -207,11 +205,7 @@ def test_inbound_messages_not_visible_to_service_without_permissions( assert mock_get_inbound_sms_summary.called is False -@pytest.mark.parametrize('inbound_summary_mock, expected_text', [ - (mock_get_inbound_sms_summary_with_no_messages, '0 text messages received'), - (mock_get_inbound_sms_summary, '99 text messages received latest message just now'), -]) -def test_inbound_messages_shows_count_of_messages( +def test_inbound_messages_shows_count_of_messages_when_there_are_messages( client_request, mocker, service_one, @@ -221,19 +215,41 @@ def test_inbound_messages_shows_count_of_messages( mock_get_template_statistics, mock_get_usage, mock_get_free_sms_fragment_limit, - inbound_summary_mock, - expected_text + mock_get_inbound_sms_summary, ): - service_one['permissions'] = ['inbound_sms'] - inbound_summary_mock(mocker) - page = client_request.get( 'main.service_dashboard', service_id=SERVICE_ONE_ID, ) - assert normalize_spaces(page.select('.big-number-meta-wrapper')[0].text) == expected_text + assert normalize_spaces( + page.select('.big-number-meta-wrapper')[0].text + ) == '99 text messages received latest message just now' + assert page.select('.big-number-meta-wrapper a')[0]['href'] == url_for( + 'main.inbox', service_id=SERVICE_ONE_ID + ) + + +def test_inbound_messages_shows_count_of_messages_when_there_are_no_messages( + client_request, + mocker, + service_one, + mock_get_service_templates_when_no_templates_exist, + mock_get_jobs, + mock_get_service_statistics, + mock_get_template_statistics, + mock_get_usage, + mock_get_free_sms_fragment_limit, + mock_get_inbound_sms_summary_with_no_messages, +): + service_one['permissions'] = ['inbound_sms'] + page = client_request.get( + 'main.service_dashboard', + service_id=SERVICE_ONE_ID, + ) + + assert normalize_spaces(page.select('.big-number-meta-wrapper')[0].text) == '0 text messages received' assert page.select('.big-number-meta-wrapper a')[0]['href'] == url_for( 'main.inbox', service_id=SERVICE_ONE_ID ) diff --git a/tests/app/main/views/test_email_branding.py b/tests/app/main/views/test_email_branding.py index 89e9052f9..92b4c236b 100644 --- a/tests/app/main/views/test_email_branding.py +++ b/tests/app/main/views/test_email_branding.py @@ -7,7 +7,7 @@ from flask import url_for from notifications_python_client.errors import HTTPError from app.s3_client.s3_logo_client import EMAIL_LOGO_LOCATION_STRUCTURE, TEMP_TAG -from tests.conftest import mock_get_email_branding, normalize_spaces +from tests.conftest import create_email_branding, normalize_spaces def test_email_branding_page_shows_full_branding_list( @@ -231,7 +231,7 @@ def test_deletes_previous_temp_logo_after_uploading_logo( fake_uuid ): if has_data: - mock_get_email_branding(mocker, fake_uuid) + mocker.patch('app.email_branding_client.get_email_branding', return_value=create_email_branding(fake_uuid)) with platform_admin_client.session_transaction() as session: user_id = session["user_id"] diff --git a/tests/app/main/views/test_send.py b/tests/app/main/views/test_send.py index 87d13aedd..3e44a10b0 100644 --- a/tests/app/main/views/test_send.py +++ b/tests/app/main/views/test_send.py @@ -45,8 +45,6 @@ from tests.conftest import ( multiple_sms_senders, multiple_sms_senders_no_inbound, multiple_sms_senders_with_diff_default, - no_reply_to_email_addresses, - no_sms_senders, normalize_spaces, ) @@ -204,26 +202,12 @@ def test_sender_session_is_present_after_selected( assert session['sender_id'] == '1234' -@pytest.mark.parametrize('template_mock, sender_data', [ - ( - mock_get_service_email_template, - no_reply_to_email_addresses, - ), - ( - mock_get_service_template, - no_sms_senders - ) -]) -def test_set_sender_redirects_if_no_sender_data( +def test_set_sender_redirects_if_no_reply_to_email_addresses( client_request, - service_one, fake_uuid, - template_mock, - sender_data, - mocker + mock_get_service_email_template, + no_reply_to_email_addresses, ): - template_mock(mocker) - sender_data(mocker) client_request.get( '.set_sender', service_id=SERVICE_ONE_ID, @@ -231,7 +215,27 @@ def test_set_sender_redirects_if_no_sender_data( _expected_status=302, _expected_url=url_for( '.send_one_off', - service_id=service_one['id'], + service_id=SERVICE_ONE_ID, + template_id=fake_uuid, + _external=True, + ) + ) + + +def test_set_sender_redirects_if_no_sms_senders( + client_request, + fake_uuid, + mock_get_service_template, + no_sms_senders, +): + client_request.get( + '.set_sender', + service_id=SERVICE_ONE_ID, + template_id=fake_uuid, + _expected_status=302, + _expected_url=url_for( + '.send_one_off', + service_id=SERVICE_ONE_ID, template_id=fake_uuid, _external=True, ) diff --git a/tests/app/main/views/test_templates.py b/tests/app/main/views/test_templates.py index 969370d57..fd6f2cfd2 100644 --- a/tests/app/main/views/test_templates.py +++ b/tests/app/main/views/test_templates.py @@ -551,8 +551,8 @@ def test_edit_letter_template_postage_page_displays_correctly( service_one, fake_uuid, mocker, + mock_get_service_letter_template, ): - mock_get_service_letter_template(mocker) page = client_request.get( 'main.edit_template_postage', service_id=SERVICE_ONE_ID, @@ -586,12 +586,12 @@ def test_edit_letter_templates_postage_updates_postage( client_request, service_one, mocker, - fake_uuid + fake_uuid, + mock_get_service_letter_template, ): mock_update_template_postage = mocker.patch( 'app.main.views.templates.service_api_client.update_service_template_postage' ) - mock_get_service_letter_template(mocker) client_request.post( 'main.edit_template_postage',