mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 05:29:38 -04:00
Don’t show send/edit links for deleted template
Since you can’t really send or edit a deleted template we should show a message telling you that the template has been deleted. This is important because deleted templates still show up in the template statistics.
This commit is contained in:
@@ -68,14 +68,17 @@ def template_json(service_id,
|
||||
type_="sms",
|
||||
content="template content",
|
||||
subject=None,
|
||||
version=1):
|
||||
version=1,
|
||||
archived=False):
|
||||
template = {
|
||||
'id': id_,
|
||||
'name': name,
|
||||
'template_type': type_,
|
||||
'content': content,
|
||||
'service': service_id,
|
||||
'version': version
|
||||
'version': version,
|
||||
'updated_at': datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f'),
|
||||
'archived': archived
|
||||
}
|
||||
if subject is not None:
|
||||
template['subject'] = subject
|
||||
|
||||
@@ -9,15 +9,17 @@ from tests import validate_route_permission
|
||||
from app.main.views.templates import get_last_use_message, get_human_readable_delta
|
||||
|
||||
|
||||
def test_should_show_page_for_one_templates(app_,
|
||||
api_user_active,
|
||||
mock_login,
|
||||
mock_get_service,
|
||||
mock_get_service_template,
|
||||
mock_get_user,
|
||||
mock_get_user_by_email,
|
||||
mock_has_permissions,
|
||||
fake_uuid):
|
||||
def test_should_show_page_for_one_template(
|
||||
app_,
|
||||
api_user_active,
|
||||
mock_login,
|
||||
mock_get_service,
|
||||
mock_get_service_template,
|
||||
mock_get_user,
|
||||
mock_get_user_by_email,
|
||||
mock_has_permissions,
|
||||
fake_uuid
|
||||
):
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
client.login(api_user_active)
|
||||
@@ -291,6 +293,39 @@ def test_should_redirect_when_deleting_a_template(app_,
|
||||
service_id, template_id)
|
||||
|
||||
|
||||
@freeze_time('2016-01-01T15:00')
|
||||
def test_should_show_page_for_a_deleted_template(
|
||||
app_,
|
||||
api_user_active,
|
||||
mock_login,
|
||||
mock_get_service,
|
||||
mock_get_deleted_template,
|
||||
mock_get_user,
|
||||
mock_get_user_by_email,
|
||||
mock_has_permissions,
|
||||
fake_uuid
|
||||
):
|
||||
with app_.test_request_context(), app_.test_client() as client:
|
||||
client.login(api_user_active)
|
||||
service_id = fake_uuid
|
||||
template_id = fake_uuid
|
||||
response = client.get(url_for(
|
||||
'.view_template',
|
||||
service_id=service_id,
|
||||
template_id=template_id
|
||||
))
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
content = response.get_data(as_text=True)
|
||||
assert url_for("main.edit_service_template", service_id=fake_uuid, template_id=fake_uuid) not in content
|
||||
assert url_for("main.send_from_api", service_id=fake_uuid, template_id=fake_uuid) not in content
|
||||
assert url_for("main.send_test", service_id=fake_uuid, template_id=fake_uuid) not in content
|
||||
assert "This template was deleted<br/>1 January 2016" in content
|
||||
|
||||
mock_get_deleted_template.assert_called_with(service_id, template_id)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('route', [
|
||||
'main.add_service_template',
|
||||
'main.edit_service_template',
|
||||
|
||||
@@ -245,6 +245,27 @@ def mock_get_service_template(mocker):
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_get_deleted_template(mocker):
|
||||
def _get(service_id, template_id, version=None):
|
||||
template = template_json(
|
||||
service_id,
|
||||
template_id,
|
||||
"Two week reminder",
|
||||
"sms",
|
||||
"Your vehicle tax is about to expire",
|
||||
archived=True
|
||||
)
|
||||
if version:
|
||||
template.update({'version': version})
|
||||
return {'data': template}
|
||||
|
||||
return mocker.patch(
|
||||
'app.service_api_client.get_service_template',
|
||||
side_effect=_get
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_get_template_version(mocker, fake_uuid, user=None):
|
||||
if user is None:
|
||||
|
||||
Reference in New Issue
Block a user