mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-09 10:59:50 -04:00
Add a third route through populating a template
This commit adds a route which is identical to send yourself a test, but with its own endpoint. This will let us add a slightly different ‘send a one-off message’ flow. This commit just adds the route though, and makes sure that the tests pass for both routes.
This commit is contained in:
@@ -157,14 +157,18 @@ def get_example_csv(service_id, template_id):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@main.route("/services/<service_id>/send/<template_id>/test")
|
@main.route("/services/<service_id>/send/<template_id>/test", endpoint='send_test')
|
||||||
|
@main.route("/services/<service_id>/send/<template_id>/one-off", endpoint='send_one_off')
|
||||||
@login_required
|
@login_required
|
||||||
@user_has_permissions('send_texts', 'send_emails', 'send_letters')
|
@user_has_permissions('send_texts', 'send_emails', 'send_letters')
|
||||||
def send_test(service_id, template_id):
|
def send_test(service_id, template_id):
|
||||||
session['send_test_values'] = dict()
|
session['send_test_values'] = dict()
|
||||||
session['send_test_letter_page_count'] = None
|
session['send_test_letter_page_count'] = None
|
||||||
return redirect(url_for(
|
return redirect(url_for(
|
||||||
'.send_test_step',
|
{
|
||||||
|
'main.send_test': '.send_test_step',
|
||||||
|
'main.send_one_off': '.send_one_off_step',
|
||||||
|
}[request.endpoint],
|
||||||
service_id=service_id,
|
service_id=service_id,
|
||||||
template_id=template_id,
|
template_id=template_id,
|
||||||
step_index=0,
|
step_index=0,
|
||||||
@@ -172,14 +176,28 @@ def send_test(service_id, template_id):
|
|||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
@main.route("/services/<service_id>/send/<template_id>/test/step-<int:step_index>", methods=['GET', 'POST'])
|
@main.route(
|
||||||
|
"/services/<service_id>/send/<template_id>/test/step-<int:step_index>",
|
||||||
|
methods=['GET', 'POST'],
|
||||||
|
endpoint='send_test_step',
|
||||||
|
)
|
||||||
|
@main.route(
|
||||||
|
"/services/<service_id>/send/<template_id>/one-off/step-<int:step_index>",
|
||||||
|
methods=['GET', 'POST'],
|
||||||
|
endpoint='send_one_off_step',
|
||||||
|
)
|
||||||
@login_required
|
@login_required
|
||||||
@user_has_permissions('send_texts', 'send_emails', 'send_letters')
|
@user_has_permissions('send_texts', 'send_emails', 'send_letters')
|
||||||
def send_test_step(service_id, template_id, step_index):
|
def send_test_step(service_id, template_id, step_index):
|
||||||
|
|
||||||
if 'send_test_values' not in session:
|
if 'send_test_values' not in session:
|
||||||
return redirect(url_for(
|
return redirect(url_for(
|
||||||
'.send_test', service_id=service_id, template_id=template_id
|
{
|
||||||
|
'main.send_test_step': '.send_test',
|
||||||
|
'main.send_one_off_step': '.send_one_off',
|
||||||
|
}[request.endpoint],
|
||||||
|
service_id=service_id,
|
||||||
|
template_id=template_id,
|
||||||
))
|
))
|
||||||
|
|
||||||
template = service_api_client.get_service_template(service_id, template_id)['data']
|
template = service_api_client.get_service_template(service_id, template_id)['data']
|
||||||
@@ -210,7 +228,12 @@ def send_test_step(service_id, template_id, step_index):
|
|||||||
current_placeholder = placeholders[step_index]
|
current_placeholder = placeholders[step_index]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return redirect(url_for(
|
return redirect(url_for(
|
||||||
'.send_test', service_id=service_id, template_id=template_id
|
{
|
||||||
|
'main.send_test_step': '.send_test',
|
||||||
|
'main.send_one_off_step': '.send_one_off',
|
||||||
|
}[request.endpoint],
|
||||||
|
service_id=service_id,
|
||||||
|
template_id=template_id,
|
||||||
))
|
))
|
||||||
optional_placeholder = (current_placeholder in optional_address_columns)
|
optional_placeholder = (current_placeholder in optional_address_columns)
|
||||||
form = get_placeholder_form_instance(
|
form = get_placeholder_form_instance(
|
||||||
@@ -230,7 +253,7 @@ def send_test_step(service_id, template_id, step_index):
|
|||||||
return make_and_upload_csv_file(service_id, template)
|
return make_and_upload_csv_file(service_id, template)
|
||||||
|
|
||||||
return redirect(url_for(
|
return redirect(url_for(
|
||||||
'.send_test_step',
|
request.endpoint,
|
||||||
service_id=service_id,
|
service_id=service_id,
|
||||||
template_id=template_id,
|
template_id=template_id,
|
||||||
step_index=step_index + 1,
|
step_index=step_index + 1,
|
||||||
@@ -247,7 +270,7 @@ def send_test_step(service_id, template_id, step_index):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
back_link = url_for(
|
back_link = url_for(
|
||||||
'.send_test_step',
|
request.endpoint,
|
||||||
service_id=service_id,
|
service_id=service_id,
|
||||||
template_id=template_id,
|
template_id=template_id,
|
||||||
step_index=step_index - 1,
|
step_index=step_index - 1,
|
||||||
|
|||||||
@@ -297,18 +297,23 @@ def test_send_test_sms_message(
|
|||||||
mock_s3_upload.assert_called_with(service_one['id'], expected_data, 'eu-west-1')
|
mock_s3_upload.assert_called_with(service_one['id'], expected_data, 'eu-west-1')
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('endpoint', [
|
||||||
|
'main.send_test_step',
|
||||||
|
'main.send_one_off_step',
|
||||||
|
])
|
||||||
def test_send_test_step_redirects_if_session_not_setup(
|
def test_send_test_step_redirects_if_session_not_setup(
|
||||||
logged_in_client,
|
logged_in_client,
|
||||||
service_one,
|
service_one,
|
||||||
fake_uuid,
|
fake_uuid,
|
||||||
mock_get_service_email_template,
|
mock_get_service_email_template,
|
||||||
|
endpoint,
|
||||||
):
|
):
|
||||||
|
|
||||||
with logged_in_client.session_transaction() as session:
|
with logged_in_client.session_transaction() as session:
|
||||||
assert 'send_test_values' not in session
|
assert 'send_test_values' not in session
|
||||||
|
|
||||||
response = logged_in_client.get(
|
response = logged_in_client.get(
|
||||||
url_for('main.send_test_step', service_id=service_one['id'], template_id=fake_uuid, step_index=0),
|
url_for(endpoint, service_id=service_one['id'], template_id=fake_uuid, step_index=0),
|
||||||
follow_redirects=True
|
follow_redirects=True
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
@@ -317,6 +322,10 @@ def test_send_test_step_redirects_if_session_not_setup(
|
|||||||
assert session['send_test_values'] == {'email address': 'test@user.gov.uk'}
|
assert session['send_test_values'] == {'email address': 'test@user.gov.uk'}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('endpoint', [
|
||||||
|
'main.send_test_step',
|
||||||
|
'main.send_one_off_step',
|
||||||
|
])
|
||||||
def test_send_test_redirects_to_end_if_step_out_of_bounds(
|
def test_send_test_redirects_to_end_if_step_out_of_bounds(
|
||||||
logged_in_client,
|
logged_in_client,
|
||||||
service_one,
|
service_one,
|
||||||
@@ -325,13 +334,14 @@ def test_send_test_redirects_to_end_if_step_out_of_bounds(
|
|||||||
mock_s3_upload,
|
mock_s3_upload,
|
||||||
mock_get_users_by_service,
|
mock_get_users_by_service,
|
||||||
mock_get_detailed_service_for_today,
|
mock_get_detailed_service_for_today,
|
||||||
|
endpoint,
|
||||||
):
|
):
|
||||||
|
|
||||||
with logged_in_client.session_transaction() as session:
|
with logged_in_client.session_transaction() as session:
|
||||||
session['send_test_values'] = {'name': 'foo'}
|
session['send_test_values'] = {'name': 'foo'}
|
||||||
|
|
||||||
response = logged_in_client.get(url_for(
|
response = logged_in_client.get(url_for(
|
||||||
'main.send_test_step',
|
endpoint,
|
||||||
service_id=service_one['id'],
|
service_id=service_one['id'],
|
||||||
template_id=fake_uuid,
|
template_id=fake_uuid,
|
||||||
step_index=999,
|
step_index=999,
|
||||||
@@ -351,6 +361,10 @@ def test_send_test_redirects_to_end_if_step_out_of_bounds(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('endpoint, expected_redirect', [
|
||||||
|
('main.send_test_step', 'main.send_test'),
|
||||||
|
('main.send_one_off_step', 'main.send_one_off'),
|
||||||
|
])
|
||||||
def test_send_test_redirects_to_start_if_you_skip_steps(
|
def test_send_test_redirects_to_start_if_you_skip_steps(
|
||||||
logged_in_platform_admin_client,
|
logged_in_platform_admin_client,
|
||||||
service_one,
|
service_one,
|
||||||
@@ -360,6 +374,8 @@ def test_send_test_redirects_to_start_if_you_skip_steps(
|
|||||||
mock_get_users_by_service,
|
mock_get_users_by_service,
|
||||||
mock_get_detailed_service_for_today,
|
mock_get_detailed_service_for_today,
|
||||||
mocker,
|
mocker,
|
||||||
|
endpoint,
|
||||||
|
expected_redirect,
|
||||||
):
|
):
|
||||||
|
|
||||||
with logged_in_platform_admin_client.session_transaction() as session:
|
with logged_in_platform_admin_client.session_transaction() as session:
|
||||||
@@ -367,20 +383,24 @@ def test_send_test_redirects_to_start_if_you_skip_steps(
|
|||||||
session['send_test_values'] = {'address_line_1': 'foo'}
|
session['send_test_values'] = {'address_line_1': 'foo'}
|
||||||
|
|
||||||
response = logged_in_platform_admin_client.get(url_for(
|
response = logged_in_platform_admin_client.get(url_for(
|
||||||
'main.send_test_step',
|
endpoint,
|
||||||
service_id=service_one['id'],
|
service_id=service_one['id'],
|
||||||
template_id=fake_uuid,
|
template_id=fake_uuid,
|
||||||
step_index=7, # letter template has 7 placeholders – we’re at the end
|
step_index=7, # letter template has 7 placeholders – we’re at the end
|
||||||
))
|
))
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
assert response.location == url_for(
|
assert response.location == url_for(
|
||||||
'main.send_test',
|
expected_redirect,
|
||||||
service_id=service_one['id'],
|
service_id=service_one['id'],
|
||||||
template_id=fake_uuid,
|
template_id=fake_uuid,
|
||||||
_external=True,
|
_external=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('endpoint, expected_redirect', [
|
||||||
|
('main.send_test_step', 'main.send_test'),
|
||||||
|
('main.send_one_off_step', 'main.send_one_off'),
|
||||||
|
])
|
||||||
def test_send_test_redirects_to_start_if_index_out_of_bounds_and_some_placeholders_empty(
|
def test_send_test_redirects_to_start_if_index_out_of_bounds_and_some_placeholders_empty(
|
||||||
logged_in_client,
|
logged_in_client,
|
||||||
service_one,
|
service_one,
|
||||||
@@ -389,13 +409,15 @@ def test_send_test_redirects_to_start_if_index_out_of_bounds_and_some_placeholde
|
|||||||
mock_s3_download,
|
mock_s3_download,
|
||||||
mock_get_users_by_service,
|
mock_get_users_by_service,
|
||||||
mock_get_detailed_service_for_today,
|
mock_get_detailed_service_for_today,
|
||||||
|
endpoint,
|
||||||
|
expected_redirect,
|
||||||
):
|
):
|
||||||
|
|
||||||
with logged_in_client.session_transaction() as session:
|
with logged_in_client.session_transaction() as session:
|
||||||
session['send_test_values'] = {'name': 'foo'}
|
session['send_test_values'] = {'name': 'foo'}
|
||||||
|
|
||||||
response = logged_in_client.get(url_for(
|
response = logged_in_client.get(url_for(
|
||||||
'main.send_test_step',
|
endpoint,
|
||||||
service_id=service_one['id'],
|
service_id=service_one['id'],
|
||||||
template_id=fake_uuid,
|
template_id=fake_uuid,
|
||||||
step_index=999,
|
step_index=999,
|
||||||
@@ -403,24 +425,30 @@ def test_send_test_redirects_to_start_if_index_out_of_bounds_and_some_placeholde
|
|||||||
|
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
assert response.location == url_for(
|
assert response.location == url_for(
|
||||||
'main.send_test',
|
expected_redirect,
|
||||||
service_id=service_one['id'],
|
service_id=service_one['id'],
|
||||||
template_id=fake_uuid,
|
template_id=fake_uuid,
|
||||||
_external=True,
|
_external=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('endpoint, expected_redirect', [
|
||||||
|
('main.send_test', 'main.send_test_step'),
|
||||||
|
('main.send_one_off', 'main.send_one_off_step'),
|
||||||
|
])
|
||||||
def test_send_test_sms_message_redirects_with_help_argument(
|
def test_send_test_sms_message_redirects_with_help_argument(
|
||||||
logged_in_client,
|
logged_in_client,
|
||||||
service_one,
|
service_one,
|
||||||
fake_uuid,
|
fake_uuid,
|
||||||
|
endpoint,
|
||||||
|
expected_redirect,
|
||||||
):
|
):
|
||||||
response = logged_in_client.get(
|
response = logged_in_client.get(
|
||||||
url_for('main.send_test', service_id=service_one['id'], template_id=fake_uuid, help=1)
|
url_for(endpoint, service_id=service_one['id'], template_id=fake_uuid, help=1)
|
||||||
)
|
)
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
assert response.location == url_for(
|
assert response.location == url_for(
|
||||||
'main.send_test_step',
|
expected_redirect,
|
||||||
service_id=service_one['id'],
|
service_id=service_one['id'],
|
||||||
template_id=fake_uuid,
|
template_id=fake_uuid,
|
||||||
step_index=0,
|
step_index=0,
|
||||||
|
|||||||
Reference in New Issue
Block a user