mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-10 18:22:37 -04:00
notify-api-412 use black to enforce python coding style
This commit is contained in:
+147
-131
@@ -13,19 +13,17 @@ def test_non_logged_in_user_can_see_homepage(
|
||||
mock_get_service_and_organization_counts,
|
||||
):
|
||||
client_request.logout()
|
||||
page = client_request.get('main.index', _test_page_title=False)
|
||||
page = client_request.get("main.index", _test_page_title=False)
|
||||
|
||||
assert page.h1.text.strip() == (
|
||||
'Send text messages to your participants'
|
||||
assert page.h1.text.strip() == ("Send text messages to your participants")
|
||||
|
||||
assert page.select_one("a.usa-button.usa-button--big")["href"] == url_for(
|
||||
"main.sign_in",
|
||||
)
|
||||
|
||||
assert page.select_one('a.usa-button.usa-button--big')['href'] == url_for(
|
||||
'main.sign_in',
|
||||
)
|
||||
|
||||
assert page.select_one('meta[name=description]')['content'].strip() == (
|
||||
'Notify.gov lets you send text messages to your users. '
|
||||
'Try it now if you work in federal, state, or local government.'
|
||||
assert page.select_one("meta[name=description]")["content"].strip() == (
|
||||
"Notify.gov lets you send text messages to your users. "
|
||||
"Try it now if you work in federal, state, or local government."
|
||||
)
|
||||
|
||||
# This area is hidden for the pilot
|
||||
@@ -36,7 +34,7 @@ def test_non_logged_in_user_can_see_homepage(
|
||||
# 'There are 111 Organizations and 9,999 Services using Notify.'
|
||||
# )
|
||||
|
||||
assert page.select_one('#whos-using-notify a') is None
|
||||
assert page.select_one("#whos-using-notify a") is None
|
||||
|
||||
|
||||
def test_logged_in_user_redirects_to_choose_account(
|
||||
@@ -47,34 +45,37 @@ def test_logged_in_user_redirects_to_choose_account(
|
||||
mock_login,
|
||||
):
|
||||
client_request.get(
|
||||
'main.index',
|
||||
"main.index",
|
||||
_expected_status=302,
|
||||
)
|
||||
client_request.get(
|
||||
'main.sign_in',
|
||||
"main.sign_in",
|
||||
_expected_status=302,
|
||||
_expected_redirect=url_for('main.show_accounts_or_dashboard')
|
||||
_expected_redirect=url_for("main.show_accounts_or_dashboard"),
|
||||
)
|
||||
|
||||
|
||||
def test_robots(client_request):
|
||||
client_request.get_url('/robots.txt', _expected_status=404)
|
||||
client_request.get_url("/robots.txt", _expected_status=404)
|
||||
|
||||
|
||||
@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', {}),
|
||||
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
|
||||
@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", {}),
|
||||
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
|
||||
def test_hiding_pages_from_search_engines(
|
||||
client_request,
|
||||
mock_get_service_and_organization_counts,
|
||||
@@ -82,103 +83,113 @@ def test_hiding_pages_from_search_engines(
|
||||
kwargs,
|
||||
):
|
||||
client_request.logout()
|
||||
response = client_request.get_response(f'main.{endpoint}', **kwargs)
|
||||
assert 'X-Robots-Tag' in response.headers
|
||||
assert response.headers['X-Robots-Tag'] == 'noindex'
|
||||
response = client_request.get_response(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')
|
||||
assert page.select_one('meta[name=robots]')['content'] == 'noindex'
|
||||
page = BeautifulSoup(response.data.decode("utf-8"), "html.parser")
|
||||
assert page.select_one("meta[name=robots]")["content"] == "noindex"
|
||||
|
||||
|
||||
@pytest.mark.parametrize('view', [
|
||||
'privacy', 'pricing', 'terms', 'roadmap',
|
||||
'features', 'documentation', 'security',
|
||||
'message_status', 'features_email', 'features_sms',
|
||||
'how_to_pay', 'get_started',
|
||||
'guidance_index', 'branding_and_customisation',
|
||||
'create_and_send_messages', 'edit_and_format_messages',
|
||||
'send_files_by_email',
|
||||
'billing_details',
|
||||
])
|
||||
@pytest.mark.parametrize(
|
||||
"view",
|
||||
[
|
||||
"privacy",
|
||||
"pricing",
|
||||
"terms",
|
||||
"roadmap",
|
||||
"features",
|
||||
"documentation",
|
||||
"security",
|
||||
"message_status",
|
||||
"features_email",
|
||||
"features_sms",
|
||||
"how_to_pay",
|
||||
"get_started",
|
||||
"guidance_index",
|
||||
"branding_and_customisation",
|
||||
"create_and_send_messages",
|
||||
"edit_and_format_messages",
|
||||
"send_files_by_email",
|
||||
"billing_details",
|
||||
],
|
||||
)
|
||||
def test_static_pages(
|
||||
client_request,
|
||||
mock_get_organization_by_domain,
|
||||
view,
|
||||
):
|
||||
request = partial(client_request.get, 'main.{}'.format(view))
|
||||
request = partial(client_request.get, "main.{}".format(view))
|
||||
|
||||
# Check the page loads when user is signed in
|
||||
page = request()
|
||||
assert not page.select_one('meta[name=description]')
|
||||
assert not page.select_one("meta[name=description]")
|
||||
|
||||
# Check it still works when they don’t have a recent service
|
||||
with client_request.session_transaction() as session:
|
||||
session['service_id'] = None
|
||||
session["service_id"] = None
|
||||
request()
|
||||
|
||||
# Check it redirects to the login screen when they sign out
|
||||
client_request.logout()
|
||||
with client_request.session_transaction() as session:
|
||||
session['service_id'] = None
|
||||
session['user_id'] = None
|
||||
session["service_id"] = None
|
||||
session["user_id"] = None
|
||||
request(
|
||||
_expected_status=302,
|
||||
_expected_redirect='/sign-in?next={}'.format(
|
||||
url_for('main.{}'.format(view))
|
||||
)
|
||||
_expected_redirect="/sign-in?next={}".format(url_for("main.{}".format(view))),
|
||||
)
|
||||
|
||||
|
||||
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'
|
||||
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',
|
||||
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
|
||||
session["service_id"] = None
|
||||
page = request()
|
||||
assert not page.select_one(selector)
|
||||
|
||||
# Check it redirects to the login screen when they sign out
|
||||
client_request.logout()
|
||||
with client_request.session_transaction() as session:
|
||||
session['service_id'] = None
|
||||
session['user_id'] = None
|
||||
session["service_id"] = None
|
||||
session["user_id"] = None
|
||||
page = request(_expected_status=302)
|
||||
assert not page.select_one(selector)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('view, expected_view', [
|
||||
('information_risk_management', 'security'),
|
||||
('old_integration_testing', 'integration_testing'),
|
||||
('old_roadmap', 'roadmap'),
|
||||
('information_risk_management', 'security'),
|
||||
('old_terms', 'terms'),
|
||||
('information_security', 'using_notify'),
|
||||
('old_using_notify', 'using_notify'),
|
||||
('delivery_and_failure', 'message_status'),
|
||||
('callbacks', 'documentation'),
|
||||
])
|
||||
def test_old_static_pages_redirect(
|
||||
client_request,
|
||||
view,
|
||||
expected_view
|
||||
):
|
||||
@pytest.mark.parametrize(
|
||||
"view, expected_view",
|
||||
[
|
||||
("information_risk_management", "security"),
|
||||
("old_integration_testing", "integration_testing"),
|
||||
("old_roadmap", "roadmap"),
|
||||
("information_risk_management", "security"),
|
||||
("old_terms", "terms"),
|
||||
("information_security", "using_notify"),
|
||||
("old_using_notify", "using_notify"),
|
||||
("delivery_and_failure", "message_status"),
|
||||
("callbacks", "documentation"),
|
||||
],
|
||||
)
|
||||
def test_old_static_pages_redirect(client_request, view, expected_view):
|
||||
client_request.logout()
|
||||
client_request.get(
|
||||
'main.{}'.format(view),
|
||||
"main.{}".format(view),
|
||||
_expected_status=301,
|
||||
_expected_redirect=url_for(
|
||||
'main.{}'.format(expected_view),
|
||||
"main.{}".format(expected_view),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -186,23 +197,25 @@ def test_old_static_pages_redirect(
|
||||
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')
|
||||
page = client_request.get("main.message_status")
|
||||
|
||||
# email-statuses is commented out in view
|
||||
# assert page.find(id='email-statuses')
|
||||
assert page.find(id='text-message-statuses')
|
||||
assert page.find(id="text-message-statuses")
|
||||
|
||||
|
||||
def test_message_status_page_contains_link_to_support(client_request):
|
||||
page = client_request.get('main.message_status')
|
||||
sms_status_table = page.find(id='text-message-statuses').findNext('tbody')
|
||||
page = client_request.get("main.message_status")
|
||||
sms_status_table = page.find(id="text-message-statuses").findNext("tbody")
|
||||
|
||||
temp_fail_details_cell = sms_status_table.select_one('tr:nth-child(4) > td:nth-child(2)')
|
||||
assert temp_fail_details_cell.find('a').attrs['href'] == url_for('main.support')
|
||||
temp_fail_details_cell = sms_status_table.select_one(
|
||||
"tr:nth-child(4) > td:nth-child(2)"
|
||||
)
|
||||
assert temp_fail_details_cell.find("a").attrs["href"] == url_for("main.support")
|
||||
|
||||
|
||||
def test_old_using_notify_page(client_request):
|
||||
client_request.get('main.using_notify', _expected_status=410)
|
||||
client_request.get("main.using_notify", _expected_status=410)
|
||||
|
||||
|
||||
# def test_old_integration_testing_page(
|
||||
@@ -223,23 +236,23 @@ def test_old_using_notify_page(client_request):
|
||||
|
||||
|
||||
def test_terms_page_has_correct_content(client_request):
|
||||
terms_page = client_request.get('main.terms')
|
||||
assert normalize_spaces(terms_page.select('main p')[0].text) == (
|
||||
'These terms apply to your service’s use of Notify.gov. '
|
||||
'You must be the service manager to accept them.'
|
||||
terms_page = client_request.get("main.terms")
|
||||
assert normalize_spaces(terms_page.select("main p")[0].text) == (
|
||||
"These terms apply to your service’s use of Notify.gov. "
|
||||
"You must be the service manager to accept them."
|
||||
)
|
||||
|
||||
|
||||
def test_css_is_served_from_correct_path(client_request):
|
||||
page = client_request.get("main.documentation") # easy static page
|
||||
|
||||
page = client_request.get('main.documentation') # easy static page
|
||||
for index, link in enumerate(page.select("link[rel=stylesheet]")):
|
||||
assert link["href"].startswith(
|
||||
[
|
||||
"https://static.example.com/css/styles.css?",
|
||||
][index]
|
||||
)
|
||||
|
||||
for index, link in enumerate(
|
||||
page.select('link[rel=stylesheet]')
|
||||
):
|
||||
assert link['href'].startswith([
|
||||
'https://static.example.com/css/styles.css?',
|
||||
][index])
|
||||
|
||||
# Commenting out until after the pilot when we'll decide on a logo
|
||||
# def test_resources_that_use_asset_path_variable_have_correct_path(client_request):
|
||||
@@ -251,20 +264,23 @@ def test_css_is_served_from_correct_path(client_request):
|
||||
# assert logo_svg_fallback['src'].startswith('https://static.example.com/images/us-notify-color.png')
|
||||
|
||||
|
||||
@pytest.mark.parametrize('extra_args, email_branding_retrieved', (
|
||||
@pytest.mark.parametrize(
|
||||
"extra_args, email_branding_retrieved",
|
||||
(
|
||||
{},
|
||||
False,
|
||||
(
|
||||
{},
|
||||
False,
|
||||
),
|
||||
(
|
||||
{"branding_style": "__NONE__"},
|
||||
False,
|
||||
),
|
||||
(
|
||||
{"branding_style": sample_uuid()},
|
||||
True,
|
||||
),
|
||||
),
|
||||
(
|
||||
{'branding_style': '__NONE__'},
|
||||
False,
|
||||
),
|
||||
(
|
||||
{'branding_style': sample_uuid()},
|
||||
True,
|
||||
),
|
||||
))
|
||||
)
|
||||
def test_email_branding_preview(
|
||||
client_request,
|
||||
mock_get_email_branding,
|
||||
@@ -272,11 +288,9 @@ def test_email_branding_preview(
|
||||
email_branding_retrieved,
|
||||
):
|
||||
page = client_request.get(
|
||||
'main.email_template',
|
||||
_test_page_title=False,
|
||||
**extra_args
|
||||
"main.email_template", _test_page_title=False, **extra_args
|
||||
)
|
||||
assert page.title.text == 'Email branding preview'
|
||||
assert page.title.text == "Email branding preview"
|
||||
assert mock_get_email_branding.called is email_branding_retrieved
|
||||
|
||||
|
||||
@@ -285,20 +299,22 @@ def test_font_preload(
|
||||
mock_get_service_and_organization_counts,
|
||||
):
|
||||
client_request.logout()
|
||||
page = client_request.get('main.index', _test_page_title=False)
|
||||
page = client_request.get("main.index", _test_page_title=False)
|
||||
|
||||
preload_tags = page.select('link[rel=preload][as=font][type="font/woff2"][crossorigin]')
|
||||
preload_tags = page.select(
|
||||
'link[rel=preload][as=font][type="font/woff2"][crossorigin]'
|
||||
)
|
||||
|
||||
assert len(preload_tags) == 4, 'Run `npm run build` to copy fonts into app/static/fonts/'
|
||||
assert (
|
||||
len(preload_tags) == 4
|
||||
), "Run `npm run build` to copy fonts into app/static/fonts/"
|
||||
|
||||
for element in preload_tags:
|
||||
assert element['href'].startswith('https://static.example.com/fonts/')
|
||||
assert element['href'].endswith('.woff2')
|
||||
assert element["href"].startswith("https://static.example.com/fonts/")
|
||||
assert element["href"].endswith(".woff2")
|
||||
|
||||
|
||||
@pytest.mark.parametrize('current_date, expected_rate', (
|
||||
('2022-05-01', '1.72'),
|
||||
))
|
||||
@pytest.mark.parametrize("current_date, expected_rate", (("2022-05-01", "1.72"),))
|
||||
@pytest.mark.skip(reason="Currently hidden for TTS")
|
||||
def test_sms_price(
|
||||
client_request,
|
||||
@@ -309,21 +325,21 @@ def test_sms_price(
|
||||
client_request.logout()
|
||||
|
||||
with freeze_time(current_date):
|
||||
home_page = client_request.get('main.index', _test_page_title=False)
|
||||
pricing_page = client_request.get('main.pricing')
|
||||
home_page = client_request.get("main.index", _test_page_title=False)
|
||||
pricing_page = client_request.get("main.pricing")
|
||||
|
||||
assert normalize_spaces(
|
||||
home_page.select('.product-page-section')[5].select('.govuk-grid-column-one-half')[1].text
|
||||
home_page.select(".product-page-section")[5]
|
||||
.select(".govuk-grid-column-one-half")[1]
|
||||
.text
|
||||
) == (
|
||||
f'Text messages '
|
||||
f'Up to 40,000 free text messages a year, '
|
||||
f'then {expected_rate} pence per message'
|
||||
f"Text messages "
|
||||
f"Up to 40,000 free text messages a year, "
|
||||
f"then {expected_rate} pence per message"
|
||||
)
|
||||
|
||||
assert normalize_spaces(
|
||||
pricing_page.select_one('#text-messages + p + p').text
|
||||
) == (
|
||||
f'When a service has used its annual allowance, it costs '
|
||||
f'{expected_rate} pence (plus VAT) for each text message you '
|
||||
f'send.'
|
||||
assert normalize_spaces(pricing_page.select_one("#text-messages + p + p").text) == (
|
||||
f"When a service has used its annual allowance, it costs "
|
||||
f"{expected_rate} pence (plus VAT) for each text message you "
|
||||
f"send."
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user