Fix the logic about showing extra task list items

It should be:
- if they have said they are going to send by a certain channel, show
  the extra required task(s) for that channel
- if they haven’t said, infer from which templates they have
This commit is contained in:
Chris Hill-Scott
2019-03-08 14:26:39 +00:00
parent d1844aac33
commit 1af844c95f
3 changed files with 94 additions and 49 deletions

View File

@@ -200,6 +200,18 @@ class Service():
def has_sms_templates(self): def has_sms_templates(self):
return len(self.get_templates('sms')) > 0 return len(self.get_templates('sms')) > 0
@property
def intending_to_send_email(self):
if self.volume_email is None:
return self.has_email_templates
return self.volume_email > 0
@property
def intending_to_send_sms(self):
if self.volume_sms is None:
return self.has_sms_templates
return self.volume_sms > 0
@cached_property @cached_property
def email_reply_to_addresses(self): def email_reply_to_addresses(self):
return service_api_client.get_reply_to_email_addresses(self.id) return service_api_client.get_reply_to_email_addresses(self.id)
@@ -226,7 +238,7 @@ class Service():
@property @property
def needs_to_add_email_reply_to_address(self): def needs_to_add_email_reply_to_address(self):
return self.volume_email and not self.has_email_reply_to_address return self.intending_to_send_email and not self.has_email_reply_to_address
@property @property
def shouldnt_use_govuk_as_sms_sender(self): def shouldnt_use_govuk_as_sms_sender(self):
@@ -269,7 +281,7 @@ class Service():
@property @property
def needs_to_change_sms_sender(self): def needs_to_change_sms_sender(self):
return all(( return all((
self.volume_sms, self.intending_to_send_sms,
self.shouldnt_use_govuk_as_sms_sender, self.shouldnt_use_govuk_as_sms_sender,
self.sms_sender_is_govuk, self.sms_sender_is_govuk,
)) ))

View File

@@ -27,10 +27,7 @@
'Add templates with examples of the content you plan to send', 'Add templates with examples of the content you plan to send',
url_for('main.choose_template', service_id=current_service.id), url_for('main.choose_template', service_id=current_service.id),
) }} ) }}
{% if ( {% if current_service.intending_to_send_email %}
current_service.has_email_templates
and (current_service.volume_email != 0)
) %}
{{ task_list_item( {{ task_list_item(
current_service.has_email_reply_to_address, current_service.has_email_reply_to_address,
'Add an email reply-to address', 'Add an email reply-to address',
@@ -38,9 +35,8 @@
) }} ) }}
{% endif %} {% endif %}
{% if ( {% if (
current_service.has_sms_templates current_service.intending_to_send_sms
and current_service.shouldnt_use_govuk_as_sms_sender and current_service.shouldnt_use_govuk_as_sms_sender
and (current_service.volume_sms != 0)
) %} ) %}
{{ task_list_item( {{ task_list_item(
not current_service.sms_sender_is_govuk, not current_service.sms_sender_is_govuk,

View File

@@ -570,11 +570,20 @@ def test_should_check_if_estimated_volumes_provided(
(1, 'Add templates with examples of the content you plan to send Completed'), (1, 'Add templates with examples of the content you plan to send Completed'),
(2, 'Add templates with examples of the content you plan to send Completed'), (2, 'Add templates with examples of the content you plan to send Completed'),
]) ])
@pytest.mark.parametrize('count_of_email_templates, reply_to_email_addresses, expected_reply_to_checklist_item', [ @pytest.mark.parametrize((
pytest.param(0, [], '', marks=pytest.mark.xfail(raises=IndexError)), 'volume_email,'
pytest.param(0, [{}], '', marks=pytest.mark.xfail(raises=IndexError)), 'count_of_email_templates,'
(1, [], 'Add an email reply-to address Not completed'), 'reply_to_email_addresses,'
(1, [{}], 'Add an email reply-to address Completed'), 'expected_reply_to_checklist_item'
), [
pytest.param(None, 0, [], '', marks=pytest.mark.xfail(raises=IndexError)),
pytest.param(0, 0, [], '', marks=pytest.mark.xfail(raises=IndexError)),
(None, 1, [], 'Add an email reply-to address Not completed'),
(None, 1, [{}], 'Add an email reply-to address Completed'),
(1, 1, [], 'Add an email reply-to address Not completed'),
(1, 1, [{}], 'Add an email reply-to address Completed'),
(1, 0, [], 'Add an email reply-to address Not completed'),
(1, 0, [{}], 'Add an email reply-to address Completed'),
]) ])
def test_should_check_for_sending_things_right( def test_should_check_for_sending_things_right(
client_request, client_request,
@@ -584,6 +593,7 @@ def test_should_check_for_sending_things_right(
expected_user_checklist_item, expected_user_checklist_item,
count_of_templates, count_of_templates,
expected_templates_checklist_item, expected_templates_checklist_item,
volume_email,
count_of_email_templates, count_of_email_templates,
reply_to_email_addresses, reply_to_email_addresses,
expected_reply_to_checklist_item, expected_reply_to_checklist_item,
@@ -606,7 +616,7 @@ def test_should_check_for_sending_things_right(
return_value=list(range(0, count_of_templates)), return_value=list(range(0, count_of_templates)),
) )
mock_get_templates = mocker.patch( mocker.patch(
'app.models.service.Service.get_templates', 'app.models.service.Service.get_templates',
side_effect=_templates_by_type, side_effect=_templates_by_type,
) )
@@ -616,12 +626,12 @@ def test_should_check_for_sending_things_right(
return_value=reply_to_email_addresses return_value=reply_to_email_addresses
) )
for channel, volume in (('email', 1), ('sms', 0), ('letter', 1)): for channel, volume in (('email', volume_email), ('sms', 0), ('letter', 1)):
mocker.patch( mocker.patch(
'app.models.service.Service.volume_{}'.format(channel), 'app.models.service.Service.volume_{}'.format(channel),
create=True, create=True,
new_callable=PropertyMock, new_callable=PropertyMock,
return_value=1, return_value=volume,
) )
page = client_request.get( page = client_request.get(
@@ -642,22 +652,20 @@ def test_should_check_for_sending_things_right(
assert mock_templates.call_args_list == [ assert mock_templates.call_args_list == [
call(), call(),
] ]
assert mock_get_templates.call_args_list == [
call('email'),
call('sms'),
]
if count_of_email_templates: if count_of_email_templates:
mock_get_reply_to_email_addresses.assert_called_once_with(SERVICE_ONE_ID) mock_get_reply_to_email_addresses.assert_called_once_with(SERVICE_ONE_ID)
@pytest.mark.parametrize('estimated_sms_volume', ( @pytest.mark.parametrize((
pytest.param(None), 'estimated_sms_volume,'
pytest.param(1), 'organisation_type,'
pytest.param(0, marks=pytest.mark.xfail(raises=IndexError)), 'count_of_sms_templates,'
)) 'sms_senders,'
@pytest.mark.parametrize('organisation_type,count_of_sms_templates, sms_senders, expected_sms_sender_checklist_item', [ 'expected_sms_sender_checklist_item'
), [
pytest.param( pytest.param(
0,
'local', 'local',
0, 0,
[], [],
@@ -665,6 +673,7 @@ def test_should_check_for_sending_things_right(
marks=pytest.mark.xfail(raises=IndexError) marks=pytest.mark.xfail(raises=IndexError)
), ),
pytest.param( pytest.param(
None,
'local', 'local',
0, 0,
[{'is_default': True, 'sms_sender': 'GOVUK'}], [{'is_default': True, 'sms_sender': 'GOVUK'}],
@@ -672,6 +681,7 @@ def test_should_check_for_sending_things_right(
marks=pytest.mark.xfail(raises=IndexError) marks=pytest.mark.xfail(raises=IndexError)
), ),
pytest.param( pytest.param(
1,
None, None,
99, 99,
[{'is_default': True, 'sms_sender': 'GOVUK'}], [{'is_default': True, 'sms_sender': 'GOVUK'}],
@@ -679,6 +689,15 @@ def test_should_check_for_sending_things_right(
marks=pytest.mark.xfail(raises=IndexError) marks=pytest.mark.xfail(raises=IndexError)
), ),
pytest.param( pytest.param(
None,
'central',
99,
[{'is_default': True, 'sms_sender': 'GOVUK'}],
'',
marks=pytest.mark.xfail(raises=IndexError)
),
pytest.param(
1,
'central', 'central',
99, 99,
[{'is_default': True, 'sms_sender': 'GOVUK'}], [{'is_default': True, 'sms_sender': 'GOVUK'}],
@@ -686,18 +705,28 @@ def test_should_check_for_sending_things_right(
marks=pytest.mark.xfail(raises=IndexError) marks=pytest.mark.xfail(raises=IndexError)
), ),
( (
None,
'local', 'local',
1, 1,
[], [],
'Change your text message sender name Not completed', 'Change your text message sender name Not completed',
), ),
( (
1,
'local',
0,
[],
'Change your text message sender name Not completed',
),
(
None,
'local', 'local',
1, 1,
[{'is_default': True, 'sms_sender': 'GOVUK'}], [{'is_default': True, 'sms_sender': 'GOVUK'}],
'Change your text message sender name Not completed', 'Change your text message sender name Not completed',
), ),
( (
None,
'local', 'local',
1, 1,
[ [
@@ -707,6 +736,7 @@ def test_should_check_for_sending_things_right(
'Change your text message sender name Completed', 'Change your text message sender name Completed',
), ),
( (
None,
'nhs', 'nhs',
1, 1,
[{'is_default': True, 'sms_sender': 'KUVOG'}], [{'is_default': True, 'sms_sender': 'KUVOG'}],
@@ -741,7 +771,7 @@ def test_should_check_for_sms_sender_on_go_live(
new_callable=PropertyMock, new_callable=PropertyMock,
side_effect=partial(_templates_by_type, 'all'), side_effect=partial(_templates_by_type, 'all'),
) )
mock_get_templates = mocker.patch( mocker.patch(
'app.models.service.Service.get_templates', 'app.models.service.Service.get_templates',
side_effect=_templates_by_type, side_effect=_templates_by_type,
) )
@@ -755,12 +785,13 @@ def test_should_check_for_sms_sender_on_go_live(
return_value=[], return_value=[],
) )
mocker.patch( for channel, volume in (('email', 0), ('sms', estimated_sms_volume)):
'app.models.service.Service.volume_sms', mocker.patch(
create=True, 'app.models.service.Service.volume_{}'.format(channel),
new_callable=PropertyMock, create=True,
return_value=estimated_sms_volume, new_callable=PropertyMock,
) return_value=volume,
)
page = client_request.get( page = client_request.get(
'main.request_to_go_live', service_id=SERVICE_ONE_ID 'main.request_to_go_live', service_id=SERVICE_ONE_ID
@@ -773,10 +804,6 @@ def test_should_check_for_sms_sender_on_go_live(
assert mock_templates.call_args_list == [ assert mock_templates.call_args_list == [
call(), call(),
] ]
assert mock_get_templates.call_args_list == [
call('email'),
call('sms'),
]
mock_get_sms_senders.assert_called_once_with(SERVICE_ONE_ID) mock_get_sms_senders.assert_called_once_with(SERVICE_ONE_ID)
@@ -820,6 +847,13 @@ def test_should_check_for_mou_on_request_to_go_live(
'app.main.views.service_settings.service_api_client.get_reply_to_email_addresses', 'app.main.views.service_settings.service_api_client.get_reply_to_email_addresses',
return_value=[], return_value=[],
) )
for channel in {'email', 'sms', 'letter'}:
mocker.patch(
'app.models.service.Service.volume_{}'.format(channel),
create=True,
new_callable=PropertyMock,
return_value=None,
)
user = active_user_with_permissions(uuid4()) user = active_user_with_permissions(uuid4())
user.email_address = email_address user.email_address = email_address
@@ -1300,12 +1334,12 @@ def test_should_redirect_after_request_to_go_live(
( # Not done anything yet ( # Not done anything yet
False, False,
False, False,
True, False,
True, False,
False,
False, False,
True, True,
True, None, None, None,
0, None, 0,
'No', 'No',
False, False,
[ [
@@ -1351,14 +1385,17 @@ def test_ready_to_go_live(
new_callable=PropertyMock new_callable=PropertyMock
).return_value = locals()[prop] ).return_value = locals()[prop]
mocker.patch( for channel, volume in (
'app.models.service.Service.__getattr__', ('sms', volume_sms),
side_effect=lambda prop: { ('email', volume_email),
'volume_email': volume_email, ('letter', volume_letter),
'volume_sms': volume_sms, ):
'volume_letter': volume_letter, mocker.patch(
}.get(prop) 'app.models.service.Service.volume_{}'.format(channel),
) create=True,
new_callable=PropertyMock,
return_value=volume,
)
assert app.models.service.Service({ assert app.models.service.Service({
'id': SERVICE_ONE_ID 'id': SERVICE_ONE_ID