Make send one-off route ask for phone number/email

This commit adds an extra, initial, step to the ‘send one-off message’
flow to ask for a phone number or email address. This is the first pass
at making a feature which caseworkers or similar could use Notify to
send individual messages while they’re working a case.
This commit is contained in:
Chris Hill-Scott
2017-05-25 09:18:26 +01:00
parent eabd9fcbf1
commit 7310e8b435
2 changed files with 47 additions and 18 deletions

View File

@@ -219,7 +219,10 @@ def send_test_step(service_id, template_id, step_index):
page_count=session['send_test_letter_page_count']
)
placeholders = fields_to_fill_in(template)
placeholders = fields_to_fill_in(
template,
prefill_current_user=(request.endpoint == 'main.send_test_step'),
)
if len(placeholders) == 0:
return make_and_upload_csv_file(service_id, template)
@@ -227,6 +230,8 @@ def send_test_step(service_id, template_id, step_index):
try:
current_placeholder = placeholders[step_index]
except IndexError:
if all_placeholders_in_session(placeholders):
return make_and_upload_csv_file(service_id, template)
return redirect(url_for(
{
'main.send_test_step': '.send_test',
@@ -246,10 +251,7 @@ def send_test_step(service_id, template_id, step_index):
session['send_test_values'][current_placeholder] = form.placeholder_value.data
if all(
get_normalised_send_test_values_from_session().get(placeholder, False) not in (False, None)
for placeholder in placeholders
):
if all_placeholders_in_session(placeholders):
return make_and_upload_csv_file(service_id, template)
return redirect(url_for(
@@ -493,11 +495,11 @@ def get_check_messages_back_url(service_id, template_type):
return url_for('main.choose_template', service_id=service_id)
def fields_to_fill_in(template):
def fields_to_fill_in(template, prefill_current_user=False):
recipient_columns = first_column_headings[template.template_type]
if 'letter' == template.template_type:
if 'letter' == template.template_type or not prefill_current_user:
return recipient_columns + list(template.placeholders)
session['send_test_values'][recipient_columns[0]] = {
@@ -536,3 +538,10 @@ def make_and_upload_csv_file(service_id, template):
from_test=True,
help=2 if get_help_argument() else 0
))
def all_placeholders_in_session(placeholders):
return all(
get_normalised_send_test_values_from_session().get(placeholder, False) not in (False, None)
for placeholder in placeholders
)

View File

@@ -297,34 +297,52 @@ def test_send_test_sms_message(
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',
@pytest.mark.parametrize('endpoint, template_mock, expected_session_contents', [
('main.send_test_step', mock_get_service_template_with_placeholders, {'phone number': '07700 900762'}),
('main.send_test_step', mock_get_service_email_template, {'email address': 'test@user.gov.uk'}),
('main.send_test_step', mock_get_service_letter_template, {}),
('main.send_one_off_step', mock_get_service_template, {}),
('main.send_one_off_step', mock_get_service_email_template, {}),
('main.send_one_off_step', mock_get_service_letter_template, {}),
])
def test_send_test_step_redirects_if_session_not_setup(
mocker,
logged_in_client,
service_one,
mock_get_detailed_service_for_today,
mock_get_users_by_service,
fake_uuid,
mock_get_service_email_template,
endpoint,
template_mock,
expected_session_contents,
):
template_mock(mocker)
mocker.patch('app.main.views.send.get_page_count_for_letter', return_value=99)
with logged_in_client.session_transaction() as session:
assert 'send_test_values' not in session
response = logged_in_client.get(
url_for(endpoint, 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
)
assert response.status_code == 200
with logged_in_client.session_transaction() as session:
assert session['send_test_values'] == {'email address': 'test@user.gov.uk'}
assert session['send_test_values'] == expected_session_contents
@pytest.mark.parametrize('endpoint', [
'main.send_test_step',
'main.send_one_off_step',
@pytest.mark.parametrize('endpoint, expected_redirect, send_test_values', [
(
'main.send_test_step',
'main.send_test',
{'name': 'foo'},
),
(
'main.send_one_off_step',
'main.send_one_off',
{'name': 'foo', 'phone number': '07900900123'},
),
])
def test_send_test_redirects_to_end_if_step_out_of_bounds(
logged_in_client,
@@ -335,10 +353,12 @@ def test_send_test_redirects_to_end_if_step_out_of_bounds(
mock_get_users_by_service,
mock_get_detailed_service_for_today,
endpoint,
send_test_values,
expected_redirect,
):
with logged_in_client.session_transaction() as session:
session['send_test_values'] = {'name': 'foo'}
session['send_test_values'] = send_test_values
response = logged_in_client.get(url_for(
endpoint,