mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-03-02 07:11:14 -05:00
Bug fixed when sending yourself a test the back button links to the correct url.
Remove traceback.
This commit is contained in:
@@ -205,7 +205,6 @@ def send_from_api(service_id, template_id):
|
||||
@login_required
|
||||
@user_has_permissions('send_texts', 'send_emails', 'send_letters')
|
||||
def check_messages(service_id, template_type, upload_id):
|
||||
|
||||
if not session.get('upload_data'):
|
||||
return redirect(url_for('main.choose_template', service_id=service_id, template_type=template_type))
|
||||
|
||||
@@ -239,8 +238,9 @@ def check_messages(service_id, template_type, upload_id):
|
||||
)
|
||||
|
||||
if request.args.get('from_test') and len(template.placeholders):
|
||||
extra_args = {'help': 1} if request.args.get('help') else {}
|
||||
back_link = url_for(
|
||||
'.send_test', service_id=service_id, template_id=template.id, help=1 if request.args.get('help') else 0
|
||||
'.send_test', service_id=service_id, template_id=template.id, **extra_args
|
||||
)
|
||||
else:
|
||||
back_link = url_for('.send_messages', service_id=service_id, template_id=template.id)
|
||||
|
||||
@@ -591,3 +591,66 @@ def test_route_choose_template_manage_api_keys_permissions(mocker,
|
||||
service_id=service_one['id'],
|
||||
template_id=template_id)))
|
||||
assert len(links) == 1
|
||||
|
||||
|
||||
def test_check_messages_back_link_with_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,
|
||||
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,
|
||||
help=2)
|
||||
)
|
||||
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, help=1) in content
|
||||
|
||||
|
||||
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,
|
||||
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
|
||||
|
||||
@@ -891,6 +891,20 @@ def mock_s3_upload(mocker):
|
||||
return mocker.patch('app.main.views.send.s3upload', side_effect=_upload)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_s3_download(mocker, content=None):
|
||||
if not content:
|
||||
content = """
|
||||
phone number,name
|
||||
+447700900986,John
|
||||
+447700900986,Smith
|
||||
"""
|
||||
|
||||
def _download(service_id, upload_id):
|
||||
return content
|
||||
return mocker.patch('app.main.views.send.s3download', side_effect=_download)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def sample_invite(mocker, service_one, status='pending'):
|
||||
id_ = str(generate_uuid())
|
||||
|
||||
Reference in New Issue
Block a user