mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-25 08:44:23 -04:00
Merge pull request #727 from alphagov/fix-back-link-bug
Fix ‘help’ appearing when it shouldn’t
This commit is contained in:
@@ -243,7 +243,7 @@ def check_messages(service_id, template_type, upload_id):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if request.args.get('from_test') and len(template.placeholders):
|
if request.args.get('from_test') and len(template.placeholders):
|
||||||
extra_args = {'help': 1} if request.args.get('help') else {}
|
extra_args = {'help': 1} if request.args.get('help', '0') != '0' else {}
|
||||||
back_link = url_for(
|
back_link = url_for(
|
||||||
'.send_test', service_id=service_id, template_id=template.id, **extra_args
|
'.send_test', service_id=service_id, template_id=template.id, **extra_args
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ from io import BytesIO
|
|||||||
from os import path
|
from os import path
|
||||||
from glob import glob
|
from glob import glob
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
from functools import partial
|
||||||
from flask import url_for
|
from flask import url_for
|
||||||
from tests import validate_route_permission
|
from tests import validate_route_permission
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@@ -598,67 +599,58 @@ def test_route_choose_template_manage_api_keys_permissions(mocker,
|
|||||||
assert len(links) == 1
|
assert len(links) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_check_messages_back_link_with_help(app_,
|
@pytest.mark.parametrize(
|
||||||
api_user_active,
|
'extra_args,expected_url',
|
||||||
mock_login,
|
[
|
||||||
mock_get_user_by_email,
|
(
|
||||||
mock_get_users_by_service,
|
dict(),
|
||||||
mock_get_service,
|
partial(url_for, '.send_test')
|
||||||
mock_get_service_template_with_placeholders,
|
),
|
||||||
mock_has_permissions,
|
(
|
||||||
mock_get_service_statistics_for_day,
|
dict(help='0'),
|
||||||
mock_s3_download,
|
partial(url_for, '.send_test')
|
||||||
fake_uuid):
|
),
|
||||||
with app_.test_request_context():
|
(
|
||||||
with app_.test_client() as client:
|
dict(help='2'),
|
||||||
client.login(api_user_active)
|
partial(url_for, '.send_test', help='1')
|
||||||
with client.session_transaction() as session:
|
)
|
||||||
session['upload_data'] = {'original_file_name': 'valid.csv',
|
]
|
||||||
'template_id': fake_uuid,
|
)
|
||||||
'notification_count': 1,
|
def test_check_messages_back_link(
|
||||||
'valid': True}
|
app_,
|
||||||
response = client.get(url_for(
|
api_user_active,
|
||||||
'main.check_messages',
|
mock_login,
|
||||||
service_id=fake_uuid,
|
mock_get_user_by_email,
|
||||||
upload_id=fake_uuid,
|
mock_get_users_by_service,
|
||||||
template_type='sms',
|
mock_get_service,
|
||||||
from_test=True,
|
mock_get_service_template_with_placeholders,
|
||||||
help=2)
|
mock_has_permissions,
|
||||||
)
|
mock_get_service_statistics_for_day,
|
||||||
|
mock_s3_download,
|
||||||
|
fake_uuid,
|
||||||
|
extra_args,
|
||||||
|
expected_url
|
||||||
|
):
|
||||||
|
with app_.test_request_context(), app_.test_client() as client:
|
||||||
|
client.login(api_user_active)
|
||||||
|
with client.session_transaction() as session:
|
||||||
|
session['upload_data'] = {'original_file_name': 'valid.csv',
|
||||||
|
'template_id': fake_uuid,
|
||||||
|
'notification_count': 1,
|
||||||
|
'valid': True}
|
||||||
|
response = client.get(url_for(
|
||||||
|
'main.check_messages',
|
||||||
|
service_id=fake_uuid,
|
||||||
|
upload_id=fake_uuid,
|
||||||
|
template_type='sms',
|
||||||
|
from_test=True,
|
||||||
|
**extra_args
|
||||||
|
))
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
content = response.get_data(as_text=True)
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||||
assert url_for('.send_test', service_id=fake_uuid, template_id=fake_uuid, help=1) in content
|
assert (
|
||||||
|
page.findAll('a', {'class': 'page-footer-back-link'})[0]['href']
|
||||||
|
) == expected_url(service_id=fake_uuid, template_id=fake_uuid)
|
||||||
def test_check_messages_back_link_without_help(app_,
|
|
||||||
api_user_active,
|
|
||||||
mock_login,
|
|
||||||
mock_get_user_by_email,
|
|
||||||
mock_get_users_by_service,
|
|
||||||
mock_get_service,
|
|
||||||
mock_get_service_template_with_placeholders,
|
|
||||||
mock_has_permissions,
|
|
||||||
mock_get_service_statistics_for_day,
|
|
||||||
mock_s3_download,
|
|
||||||
fake_uuid):
|
|
||||||
with app_.test_request_context():
|
|
||||||
with app_.test_client() as client:
|
|
||||||
client.login(api_user_active)
|
|
||||||
with client.session_transaction() as session:
|
|
||||||
session['upload_data'] = {'original_file_name': 'valid.csv',
|
|
||||||
'template_id': fake_uuid,
|
|
||||||
'notification_count': 1,
|
|
||||||
'valid': True}
|
|
||||||
response = client.get(url_for(
|
|
||||||
'main.check_messages',
|
|
||||||
service_id=fake_uuid,
|
|
||||||
upload_id=fake_uuid,
|
|
||||||
template_type='sms',
|
|
||||||
from_test=True)
|
|
||||||
)
|
|
||||||
assert response.status_code == 200
|
|
||||||
content = response.get_data(as_text=True)
|
|
||||||
assert url_for('.send_test', service_id=fake_uuid, template_id=fake_uuid) in content
|
|
||||||
|
|
||||||
|
|
||||||
def test_send_and_check_page_renders_if_no_statistics(
|
def test_send_and_check_page_renders_if_no_statistics(
|
||||||
|
|||||||
Reference in New Issue
Block a user