mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-06 00:28:25 -04:00
Update message seen when deleting a template.
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
from datetime import datetime, timedelta
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from dateutil.parser import parse
|
|
||||||
from flask import abort, flash, redirect, render_template, request, url_for
|
from flask import abort, flash, redirect, render_template, request, url_for
|
||||||
from flask_login import current_user
|
from flask_login import current_user
|
||||||
from notifications_python_client.errors import HTTPError
|
from notifications_python_client.errors import HTTPError
|
||||||
@@ -10,6 +8,7 @@ from notifications_utils.pdf import is_letter_too_long
|
|||||||
|
|
||||||
from app import (
|
from app import (
|
||||||
current_service,
|
current_service,
|
||||||
|
format_delta,
|
||||||
nl2br,
|
nl2br,
|
||||||
service_api_client,
|
service_api_client,
|
||||||
template_folder_api_client,
|
template_folder_api_client,
|
||||||
@@ -676,12 +675,8 @@ def delete_service_template(service_id, template_id):
|
|||||||
last_used_notification = template_statistics_client.get_template_statistics_for_template(
|
last_used_notification = template_statistics_client.get_template_statistics_for_template(
|
||||||
service_id, template['id']
|
service_id, template['id']
|
||||||
)
|
)
|
||||||
message = 'This template was last used {} ago.'.format(
|
message = 'This template has never been used.' if not last_used_notification else \
|
||||||
'more than seven days' if not last_used_notification else get_human_readable_delta(
|
'This template was last used {}.'.format(format_delta(last_used_notification['created_at']))
|
||||||
parse(last_used_notification['created_at']).replace(tzinfo=None),
|
|
||||||
datetime.utcnow()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
if e.status_code == 404:
|
if e.status_code == 404:
|
||||||
@@ -848,18 +843,3 @@ def get_template_sender_form_dict(service_id, template):
|
|||||||
|
|
||||||
context['current_choice'] = template['service_letter_contact'] if template['service_letter_contact'] else ''
|
context['current_choice'] = template['service_letter_contact'] if template['service_letter_contact'] else ''
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
def get_human_readable_delta(from_time, until_time):
|
|
||||||
delta = until_time - from_time
|
|
||||||
if delta < timedelta(seconds=60):
|
|
||||||
return 'under a minute'
|
|
||||||
elif delta < timedelta(hours=1):
|
|
||||||
minutes = int(delta.seconds / 60)
|
|
||||||
return '{} minute{}'.format(minutes, '' if minutes == 1 else 's')
|
|
||||||
elif delta < timedelta(days=1):
|
|
||||||
hours = int(delta.seconds / 3600)
|
|
||||||
return '{} hour{}'.format(hours, '' if hours == 1 else 's')
|
|
||||||
else:
|
|
||||||
days = delta.days
|
|
||||||
return '{} day{}'.format(days, '' if days == 1 else 's')
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
from datetime import datetime
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from unittest.mock import ANY, Mock
|
from unittest.mock import ANY, Mock
|
||||||
|
|
||||||
@@ -7,7 +6,6 @@ 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 get_human_readable_delta
|
|
||||||
from tests import (
|
from tests import (
|
||||||
sample_uuid,
|
sample_uuid,
|
||||||
single_notification_json,
|
single_notification_json,
|
||||||
@@ -1730,7 +1728,7 @@ def test_should_show_delete_template_page_with_time_block_for_empty_notification
|
|||||||
)
|
)
|
||||||
assert "Are you sure you want to delete ‘Two week reminder’?" in page.select('.banner-dangerous')[0].text
|
assert "Are you sure you want to delete ‘Two week reminder’?" in page.select('.banner-dangerous')[0].text
|
||||||
assert normalize_spaces(page.select('.banner-dangerous p')[0].text) == (
|
assert normalize_spaces(page.select('.banner-dangerous p')[0].text) == (
|
||||||
'This template was last used more than seven days ago.'
|
'This template has never been used.'
|
||||||
)
|
)
|
||||||
assert normalize_spaces(page.select('.sms-message-wrapper')[0].text) == (
|
assert normalize_spaces(page.select('.sms-message-wrapper')[0].text) == (
|
||||||
'service one: Template <em>content</em> with & entity'
|
'service one: Template <em>content</em> with & entity'
|
||||||
@@ -1920,21 +1918,6 @@ def test_route_invalid_permissions(
|
|||||||
service_one)
|
service_one)
|
||||||
|
|
||||||
|
|
||||||
@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'),
|
|
||||||
(datetime(2000, 1, 1, 12, 0), datetime(2000, 1, 1, 12, 2, 35), '2 minutes'),
|
|
||||||
(datetime(2000, 1, 1, 12, 0), datetime(2000, 1, 1, 12, 59), '59 minutes'),
|
|
||||||
(datetime(2000, 1, 1, 12, 0), datetime(2000, 1, 1, 13, 0), '1 hour'),
|
|
||||||
(datetime(2000, 1, 1, 12, 0), datetime(2000, 1, 1, 14, 0), '2 hours'),
|
|
||||||
(datetime(2000, 1, 1, 12, 0), datetime(2000, 1, 2, 11, 59), '23 hours'),
|
|
||||||
(datetime(2000, 1, 1, 12, 0), datetime(2000, 1, 2, 12, 0), '1 day'),
|
|
||||||
(datetime(2000, 1, 1, 12, 0), datetime(2000, 1, 3, 14, 0), '2 days'),
|
|
||||||
])
|
|
||||||
def test_get_human_readable_delta(from_time, until_time, message):
|
|
||||||
assert get_human_readable_delta(from_time, until_time) == message
|
|
||||||
|
|
||||||
|
|
||||||
def test_can_create_email_template_with_emoji(
|
def test_can_create_email_template_with_emoji(
|
||||||
client_request,
|
client_request,
|
||||||
mock_create_service_template
|
mock_create_service_template
|
||||||
|
|||||||
Reference in New Issue
Block a user