From ecc506306be556d51c64da05740b2a2539cd5499 Mon Sep 17 00:00:00 2001 From: Chris Hill Scott Date: Tue, 4 Jul 2017 13:38:08 +0100 Subject: [PATCH] Move helper function `test_utils.py` is actually a file for testing some utils, not some utils for testing. Test helper functions and fixtures are better placed in conftest, and also means that we can use them in conftest. --- tests/app/main/views/test_activity.py | 3 +-- tests/app/main/views/test_conversation.py | 2 +- tests/app/main/views/test_dashboard.py | 2 +- tests/app/main/views/test_jobs.py | 3 +-- tests/app/main/views/test_notifications.py | 3 +-- tests/app/main/views/test_send.py | 2 +- tests/app/main/views/test_service_settings.py | 2 +- tests/app/main/views/test_templates.py | 8 ++++++-- tests/app/test_utils.py | 6 ------ tests/conftest.py | 6 ++++++ 10 files changed, 19 insertions(+), 18 deletions(-) diff --git a/tests/app/main/views/test_activity.py b/tests/app/main/views/test_activity.py index 8872b5296..0ac91737a 100644 --- a/tests/app/main/views/test_activity.py +++ b/tests/app/main/views/test_activity.py @@ -8,8 +8,7 @@ from bs4 import BeautifulSoup from app.main.views.jobs import get_time_left, get_status_filters from tests import notification_json -from tests.conftest import SERVICE_ONE_ID, mock_get_notifications -from tests.app.test_utils import normalize_spaces +from tests.conftest import SERVICE_ONE_ID, mock_get_notifications, normalize_spaces from freezegun import freeze_time diff --git a/tests/app/main/views/test_conversation.py b/tests/app/main/views/test_conversation.py index e70aea412..0408690d5 100644 --- a/tests/app/main/views/test_conversation.py +++ b/tests/app/main/views/test_conversation.py @@ -8,7 +8,7 @@ from notifications_python_client.errors import HTTPError from tests.conftest import ( SERVICE_ONE_ID, ) -from tests.app.test_utils import normalize_spaces +from tests.conftest import normalize_spaces from freezegun import freeze_time from unittest import mock from app.main.views.conversation import get_user_number diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index d5819bc8e..668d2acd4 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -21,8 +21,8 @@ from tests.conftest import ( SERVICE_ONE_ID, mock_get_inbound_sms_summary, mock_get_inbound_sms_summary_with_no_messages, + normalize_spaces, ) -from tests.app.test_utils import normalize_spaces stub_template_stats = [ { diff --git a/tests/app/main/views/test_jobs.py b/tests/app/main/views/test_jobs.py index ad9abb6ae..3a4a65b82 100644 --- a/tests/app/main/views/test_jobs.py +++ b/tests/app/main/views/test_jobs.py @@ -8,8 +8,7 @@ from bs4 import BeautifulSoup from app.main.views.jobs import get_time_left, get_status_filters from tests import notification_json -from tests.app.test_utils import normalize_spaces -from tests.conftest import SERVICE_ONE_ID +from tests.conftest import SERVICE_ONE_ID, normalize_spaces from freezegun import freeze_time diff --git a/tests/app/main/views/test_notifications.py b/tests/app/main/views/test_notifications.py index 6b7b8bb69..996394fda 100644 --- a/tests/app/main/views/test_notifications.py +++ b/tests/app/main/views/test_notifications.py @@ -8,8 +8,7 @@ from app.utils import ( DELIVERED_STATUSES, ) -from tests.app.test_utils import normalize_spaces -from tests.conftest import mock_get_notification, SERVICE_ONE_ID +from tests.conftest import mock_get_notification, SERVICE_ONE_ID, normalize_spaces @pytest.mark.parametrize('notification_status, expected_status', [ diff --git a/tests/app/main/views/test_send.py b/tests/app/main/views/test_send.py index acbb0ac73..f54cb0aaf 100644 --- a/tests/app/main/views/test_send.py +++ b/tests/app/main/views/test_send.py @@ -15,7 +15,6 @@ from notifications_utils.template import LetterPreviewTemplate, LetterImageTempl from notifications_utils.recipients import RecipientCSV from tests import validate_route_permission, validate_route_permission_with_client -from tests.app.test_utils import normalize_spaces from tests.conftest import ( mock_get_service_template, mock_get_service_template_with_placeholders, @@ -23,6 +22,7 @@ from tests.conftest import ( mock_get_service, mock_get_international_service, mock_get_service_email_template, + normalize_spaces, SERVICE_ONE_ID, ) diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index 54f5f5b22..6c0f70ac6 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -10,7 +10,7 @@ import app from app.main.views.service_settings import dummy_bearer_token from app.utils import email_safe from tests import validate_route_permission, service_json -from tests.app.test_utils import normalize_spaces +from tests.conftest import normalize_spaces from tests.conftest import active_user_with_permissions, platform_admin_user diff --git a/tests/app/main/views/test_templates.py b/tests/app/main/views/test_templates.py index 38446df14..e193c2a9c 100644 --- a/tests/app/main/views/test_templates.py +++ b/tests/app/main/views/test_templates.py @@ -7,9 +7,13 @@ from flask import url_for from freezegun import freeze_time from notifications_python_client.errors import HTTPError from tests.conftest import service_one as create_sample_service -from tests.conftest import mock_get_service_email_template, mock_get_service_letter_template, SERVICE_ONE_ID +from tests.conftest import ( + mock_get_service_email_template, + mock_get_service_letter_template, + normalize_spaces, + SERVICE_ONE_ID, +) from tests import validate_route_permission, template_json, single_notification_json -from tests.app.test_utils import normalize_spaces from app.main.views.templates import get_last_use_message, get_human_readable_delta diff --git a/tests/app/test_utils.py b/tests/app/test_utils.py index 9bfe8828b..e1fa0e4f3 100644 --- a/tests/app/test_utils.py +++ b/tests/app/test_utils.py @@ -154,9 +154,3 @@ def test_generate_notifications_csv_calls_twice_if_next_link(mocker): # mock_calls[0][2] is the kwargs from first call assert mock_get_notifications.mock_calls[0][2]['page'] == 1 assert mock_get_notifications.mock_calls[1][2]['page'] == 2 - - -def normalize_spaces(input): - if isinstance(input, str): - return ' '.join(input.split()) - return normalize_spaces(' '.join(item.text for item in input)) diff --git a/tests/conftest.py b/tests/conftest.py index 2afa1880e..69fc41a23 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1778,3 +1778,9 @@ def client_request(logged_in_client): return BeautifulSoup(resp.data.decode('utf-8'), 'html.parser') return ClientRequest + + +def normalize_spaces(input): + if isinstance(input, str): + return ' '.join(input.split()) + return normalize_spaces(' '.join(item.text for item in input))