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

@@ -633,7 +633,6 @@ def test_edit_user_permissions(
_expected_redirect=url_for(
'main.manage_users',
service_id=SERVICE_ONE_ID,
_external=True,
),
)
mock_set_user_permissions.assert_called_with(
@@ -713,7 +712,6 @@ def test_edit_user_permissions_for_broadcast_service(
_expected_redirect=url_for(
'main.manage_users',
service_id=SERVICE_ONE_ID,
_external=True,
),
)
mock_set_user_permissions.assert_called_with(
@@ -762,7 +760,6 @@ def test_edit_user_folder_permissions(
_expected_redirect=url_for(
'main.manage_users',
service_id=SERVICE_ONE_ID,
_external=True,
),
)
mock_set_user_permissions.assert_called_with(
@@ -811,7 +808,6 @@ def test_cant_edit_user_folder_permissions_for_platform_admin_users(
_expected_redirect=url_for(
'main.manage_users',
service_id=SERVICE_ONE_ID,
_external=True,
),
)
mock_set_user_permissions.assert_called_with(
@@ -874,7 +870,6 @@ def test_edit_user_permissions_including_authentication_with_email_auth_service(
_expected_redirect=url_for(
'main.manage_users',
service_id=SERVICE_ONE_ID,
_external=True,
),
)
@@ -1697,7 +1692,7 @@ def test_remove_user_from_service(
'main.remove_user_from_service',
service_id=service_one['id'],
user_id=active_user_with_permissions['id'],
_expected_redirect=url_for('main.manage_users', service_id=service_one['id'], _external=True)
_expected_redirect=url_for('main.manage_users', service_id=service_one['id'])
)
mock_remove_user_from_service.assert_called_once_with(
service_one['id'],
@@ -1778,7 +1773,6 @@ def test_edit_user_email_redirects_to_confirmation(
'main.confirm_edit_user_email',
service_id=SERVICE_ONE_ID,
user_id=active_user_with_permissions['id'],
_external=True,
),
)
with client_request.session_transaction() as session:
@@ -1805,7 +1799,6 @@ def test_edit_user_email_without_changing_goes_back_to_team_members(
_expected_redirect=url_for(
'main.manage_users',
service_id=SERVICE_ONE_ID,
_external=True
),
)
assert mock_update_user_attribute.called is False
@@ -1835,7 +1828,6 @@ def test_edit_user_email_can_change_any_email_address_to_a_gov_email_address(
'main.confirm_edit_user_email',
service_id=SERVICE_ONE_ID,
user_id=active_user_with_permissions['id'],
_external=True
),
)
@@ -1862,7 +1854,6 @@ def test_edit_user_email_can_change_a_non_gov_email_address_to_another_non_gov_e
'main.confirm_edit_user_email',
service_id=SERVICE_ONE_ID,
user_id=active_user_with_permissions['id'],
_external=True
),
)
@@ -1975,7 +1966,6 @@ def test_confirm_edit_user_email_changes_user_email(
_expected_redirect=url_for(
'main.manage_users',
service_id=SERVICE_ONE_ID,
_external=True,
),
)
@@ -2087,7 +2077,6 @@ def test_edit_user_mobile_number_redirects_to_confirmation(
'main.confirm_edit_user_mobile_number',
service_id=SERVICE_ONE_ID,
user_id=active_user_with_permissions['id'],
_external=True,
),
)
@@ -2109,7 +2098,6 @@ def test_edit_user_mobile_number_redirects_to_manage_users_if_number_not_changed
_expected_redirect=url_for(
'main.manage_users',
service_id=SERVICE_ONE_ID,
_external=True,
),
)
@@ -2189,7 +2177,6 @@ def test_confirm_edit_user_mobile_number_changes_user_mobile_number(
_expected_redirect=url_for(
'main.manage_users',
service_id=SERVICE_ONE_ID,
_external=True,
),
)
mock_update_user_attribute.assert_called_once_with(