From e4edddbeab0b14680e89ccdbbab98c619cdf332e Mon Sep 17 00:00:00 2001 From: Katie Smith Date: Thu, 7 Mar 2019 16:44:11 +0000 Subject: [PATCH] Delete unused functions and their tests --- app/main/views/dashboard.py | 14 --------- app/main/views/send.py | 27 ---------------- app/main/views/templates.py | 22 ------------- tests/app/main/views/test_dashboard.py | 43 -------------------------- tests/app/main/views/test_templates.py | 22 +------------ 5 files changed, 1 insertion(+), 127 deletions(-) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index e3510d85e..99f0bdceb 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -523,20 +523,6 @@ def requested_and_current_financial_year(request): abort(404) -def format_template_stats_to_list(stats_dict): - if not stats_dict: - return [] - for template_id, template in stats_dict.items(): - yield dict( - requested_count=sum( - template['counts'].get(status, 0) - for status in REQUESTED_STATUSES - ), - id=template_id, - **template - ) - - def get_tuples_of_financial_years( partial_url, start=2015, diff --git a/app/main/views/send.py b/app/main/views/send.py index e61dd8935..dc6fb6aaa 100644 --- a/app/main/views/send.py +++ b/app/main/views/send.py @@ -60,14 +60,6 @@ from app.utils import ( ) -def get_page_headings(template_type): - return { - 'email': 'Email templates', - 'sms': 'Text message templates', - 'letter': 'Letter templates' - }[template_type] - - def get_example_csv_fields(column_headers, use_example_as_example, submitted_fields): if use_example_as_example: return ["example" for header in column_headers] @@ -776,25 +768,6 @@ def get_recipient_and_placeholders_from_session(template_type): return placeholders -def make_and_upload_csv_file(service_id, template): - upload_id = s3upload( - service_id, - Spreadsheet.from_dict( - session['placeholders'], - filename=current_app.config['TEST_MESSAGE_FILENAME'] - ).as_dict, - current_app.config['AWS_REGION'], - ) - return redirect(url_for( - '.check_messages', - upload_id=upload_id, - service_id=service_id, - template_id=template.id, - from_test=True, - help=2 if get_help_argument() else 0 - )) - - def all_placeholders_in_session(placeholders): return all( get_normalised_placeholders_from_session().get(placeholder, False) not in (False, None) diff --git a/app/main/views/templates.py b/app/main/views/templates.py index 44eddb4b4..22dc8d57f 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -850,21 +850,6 @@ def get_template_sender_form_dict(service_id, template): return context -def get_last_use_message(template_name, template_statistics): - try: - most_recent_use = max( - parse(template_stats['updated_at']).replace(tzinfo=None) - for template_stats in template_statistics - ) - except ValueError: - return '{} has never been used'.format(template_name) - - return '{} was last used {} ago'.format( - template_name, - get_human_readable_delta(most_recent_use, datetime.utcnow()) - ) - - def get_human_readable_delta(from_time, until_time): delta = until_time - from_time if delta < timedelta(seconds=60): @@ -878,10 +863,3 @@ def get_human_readable_delta(from_time, until_time): else: days = delta.days return '{} day{}'.format(days, '' if days == 1 else 's') - - -def should_show_template(template_type): - return ( - template_type != 'letter' or - current_service.has_permission('letter') - ) diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index 9de1bd041..07e555585 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -14,7 +14,6 @@ from app.main.views.dashboard import ( aggregate_status_types, aggregate_template_usage, format_monthly_stats_to_list, - format_template_stats_to_list, get_dashboard_totals, get_free_paid_breakdown_for_billable_units, get_tuples_of_financial_years, @@ -1269,48 +1268,6 @@ def test_get_free_paid_breakdown_for_billable_units(now, expected_number_of_mont ][:expected_number_of_months] -def test_format_template_stats_to_list_with_no_stats(): - assert list(format_template_stats_to_list({})) == [] - - -def test_format_template_stats_to_list(): - counts = { - 'created': 1, - 'pending': 1, - 'delivered': 1, - 'failed': 1, - 'temporary-failure': 1, - 'permanent-failure': 1, - 'technical-failure': 1, - 'do-not-count': 999, - } - stats_list = list(format_template_stats_to_list({ - 'template_2_id': { - 'counts': {}, - 'name': 'bar', - }, - 'template_1_id': { - 'counts': counts, - 'name': 'foo', - }, - })) - - # we don’t care about the order of this function’s output - assert len(stats_list) == 2 - assert { - 'counts': counts, - 'name': 'foo', - 'requested_count': 7, - 'id': 'template_1_id', - } in stats_list - assert { - 'counts': {}, - 'name': 'bar', - 'requested_count': 0, - 'id': 'template_2_id', - } in stats_list - - def test_get_tuples_of_financial_years(): assert list(get_tuples_of_financial_years( lambda year: 'http://example.com?year={}'.format(year), diff --git a/tests/app/main/views/test_templates.py b/tests/app/main/views/test_templates.py index 4b9521432..9432a0b87 100644 --- a/tests/app/main/views/test_templates.py +++ b/tests/app/main/views/test_templates.py @@ -8,10 +8,7 @@ from flask import url_for from freezegun import freeze_time from notifications_python_client.errors import HTTPError -from app.main.views.templates import ( - get_human_readable_delta, - get_last_use_message, -) +from app.main.views.templates import get_human_readable_delta from tests import ( single_notification_json, template_json, @@ -1920,23 +1917,6 @@ def test_route_invalid_permissions( service_one) -def test_get_last_use_message_returns_no_template_message(): - assert get_last_use_message('My Template', []) == 'My Template has never been used' - - -@freeze_time('2000-01-01T15:00') -def test_get_last_use_message_uses_most_recent_statistics(): - template_statistics = [ - { - 'updated_at': '2000-01-01T12:00:00.000000+00:00' - }, - { - 'updated_at': '2000-01-01T09:00:00.000000+00:00' - }, - ] - assert get_last_use_message('My Template', template_statistics) == 'My Template was last used 3 hours ago' - - @pytest.mark.parametrize('from_time, until_time, message', [ (datetime(2000, 1, 1, 12, 0), datetime(2000, 1, 1, 12, 0, 59), 'under a minute'), (datetime(2000, 1, 1, 12, 0), datetime(2000, 1, 1, 12, 1), '1 minute'),