2019-10-31 09:43:16 +00:00
|
|
|
|
from functools import partial
|
2019-10-31 10:53:45 +00:00
|
|
|
|
|
2016-04-19 13:51:16 +01:00
|
|
|
|
import pytest
|
2017-11-14 17:25:32 +00:00
|
|
|
|
from bs4 import BeautifulSoup
|
2016-04-26 10:32:26 +01:00
|
|
|
|
from flask import url_for
|
2020-05-26 17:39:25 +01:00
|
|
|
|
from freezegun import freeze_time
|
2018-04-25 14:12:58 +01:00
|
|
|
|
|
2019-02-15 14:47:39 +00:00
|
|
|
|
from app.main.forms import FieldWithNoneOption
|
2020-02-20 15:11:10 +00:00
|
|
|
|
from tests.conftest import SERVICE_ONE_ID, normalize_spaces, sample_uuid
|
2016-01-22 17:24:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
2017-11-14 17:25:32 +00:00
|
|
|
|
def test_non_logged_in_user_can_see_homepage(
|
|
|
|
|
|
client,
|
2019-04-10 17:20:51 +01:00
|
|
|
|
mock_get_service_and_organisation_counts,
|
2017-11-14 17:25:32 +00:00
|
|
|
|
):
|
|
|
|
|
|
response = client.get(url_for('main.index'))
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
|
|
|
|
|
|
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
|
|
|
|
|
|
2018-01-18 16:38:15 +00:00
|
|
|
|
assert page.h1.text.strip() == (
|
|
|
|
|
|
'Send emails, text messages and letters to your users'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2020-01-07 17:47:17 +00:00
|
|
|
|
assert page.select_one('a[role=button][draggable=false]')['href'] == url_for(
|
|
|
|
|
|
'main.register'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2018-01-18 16:38:15 +00:00
|
|
|
|
assert page.select_one('meta[name=description]')['content'].strip() == (
|
|
|
|
|
|
'GOV.UK Notify lets you send emails, text messages and letters '
|
|
|
|
|
|
'to your users. Try it now if you work in central government, a '
|
|
|
|
|
|
'local authority, or the NHS.'
|
2017-11-14 17:25:32 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
2019-04-10 17:20:51 +01:00
|
|
|
|
assert normalize_spaces(page.select_one('#whos-using-notify').text) == (
|
|
|
|
|
|
'Who’s using GOV.UK Notify '
|
|
|
|
|
|
'Services '
|
2019-07-08 12:00:40 +01:00
|
|
|
|
'9,999 services '
|
2019-04-10 17:20:51 +01:00
|
|
|
|
'Organisations '
|
|
|
|
|
|
'111 organisations '
|
|
|
|
|
|
'See the list of services and organisations.'
|
|
|
|
|
|
)
|
|
|
|
|
|
assert page.select_one('#whos-using-notify a')['href'] == (
|
|
|
|
|
|
'https://www.gov.uk/performance/govuk-notify/government-services'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2017-11-14 17:25:32 +00:00
|
|
|
|
|
2018-03-08 16:51:53 +00:00
|
|
|
|
def test_logged_in_user_redirects_to_choose_account(
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
api_user_active,
|
|
|
|
|
|
mock_get_user,
|
|
|
|
|
|
mock_get_user_by_email,
|
|
|
|
|
|
mock_login,
|
|
|
|
|
|
):
|
2019-03-26 12:35:32 +00:00
|
|
|
|
client_request.get(
|
|
|
|
|
|
'main.index',
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
)
|
|
|
|
|
|
client_request.get(
|
|
|
|
|
|
'main.sign_in',
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for('main.show_accounts_or_dashboard', _external=True)
|
|
|
|
|
|
)
|
2016-09-07 10:49:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
2020-05-26 17:47:43 +01:00
|
|
|
|
def test_robots(client_request):
|
|
|
|
|
|
client_request.get_url('/robots.txt', _expected_status=404)
|
2018-08-29 15:41:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
2020-05-26 17:39:25 +01:00
|
|
|
|
@pytest.mark.parametrize('endpoint, kwargs', (
|
|
|
|
|
|
('sign_in', {}),
|
|
|
|
|
|
('support', {}),
|
|
|
|
|
|
('support_public', {}),
|
|
|
|
|
|
('triage', {}),
|
|
|
|
|
|
('feedback', {'ticket_type': 'ask-question-give-feedback'}),
|
|
|
|
|
|
('feedback', {'ticket_type': 'general'}),
|
|
|
|
|
|
('feedback', {'ticket_type': 'report-problem'}),
|
|
|
|
|
|
('bat_phone', {}),
|
|
|
|
|
|
('thanks', {}),
|
|
|
|
|
|
('register', {}),
|
2020-05-26 17:45:55 +01:00
|
|
|
|
('features_email', {}),
|
2020-05-26 17:39:25 +01:00
|
|
|
|
pytest.param('index', {}, marks=pytest.mark.xfail(raises=AssertionError)),
|
|
|
|
|
|
))
|
|
|
|
|
|
@freeze_time('2012-12-12 12:12') # So we don’t go out of business hours
|
2020-05-27 09:03:14 +01:00
|
|
|
|
def test_hiding_pages_from_search_engines(
|
|
|
|
|
|
client,
|
|
|
|
|
|
mock_get_service_and_organisation_counts,
|
|
|
|
|
|
endpoint,
|
|
|
|
|
|
kwargs,
|
|
|
|
|
|
):
|
|
|
|
|
|
response = client.get(url_for(f'main.{endpoint}', **kwargs))
|
|
|
|
|
|
assert 'X-Robots-Tag' in response.headers
|
|
|
|
|
|
assert response.headers['X-Robots-Tag'] == 'noindex'
|
|
|
|
|
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
2020-05-26 17:39:25 +01:00
|
|
|
|
assert page.select_one('meta[name=robots]')['content'] == 'noindex'
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-09-07 10:49:57 +01:00
|
|
|
|
@pytest.mark.parametrize('view', [
|
2019-04-11 12:00:37 +01:00
|
|
|
|
'cookies', 'privacy', 'pricing', 'terms', 'roadmap',
|
2019-09-05 16:24:40 +01:00
|
|
|
|
'features', 'documentation', 'security',
|
2019-04-18 13:06:39 +01:00
|
|
|
|
'message_status', 'features_email', 'features_sms',
|
2020-01-24 15:57:29 +00:00
|
|
|
|
'features_letters', 'how_to_pay', 'get_started',
|
|
|
|
|
|
'guidance_index', 'branding_and_customisation',
|
|
|
|
|
|
'create_and_send_messages', 'edit_and_format_messages',
|
2020-05-20 16:03:58 +01:00
|
|
|
|
'send_files_by_email', 'upload_a_letter', 'who_can_use_notify',
|
2016-09-07 10:49:57 +01:00
|
|
|
|
])
|
2017-02-03 12:07:21 +00:00
|
|
|
|
def test_static_pages(
|
2017-12-01 09:46:46 +00:00
|
|
|
|
client_request,
|
2019-04-04 11:12:53 +01:00
|
|
|
|
mock_get_organisation_by_domain,
|
2017-02-03 12:07:21 +00:00
|
|
|
|
view,
|
|
|
|
|
|
):
|
2019-10-31 09:43:16 +00:00
|
|
|
|
request = partial(client_request.get, 'main.{}'.format(view))
|
|
|
|
|
|
|
|
|
|
|
|
# Check the page loads when user is signed in
|
|
|
|
|
|
page = request()
|
2017-11-14 17:25:32 +00:00
|
|
|
|
assert not page.select_one('meta[name=description]')
|
|
|
|
|
|
|
2019-10-31 09:43:16 +00:00
|
|
|
|
# Check it still works when they don’t have a recent service
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['service_id'] = None
|
|
|
|
|
|
request()
|
|
|
|
|
|
|
|
|
|
|
|
# Check it still works when they sign out
|
2019-10-17 16:15:28 +01:00
|
|
|
|
client_request.logout()
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['service_id'] = None
|
|
|
|
|
|
session['user_id'] = None
|
2019-10-31 09:43:16 +00:00
|
|
|
|
request()
|
2019-10-17 16:15:28 +01:00
|
|
|
|
|
2017-08-30 15:22:26 +01:00
|
|
|
|
|
2020-02-20 15:11:10 +00:00
|
|
|
|
def test_guidance_pages_link_to_service_pages_when_signed_in(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
):
|
|
|
|
|
|
request = partial(client_request.get, 'main.edit_and_format_messages')
|
|
|
|
|
|
selector = '.list-number li a'
|
|
|
|
|
|
|
|
|
|
|
|
# Check the page loads when user is signed in
|
|
|
|
|
|
page = request()
|
|
|
|
|
|
assert page.select_one(selector)['href'] == url_for(
|
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Check it still works when they don’t have a recent service
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['service_id'] = None
|
|
|
|
|
|
page = request()
|
|
|
|
|
|
assert not page.select_one(selector)
|
|
|
|
|
|
|
|
|
|
|
|
# Check it still works when they sign out
|
|
|
|
|
|
client_request.logout()
|
|
|
|
|
|
with client_request.session_transaction() as session:
|
|
|
|
|
|
session['service_id'] = None
|
|
|
|
|
|
session['user_id'] = None
|
|
|
|
|
|
page = request()
|
|
|
|
|
|
assert not page.select_one(selector)
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-11-28 11:56:30 +00:00
|
|
|
|
@pytest.mark.parametrize('view, expected_view', [
|
|
|
|
|
|
('information_risk_management', 'security'),
|
|
|
|
|
|
('old_integration_testing', 'integration_testing'),
|
|
|
|
|
|
('old_roadmap', 'roadmap'),
|
2017-11-28 12:00:12 +00:00
|
|
|
|
('information_risk_management', 'security'),
|
|
|
|
|
|
('old_terms', 'terms'),
|
|
|
|
|
|
('information_security', 'using_notify'),
|
|
|
|
|
|
('old_using_notify', 'using_notify'),
|
2019-04-11 12:00:37 +01:00
|
|
|
|
('delivery_and_failure', 'message_status'),
|
2019-09-05 16:24:40 +01:00
|
|
|
|
('callbacks', 'documentation'),
|
2020-05-21 11:17:44 +01:00
|
|
|
|
('who_its_for', 'who_can_use_notify'),
|
2017-11-28 11:56:30 +00:00
|
|
|
|
])
|
|
|
|
|
|
def test_old_static_pages_redirect(
|
|
|
|
|
|
client,
|
|
|
|
|
|
view,
|
|
|
|
|
|
expected_view
|
|
|
|
|
|
):
|
|
|
|
|
|
response = client.get(url_for('main.{}'.format(view)))
|
|
|
|
|
|
assert response.status_code == 301
|
|
|
|
|
|
assert response.location == url_for(
|
|
|
|
|
|
'main.{}'.format(expected_view),
|
|
|
|
|
|
_external=True
|
|
|
|
|
|
)
|
2018-03-08 12:12:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
2019-05-09 16:31:01 +01:00
|
|
|
|
def test_message_status_page_contains_message_status_ids(client_request):
|
|
|
|
|
|
# The 'email-statuses' and 'sms-statuses' id are linked to when we display a message status,
|
|
|
|
|
|
# so this test ensures we don't accidentally remove them
|
|
|
|
|
|
page = client_request.get('main.message_status')
|
|
|
|
|
|
|
|
|
|
|
|
assert page.find(id='email-statuses')
|
|
|
|
|
|
assert page.find(id='sms-statuses')
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-11 12:00:37 +01:00
|
|
|
|
def test_old_using_notify_page(client_request):
|
|
|
|
|
|
client_request.get('main.using_notify', _expected_status=410)
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-06 17:24:30 +00:00
|
|
|
|
def test_old_integration_testing_page(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.integration_testing',
|
|
|
|
|
|
_expected_status=410,
|
|
|
|
|
|
)
|
2020-02-19 11:57:15 +00:00
|
|
|
|
assert normalize_spaces(page.select_one('.govuk-grid-row').text) == (
|
2018-11-06 17:24:30 +00:00
|
|
|
|
'Integration testing '
|
|
|
|
|
|
'This information has moved. '
|
|
|
|
|
|
'Refer to the documentation for the client library you are using.'
|
|
|
|
|
|
)
|
2020-02-19 11:57:15 +00:00
|
|
|
|
assert page.select_one('.govuk-grid-row a')['href'] == url_for(
|
2018-11-06 17:24:30 +00:00
|
|
|
|
'main.documentation'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-07-12 09:03:35 +01:00
|
|
|
|
def test_terms_page_has_correct_content(client_request):
|
2018-03-16 11:03:30 +00:00
|
|
|
|
terms_page = client_request.get('main.terms')
|
2019-07-12 09:03:35 +01:00
|
|
|
|
assert normalize_spaces(terms_page.select('main p')[0].text) == (
|
|
|
|
|
|
'These terms apply to your service’s use of GOV.UK Notify. '
|
|
|
|
|
|
'You must be the service manager to accept them.'
|
|
|
|
|
|
)
|
2018-11-29 13:06:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_css_is_served_from_correct_path(client_request):
|
|
|
|
|
|
|
2019-04-04 11:12:53 +01:00
|
|
|
|
page = client_request.get('main.documentation') # easy static page
|
2018-11-29 13:06:10 +00:00
|
|
|
|
|
|
|
|
|
|
for index, link in enumerate(
|
|
|
|
|
|
page.select('link[rel=stylesheet]')
|
|
|
|
|
|
):
|
|
|
|
|
|
assert link['href'].startswith([
|
|
|
|
|
|
'https://static.example.com/stylesheets/main.css?',
|
2019-10-22 20:01:30 +01:00
|
|
|
|
'https://static.example.com/stylesheets/print.css?',
|
2018-11-29 13:06:10 +00:00
|
|
|
|
][index])
|
2018-12-05 10:30:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
2020-01-06 11:40:12 +00:00
|
|
|
|
def test_resources_that_use_asset_path_variable_have_correct_path(client_request):
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get('main.documentation') # easy static page
|
|
|
|
|
|
|
|
|
|
|
|
logo_svg_fallback = page.select_one('.govuk-header__logotype-crown-fallback-image')
|
|
|
|
|
|
|
|
|
|
|
|
assert logo_svg_fallback['src'].startswith('https://static.example.com/images/govuk-logotype-crown.png')
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-05 10:30:44 +00:00
|
|
|
|
@pytest.mark.parametrize('extra_args, email_branding_retrieved', (
|
|
|
|
|
|
(
|
|
|
|
|
|
{},
|
|
|
|
|
|
False,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
{'branding_style': '__NONE__'},
|
|
|
|
|
|
False,
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
{'branding_style': sample_uuid()},
|
|
|
|
|
|
True,
|
|
|
|
|
|
),
|
|
|
|
|
|
))
|
|
|
|
|
|
def test_email_branding_preview(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mock_get_email_branding,
|
|
|
|
|
|
extra_args,
|
|
|
|
|
|
email_branding_retrieved,
|
|
|
|
|
|
):
|
|
|
|
|
|
client_request.get(
|
|
|
|
|
|
'main.email_template',
|
|
|
|
|
|
_test_page_title=False,
|
|
|
|
|
|
**extra_args
|
|
|
|
|
|
)
|
|
|
|
|
|
assert mock_get_email_branding.called is email_branding_retrieved
|
2019-02-15 14:47:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('branding_style, filename', [
|
|
|
|
|
|
('hm-government', 'hm-government'),
|
|
|
|
|
|
(None, 'no-branding'),
|
|
|
|
|
|
(FieldWithNoneOption.NONE_OPTION_VALUE, 'no-branding')
|
|
|
|
|
|
])
|
|
|
|
|
|
def test_letter_template_preview_links_to_the_correct_image(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_get_letter_branding_by_id,
|
|
|
|
|
|
branding_style,
|
|
|
|
|
|
filename,
|
|
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get(
|
|
|
|
|
|
'main.letter_template',
|
|
|
|
|
|
_test_page_title=False,
|
2020-06-02 10:13:27 +01:00
|
|
|
|
# Letter HTML doesn’t use the Design System, so elements won’t have class attributes
|
2020-05-29 17:11:01 +01:00
|
|
|
|
_test_for_elements_without_class=False,
|
2019-02-15 14:47:39 +00:00
|
|
|
|
branding_style=branding_style
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
image_link = page.find('img')['src']
|
|
|
|
|
|
|
|
|
|
|
|
assert image_link == url_for(
|
2019-11-29 11:40:49 +00:00
|
|
|
|
'no_cookie.letter_branding_preview_image',
|
2019-02-15 14:47:39 +00:00
|
|
|
|
filename=filename,
|
|
|
|
|
|
page=1
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_letter_template_preview_headers(
|
|
|
|
|
|
client,
|
|
|
|
|
|
mock_get_letter_branding_by_id,
|
|
|
|
|
|
):
|
|
|
|
|
|
response = client.get(
|
|
|
|
|
|
url_for('main.letter_template', branding_style='hm-government')
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert response.headers.get('X-Frame-Options') == 'SAMEORIGIN'
|
2020-01-15 10:56:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_letter_spec_redirect(client_request):
|
|
|
|
|
|
client_request.get(
|
|
|
|
|
|
'main.letter_spec',
|
|
|
|
|
|
_expected_status=302,
|
2020-01-20 15:46:03 +00:00
|
|
|
|
_expected_redirect=(
|
|
|
|
|
|
'https://docs.notifications.service.gov.uk'
|
|
|
|
|
|
'/documentation/images/notify-pdf-letter-spec-v2.4.pdf'
|
|
|
|
|
|
),
|
2020-01-15 10:56:14 +00:00
|
|
|
|
)
|
2020-01-20 15:46:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_letter_spec_redirect_with_non_logged_in_user(client_request):
|
2020-01-15 10:56:14 +00:00
|
|
|
|
client_request.logout()
|
|
|
|
|
|
client_request.get(
|
|
|
|
|
|
'main.letter_spec',
|
|
|
|
|
|
_expected_status=302,
|
2020-01-20 15:46:03 +00:00
|
|
|
|
_expected_redirect=(
|
|
|
|
|
|
'https://docs.notifications.service.gov.uk'
|
|
|
|
|
|
'/documentation/images/notify-pdf-letter-spec-v2.4.pdf'
|
|
|
|
|
|
),
|
2020-01-15 10:56:14 +00:00
|
|
|
|
)
|