Stop using _external=True in tests

It looks like, by default, Flask no longer makes full URLs, for example
`https://example.com/path`. Instead it does `/path`. This will still
work fine, and if anything is better because it reduces the number of
bytes of HTML we are sending.

It won’t mean that requests go over `http` instead of `https` without
the protocol because we set the appropriate HSTS header here:
0c57da7781/ansible/roles/paas-proxy/templates/admin.conf.j2 (L11)

This commit changes all our tests to reflect that URLs no longer have
the protocol and domain in them. `_external=True` is Flask’s way of
saying whether a URL should be generated with the domain and protocol
(`True`) or without it (`False`).

Again, I can’t find the changelog or diff where this was introuduced,
but if you’d like to go spelunking then here’s a starting point:
50374e3cfe/src/flask/helpers.py (L192)
This commit is contained in:
Chris Hill-Scott
2022-05-27 14:46:35 +01:00
parent 5b5d4af681
commit 8b7f2fbf04
38 changed files with 83 additions and 251 deletions

View File

@@ -38,7 +38,7 @@ def test_show_accounts_or_dashboard_redirects_to_choose_account_or_service_dashb
client_request.get(
'main.show_accounts_or_dashboard',
_expected_redirect=url_for(endpoint, _external=True, **endpoint_kwargs)
_expected_redirect=url_for(endpoint, **endpoint_kwargs)
)
@@ -53,7 +53,6 @@ def test_show_accounts_or_dashboard_redirects_if_service_in_session(client_reque
_expected_redirect=url_for(
'main.service_dashboard',
service_id='service1',
_external=True
),
)
@@ -69,7 +68,6 @@ def test_show_accounts_or_dashboard_redirects_if_org_in_session(client_request):
_expected_redirect=url_for(
'main.organisation_dashboard',
org_id='org1',
_external=True
),
)
@@ -86,7 +84,7 @@ def test_show_accounts_or_dashboard_doesnt_redirect_to_service_dashboard_if_user
client_request.get(
'.show_accounts_or_dashboard',
_expected_redirect=url_for('main.organisation_dashboard', org_id='org1', _external=True)
_expected_redirect=url_for('main.organisation_dashboard', org_id='org1')
)
@@ -101,7 +99,7 @@ def test_show_accounts_or_dashboard_doesnt_redirect_to_org_dashboard_if_user_not
client_request.get(
'.show_accounts_or_dashboard',
_expected_redirect=url_for('main.organisation_dashboard', org_id='org1', _external=True)
_expected_redirect=url_for('main.organisation_dashboard', org_id='org1')
)
@@ -112,7 +110,7 @@ def test_show_accounts_or_dashboard_redirects_if_not_logged_in(
client_request.logout()
client_request.get(
'main.show_accounts_or_dashboard',
_expected_redirect=url_for('main.index', _external=True),
_expected_redirect=url_for('main.index'),
)
@@ -131,7 +129,6 @@ def test_show_accounts_or_dashboard_redirects_to_service_dashboard_if_platform_a
_expected_redirect=url_for(
'main.service_dashboard',
service_id='service2',
_external=True
),
)
@@ -149,6 +146,5 @@ def test_show_accounts_or_dashboard_redirects_to_org_dashboard_if_platform_admin
_expected_redirect=url_for(
'main.organisation_dashboard',
org_id='org2',
_external=True
),
)