mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-08 08:28:15 -04:00
Merge pull request #2836 from alphagov/delete-unused-functions
Delete unused functions and their tests
This commit is contained in:
@@ -523,20 +523,6 @@ def requested_and_current_financial_year(request):
|
|||||||
abort(404)
|
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(
|
def get_tuples_of_financial_years(
|
||||||
partial_url,
|
partial_url,
|
||||||
start=2015,
|
start=2015,
|
||||||
|
|||||||
@@ -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):
|
def get_example_csv_fields(column_headers, use_example_as_example, submitted_fields):
|
||||||
if use_example_as_example:
|
if use_example_as_example:
|
||||||
return ["example" for header in column_headers]
|
return ["example" for header in column_headers]
|
||||||
@@ -776,25 +768,6 @@ def get_recipient_and_placeholders_from_session(template_type):
|
|||||||
return placeholders
|
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):
|
def all_placeholders_in_session(placeholders):
|
||||||
return all(
|
return all(
|
||||||
get_normalised_placeholders_from_session().get(placeholder, False) not in (False, None)
|
get_normalised_placeholders_from_session().get(placeholder, False) not in (False, None)
|
||||||
|
|||||||
@@ -850,21 +850,6 @@ def get_template_sender_form_dict(service_id, template):
|
|||||||
return context
|
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):
|
def get_human_readable_delta(from_time, until_time):
|
||||||
delta = until_time - from_time
|
delta = until_time - from_time
|
||||||
if delta < timedelta(seconds=60):
|
if delta < timedelta(seconds=60):
|
||||||
@@ -878,10 +863,3 @@ def get_human_readable_delta(from_time, until_time):
|
|||||||
else:
|
else:
|
||||||
days = delta.days
|
days = delta.days
|
||||||
return '{} day{}'.format(days, '' if days == 1 else 's')
|
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')
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ from app.main.views.dashboard import (
|
|||||||
aggregate_status_types,
|
aggregate_status_types,
|
||||||
aggregate_template_usage,
|
aggregate_template_usage,
|
||||||
format_monthly_stats_to_list,
|
format_monthly_stats_to_list,
|
||||||
format_template_stats_to_list,
|
|
||||||
get_dashboard_totals,
|
get_dashboard_totals,
|
||||||
get_free_paid_breakdown_for_billable_units,
|
get_free_paid_breakdown_for_billable_units,
|
||||||
get_tuples_of_financial_years,
|
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]
|
][: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():
|
def test_get_tuples_of_financial_years():
|
||||||
assert list(get_tuples_of_financial_years(
|
assert list(get_tuples_of_financial_years(
|
||||||
lambda year: 'http://example.com?year={}'.format(year),
|
lambda year: 'http://example.com?year={}'.format(year),
|
||||||
|
|||||||
@@ -8,10 +8,7 @@ from flask import url_for
|
|||||||
from freezegun import freeze_time
|
from freezegun import freeze_time
|
||||||
from notifications_python_client.errors import HTTPError
|
from notifications_python_client.errors import HTTPError
|
||||||
|
|
||||||
from app.main.views.templates import (
|
from app.main.views.templates import get_human_readable_delta
|
||||||
get_human_readable_delta,
|
|
||||||
get_last_use_message,
|
|
||||||
)
|
|
||||||
from tests import (
|
from tests import (
|
||||||
single_notification_json,
|
single_notification_json,
|
||||||
template_json,
|
template_json,
|
||||||
@@ -1920,23 +1917,6 @@ def test_route_invalid_permissions(
|
|||||||
service_one)
|
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', [
|
@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, 0, 59), 'under a minute'),
|
||||||
(datetime(2000, 1, 1, 12, 0), datetime(2000, 1, 1, 12, 1), '1 minute'),
|
(datetime(2000, 1, 1, 12, 0), datetime(2000, 1, 1, 12, 1), '1 minute'),
|
||||||
|
|||||||
Reference in New Issue
Block a user