Merge pull request #1346 from alphagov/allow-email-and-sms-to-be-disabled

Allow email and sms to be disabled
This commit is contained in:
kentsanggds
2017-07-10 12:43:17 +01:00
committed by GitHub
12 changed files with 509 additions and 67 deletions

View File

@@ -38,6 +38,32 @@ def test_that_test_files_exist():
assert len(test_non_spreadsheet_files) == 6
def test_should_not_allow_files_to_be_uploaded_without_the_correct_permission(
logged_in_client,
mock_get_service_template,
service_one,
fake_uuid,
):
template_id = fake_uuid
service_one['permissions'] = []
response = logged_in_client.get(url_for(
'.send_messages',
service_id=service_one['id'],
template_id=template_id),
follow_redirects=True)
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert response.status_code == 200
assert page.select('main p')[0].text.strip() == "Sending text messages has been disabled for your service."
assert page.select(".page-footer-back-link")[0].text == "Back to the template"
assert page.select(".page-footer-back-link")[0]['href'] == url_for(
'.view_template',
service_id=service_one['id'],
template_id=template_id,
)
@pytest.mark.parametrize(
"filename, acceptable_file",
list(zip(
@@ -310,6 +336,32 @@ def test_send_test_step_redirects_if_session_not_setup(
assert session['recipient'] == expected_recipient
def test_send_one_off_does_not_send_without_the_correct_permissions(
logged_in_client,
mock_get_service_template,
service_one,
fake_uuid,
):
template_id = fake_uuid
service_one['permissions'] = []
response = logged_in_client.get(url_for(
'.send_one_off',
service_id=service_one['id'],
template_id=template_id),
follow_redirects=True)
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert response.status_code == 200
assert page.select('main p')[0].text.strip() == "Sending text messages has been disabled for your service."
assert page.select(".page-footer-back-link")[0].text == "Back to the template"
assert page.select(".page-footer-back-link")[0]['href'] == url_for(
'.view_template',
service_id=service_one['id'],
template_id=template_id,
)
@pytest.mark.parametrize('template_mock, partial_url, expected_h1, tour_shown', [
(
mock_get_service_template_with_placeholders,
@@ -542,11 +594,15 @@ def test_send_test_redirects_to_start_if_index_out_of_bounds_and_some_placeholde
])
def _redirects_with_help_argument(
logged_in_client,
mocker,
service_one,
fake_uuid,
endpoint,
expected_redirect,
):
template = {'data': {'template_type': 'sms'}}
mocker.patch('app.service_api_client.get_service_template', return_value=template)
response = logged_in_client.get(
url_for(endpoint, service_id=service_one['id'], template_id=fake_uuid, help=1)
)
@@ -848,6 +904,8 @@ def test_send_test_clears_session(
service_one,
fake_uuid,
):
template = {'data': {'template_type': 'sms'}}
mocker.patch('app.service_api_client.get_service_template', return_value=template)
with logged_in_client.session_transaction() as session:
session['recipient'] = '07700900001'

View File

@@ -19,7 +19,9 @@ from tests.conftest import active_user_with_permissions, platform_admin_user
(active_user_with_permissions, [
'Label Value Action',
'Service name service one Change',
'Send emails On Change',
'Email reply to address None Change',
'Send text messages On Change',
'Text message sender GOVUK Change',
'International text messages Off Change',
'Receive text messages Off Change',
@@ -28,7 +30,9 @@ from tests.conftest import active_user_with_permissions, platform_admin_user
(platform_admin_user, [
'Label Value Action',
'Service name service one Change',
'Send emails On Change',
'Email reply to address None Change',
'Send text messages On Change',
'Text message sender GOVUK Change',
'International text messages Off Change',
'Receive text messages Off Change',
@@ -47,6 +51,8 @@ def test_should_show_overview(
user,
expected_rows,
):
service_one['permissions'] = ['sms', 'email']
client.login(user(fake_uuid), mocker, service_one)
response = client.get(url_for(
'main.service_settings', service_id=service_one['id']
@@ -64,7 +70,9 @@ def test_should_show_overview(
@pytest.mark.parametrize('permissions, expected_rows', [
(['email', 'sms', 'inbound_sms', 'international_sms'], [
'Service name service one Change',
'Send emails On Change',
'Email reply to address test@example.com Change',
'Send text messages On Change',
'Text message sender elevenchars',
'International text messages On Change',
'Receive text messages On Change',
@@ -73,7 +81,9 @@ def test_should_show_overview(
]),
(['email', 'sms'], [
'Service name service one Change',
'Send emails On Change',
'Email reply to address test@example.com Change',
'Send text messages On Change',
'Text message sender elevenchars Change',
'International text messages Off Change',
'Receive text messages Off Change',
@@ -114,7 +124,7 @@ def test_service_settings_show_elided_api_url_if_needed(
url,
elided_url
):
service_one['permissions'] = ['inbound_sms']
service_one['permissions'] = ['sms', 'email', 'inbound_sms']
service_one['inbound_api'] = [fake_uuid]
mocked_get_fn = mocker.patch(
@@ -152,7 +162,7 @@ def test_if_can_receive_inbound_then_cant_change_sms_sender(
service_one,
mock_get_letter_organisations,
):
service_one['permissions'] = ['inbound_sms']
service_one['permissions'] = ['email', 'sms', 'inbound_sms']
service_one['sms_sender'] = 'SomeNumber'
response = logged_in_client.get(url_for(
'main.service_settings', service_id=service_one['id']
@@ -177,7 +187,7 @@ def test_letter_contact_block_shows_none_if_not_set(
))
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
div = page.find_all('tr')[7].find_all('td')[1].div
div = page.find_all('tr')[5].find_all('td')[1].div
assert div.text.strip() == 'None'
assert 'default' in div.attrs['class'][0]
@@ -195,7 +205,7 @@ def test_escapes_letter_contact_block(
))
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
div = str(page.find_all('tr')[7].find_all('td')[1].div)
div = str(page.find_all('tr')[5].find_all('td')[1].div)
assert 'foo<br>bar' in div
assert '<script>' not in div
@@ -570,12 +580,39 @@ def test_route_for_platform_admin_update_service(
service_one)
@pytest.mark.parametrize('notification_type, permissions_before_switch, permissions_after_switch', [
('email', [], ['email']),
('email', ['email'], []),
('sms', [], ['sms']),
('sms', ['sms'], [])
])
def test_enabling_and_disabling_email_and_sms(
logged_in_platform_admin_client,
service_one,
mocker,
notification_type,
permissions_before_switch,
permissions_after_switch,
):
service_one['permissions'] = permissions_before_switch
mocked_fn = mocker.patch('app.service_api_client.update_service_with_properties', return_value=service_one)
response = logged_in_platform_admin_client.get(
url_for('main.service_switch_can_send_{}'.format(notification_type), service_id=service_one['id'])
)
assert response.status_code == 302
assert response.location == url_for('main.service_settings', service_id=service_one['id'], _external=True)
assert mocked_fn.call_args == call(service_one['id'], {'permissions': permissions_after_switch})
def test_set_reply_to_email_address(
logged_in_client,
mock_update_service,
service_one,
mock_get_letter_organisations,
):
service_one['permissions'] = ['email']
data = {"email_address": "test@someservice.gov.uk"}
response = logged_in_client.post(url_for('main.service_set_reply_to_email', service_id=service_one['id']),
data=data,
@@ -591,6 +628,7 @@ def test_if_reply_to_email_address_set_then_form_populated(
logged_in_client,
service_one,
):
service_one['permissions'] = ['email']
service_one['reply_to_email_address'] = 'test@service.gov.uk'
response = logged_in_client.get(url_for('main.service_set_reply_to_email', service_id=service_one['id']))

View File

@@ -270,6 +270,64 @@ def test_dont_show_preview_letter_templates_for_bad_filetype(
assert mock_get_service_template.called is False
@pytest.mark.parametrize('type_of_template', ['email', 'sms'])
def test_should_not_allow_creation_of_template_through_form_without_correct_permission(
logged_in_client,
service_one,
mocker,
type_of_template,
):
service_one['permissions'] = []
template_description = {'sms': 'text messages', 'email': 'emails'}
response = logged_in_client.post(url_for(
'.add_template_by_type',
service_id=service_one['id']),
data={'template_type': type_of_template},
follow_redirects=True)
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert response.status_code == 200
assert page.select('main p')[0].text.strip() == \
"Sending {} has been disabled for your service.".format(template_description[type_of_template])
assert page.select(".page-footer-back-link")[0].text == "Back to add new template"
assert page.select(".page-footer-back-link")[0]['href'] == url_for(
'.add_template_by_type',
service_id=service_one['id'],
template_id='0',
)
@pytest.mark.parametrize('type_of_template', ['email', 'sms'])
def test_should_not_allow_creation_of_a_template_without_correct_permission(
logged_in_client,
service_one,
mocker,
type_of_template,
):
service_one['permissions'] = []
template_description = {'sms': 'text messages', 'email': 'emails'}
response = logged_in_client.get(url_for(
'.add_service_template',
service_id=service_one['id'],
template_type=type_of_template),
follow_redirects=True)
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert response.status_code == 200
assert page.select('main p')[0].text.strip() == \
"Sending {} has been disabled for your service.".format(template_description[type_of_template])
assert page.select(".page-footer-back-link")[0].text == "Back to templates"
assert page.select(".page-footer-back-link")[0]['href'] == url_for(
'.choose_template',
service_id=service_one['id'],
template_id='0',
)
def test_should_redirect_when_saving_a_template(
logged_in_client,
active_user_with_permissions,
@@ -340,6 +398,32 @@ def test_should_edit_content_when_process_type_is_priority_not_platform_admin(
)
def test_should_not_allow_template_edits_without_correct_permission(
logged_in_client,
mock_get_service_template,
service_one,
fake_uuid,
):
template_id = fake_uuid
service_one['permissions'] = ['email']
response = logged_in_client.get(url_for(
'.edit_service_template',
service_id=service_one['id'],
template_id=template_id),
follow_redirects=True)
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert response.status_code == 200
assert page.select('main p')[0].text.strip() == "Sending text messages has been disabled for your service."
assert page.select(".page-footer-back-link")[0].text == "Back to the template"
assert page.select(".page-footer-back-link")[0]['href'] == url_for(
'.view_template',
service_id=service_one['id'],
template_id=template_id,
)
def test_should_403_when_edit_template_with_process_type_of_priority_for_non_platform_admin(
client,
active_user_with_permissions,