mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 16:24:08 -04:00
Merge pull request #1439 from alphagov/dvla-endpoint
Add platform–admin-only page to preview DVLA code
This commit is contained in:
@@ -9,12 +9,14 @@ from flask import (
|
|||||||
flash,
|
flash,
|
||||||
abort,
|
abort,
|
||||||
json,
|
json,
|
||||||
|
Response,
|
||||||
)
|
)
|
||||||
from flask_login import login_required, current_user
|
from flask_login import login_required, current_user
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
|
|
||||||
from notifications_utils.formatters import escape_html
|
from notifications_utils.formatters import escape_html
|
||||||
from notifications_utils.recipients import first_column_headings
|
from notifications_utils.recipients import first_column_headings
|
||||||
|
from notifications_utils.template import LetterDVLATemplate
|
||||||
from notifications_python_client.errors import HTTPError
|
from notifications_python_client.errors import HTTPError
|
||||||
|
|
||||||
from app.main import main
|
from app.main import main
|
||||||
@@ -146,6 +148,25 @@ def choose_template(service_id, template_type='all'):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@main.route("/services/<service_id>/templates/<template_id>/as-dvla")
|
||||||
|
@login_required
|
||||||
|
@user_has_permissions(admin_override=True)
|
||||||
|
def view_template_as_dvla_markup(service_id, template_id):
|
||||||
|
|
||||||
|
template = service_api_client.get_service_template(service_id, str(template_id))['data']
|
||||||
|
|
||||||
|
if template['template_type'] != 'letter':
|
||||||
|
abort(404)
|
||||||
|
|
||||||
|
return Response(
|
||||||
|
str(LetterDVLATemplate(
|
||||||
|
template,
|
||||||
|
notification_reference=1,
|
||||||
|
)).replace('<cr>', '<cr>\n'),
|
||||||
|
mimetype='text/plain',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@main.route("/services/<service_id>/templates/<template_id>.<filetype>")
|
@main.route("/services/<service_id>/templates/<template_id>.<filetype>")
|
||||||
@login_required
|
@login_required
|
||||||
@user_has_permissions('view_activity', admin_override=True)
|
@user_has_permissions('view_activity', admin_override=True)
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ from tests.conftest import (
|
|||||||
mock_get_service_template,
|
mock_get_service_template,
|
||||||
normalize_spaces,
|
normalize_spaces,
|
||||||
SERVICE_ONE_ID,
|
SERVICE_ONE_ID,
|
||||||
|
active_user_with_permissions,
|
||||||
|
platform_admin_user,
|
||||||
|
mock_get_user,
|
||||||
)
|
)
|
||||||
from tests import validate_route_permission, template_json, single_notification_json
|
from tests import validate_route_permission, template_json, single_notification_json
|
||||||
|
|
||||||
@@ -1163,3 +1166,48 @@ def test_should_show_hint_once_template_redacted(
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert page.select('.hint')[0].text == 'Personalisation is hidden after sending'
|
assert page.select('.hint')[0].text == 'Personalisation is hidden after sending'
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('test_user, template_mock, expected_response_code', [
|
||||||
|
(
|
||||||
|
active_user_with_permissions,
|
||||||
|
mock_get_service_letter_template,
|
||||||
|
403
|
||||||
|
),
|
||||||
|
(
|
||||||
|
platform_admin_user,
|
||||||
|
mock_get_service_template,
|
||||||
|
404
|
||||||
|
),
|
||||||
|
(
|
||||||
|
platform_admin_user,
|
||||||
|
mock_get_service_email_template,
|
||||||
|
404
|
||||||
|
),
|
||||||
|
(
|
||||||
|
platform_admin_user,
|
||||||
|
mock_get_service_letter_template,
|
||||||
|
200
|
||||||
|
),
|
||||||
|
])
|
||||||
|
def test_should_show_letter_template_as_dvla_markup(
|
||||||
|
client,
|
||||||
|
mocker,
|
||||||
|
service_one,
|
||||||
|
fake_uuid,
|
||||||
|
mock_get_service,
|
||||||
|
test_user,
|
||||||
|
template_mock,
|
||||||
|
expected_response_code,
|
||||||
|
):
|
||||||
|
|
||||||
|
client.login(test_user(fake_uuid), mocker, service_one)
|
||||||
|
template_mock(mocker)
|
||||||
|
|
||||||
|
response = client.get(url_for(
|
||||||
|
'.view_template_as_dvla_markup',
|
||||||
|
service_id=SERVICE_ONE_ID,
|
||||||
|
template_id=fake_uuid,
|
||||||
|
))
|
||||||
|
|
||||||
|
assert response.status_code == expected_response_code
|
||||||
|
|||||||
Reference in New Issue
Block a user