mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-10 18:22:37 -04:00
Replace uses of client to set request context
Some tests use the `client` fixture but don’t call any of its methods. The reason for doing this is because the test depends on something in the request context. This commit replaces all those instances with `client_request`, which also sets the request context. These tests are the last ones that still use the `client` fixture. By replacing it with `client_request` we will be able to say that no tests should be using the `client` fixture directly.
This commit is contained in:
@@ -9,7 +9,7 @@ from app.main.forms import CreateKeyForm
|
||||
('2001-01-01 01:01:01', None),
|
||||
))
|
||||
def test_return_validation_error_when_key_name_exists(
|
||||
client,
|
||||
client_request,
|
||||
expiry_date,
|
||||
expected_errors,
|
||||
):
|
||||
@@ -40,7 +40,7 @@ def test_return_validation_error_when_key_name_exists(
|
||||
('invalid', 'Select the type of key')
|
||||
]
|
||||
)
|
||||
def test_return_validation_error_when_key_type_not_chosen(client, key_type, expected_error):
|
||||
def test_return_validation_error_when_key_type_not_chosen(client_request, key_type, expected_error):
|
||||
|
||||
form = CreateKeyForm(
|
||||
[],
|
||||
|
||||
@@ -32,7 +32,7 @@ from app.formatters import (
|
||||
('received', 'letter', lambda: None),
|
||||
))
|
||||
def test_format_notification_status_as_url(
|
||||
client,
|
||||
client_request,
|
||||
status,
|
||||
notification_type,
|
||||
expected,
|
||||
|
||||
@@ -16,7 +16,7 @@ from app.main.validators import (
|
||||
'govuknotify', '11111111', 'kittykat', 'blackbox'
|
||||
])
|
||||
def test_should_raise_validation_error_for_password(
|
||||
client,
|
||||
client_request,
|
||||
mock_get_user_by_email,
|
||||
password,
|
||||
):
|
||||
@@ -31,7 +31,7 @@ def test_should_raise_validation_error_for_password(
|
||||
|
||||
|
||||
def test_valid_email_not_in_valid_domains(
|
||||
client,
|
||||
client_request,
|
||||
mock_get_organisations,
|
||||
):
|
||||
form = RegisterUserForm(email_address="test@test.com", mobile_number='441231231231')
|
||||
@@ -40,7 +40,7 @@ def test_valid_email_not_in_valid_domains(
|
||||
|
||||
|
||||
def test_valid_email_in_valid_domains(
|
||||
client
|
||||
client_request,
|
||||
):
|
||||
form = RegisterUserForm(
|
||||
name="test",
|
||||
@@ -52,7 +52,7 @@ def test_valid_email_in_valid_domains(
|
||||
|
||||
|
||||
def test_invalid_email_address_error_message(
|
||||
client,
|
||||
client_request,
|
||||
mock_get_organisations,
|
||||
):
|
||||
form = RegisterUserForm(
|
||||
@@ -93,7 +93,7 @@ def _gen_mock_field(x):
|
||||
'test@example.sch.uk',
|
||||
])
|
||||
def test_valid_list_of_white_list_email_domains(
|
||||
client,
|
||||
client_request,
|
||||
email,
|
||||
):
|
||||
email_domain_validators = ValidGovEmail()
|
||||
@@ -128,7 +128,7 @@ def test_valid_list_of_white_list_email_domains(
|
||||
'test@123bl.uk',
|
||||
])
|
||||
def test_invalid_list_of_white_list_email_domains(
|
||||
client,
|
||||
client_request,
|
||||
email,
|
||||
mock_get_organisations,
|
||||
):
|
||||
@@ -138,7 +138,7 @@ def test_invalid_list_of_white_list_email_domains(
|
||||
|
||||
|
||||
def test_for_commas_in_placeholders(
|
||||
client
|
||||
client_request,
|
||||
):
|
||||
with pytest.raises(ValidationError) as error:
|
||||
NoCommasInPlaceHolders()(None, _gen_mock_field('Hello ((name,date))'))
|
||||
@@ -147,7 +147,7 @@ def test_for_commas_in_placeholders(
|
||||
|
||||
|
||||
@pytest.mark.parametrize('msg', ['The quick brown fox', 'Thé “quick” bröwn fox\u200B'])
|
||||
def test_sms_character_validation(client, msg):
|
||||
def test_sms_character_validation(client_request, msg):
|
||||
OnlySMSCharacters(template_type='sms')(None, _gen_mock_field(msg))
|
||||
|
||||
|
||||
@@ -167,7 +167,7 @@ def test_sms_character_validation(client, msg):
|
||||
)
|
||||
),
|
||||
])
|
||||
def test_non_sms_character_validation(data, err_msg, client):
|
||||
def test_non_sms_character_validation(data, err_msg, client_request):
|
||||
with pytest.raises(ValidationError) as error:
|
||||
OnlySMSCharacters(template_type='sms')(None, _gen_mock_field(data))
|
||||
|
||||
@@ -203,7 +203,7 @@ def test_if_string_contains_alphanumeric_characters_does_not_raise(string):
|
||||
]
|
||||
)
|
||||
def test_sms_sender_form_validation(
|
||||
client,
|
||||
client_request,
|
||||
mock_get_user_by_email,
|
||||
sms_sender,
|
||||
error_expected,
|
||||
|
||||
@@ -577,7 +577,7 @@ STATISTICS = {
|
||||
}
|
||||
|
||||
|
||||
def test_get_status_filters_calculates_stats(client):
|
||||
def test_get_status_filters_calculates_stats(client_request):
|
||||
ret = get_status_filters(Service({'id': 'foo'}), 'sms', STATISTICS)
|
||||
|
||||
assert {label: count for label, _option, _link, count in ret} == {
|
||||
@@ -588,7 +588,7 @@ def test_get_status_filters_calculates_stats(client):
|
||||
}
|
||||
|
||||
|
||||
def test_get_status_filters_in_right_order(client):
|
||||
def test_get_status_filters_in_right_order(client_request):
|
||||
ret = get_status_filters(Service({'id': 'foo'}), 'sms', STATISTICS)
|
||||
|
||||
assert [label for label, _option, _link, _count in ret] == [
|
||||
@@ -596,7 +596,7 @@ def test_get_status_filters_in_right_order(client):
|
||||
]
|
||||
|
||||
|
||||
def test_get_status_filters_constructs_links(client):
|
||||
def test_get_status_filters_constructs_links(client_request):
|
||||
ret = get_status_filters(Service({'id': 'foo'}), 'sms', STATISTICS)
|
||||
|
||||
link = ret[0][2]
|
||||
|
||||
@@ -370,7 +370,7 @@ def test_inbox_not_accessible_to_service_without_permissions(
|
||||
|
||||
|
||||
def test_anyone_can_see_inbox(
|
||||
client,
|
||||
client_request,
|
||||
api_user_active,
|
||||
service_one,
|
||||
mocker,
|
||||
@@ -382,7 +382,7 @@ def test_anyone_can_see_inbox(
|
||||
|
||||
validate_route_permission_with_client(
|
||||
mocker,
|
||||
client,
|
||||
client_request,
|
||||
'GET',
|
||||
200,
|
||||
url_for('main.inbox', service_id=service_one['id']),
|
||||
@@ -747,7 +747,7 @@ def test_should_show_monthly_breakdown_of_template_usage(
|
||||
|
||||
|
||||
def test_anyone_can_see_monthly_breakdown(
|
||||
client,
|
||||
client_request,
|
||||
api_user_active,
|
||||
service_one,
|
||||
mocker,
|
||||
@@ -755,7 +755,7 @@ def test_anyone_can_see_monthly_breakdown(
|
||||
):
|
||||
validate_route_permission_with_client(
|
||||
mocker,
|
||||
client,
|
||||
client_request,
|
||||
'GET',
|
||||
200,
|
||||
url_for('main.monthly', service_id=service_one['id']),
|
||||
@@ -1605,7 +1605,6 @@ def test_org_breadcrumbs_do_not_show_if_service_has_no_org(
|
||||
|
||||
def test_org_breadcrumbs_do_not_show_if_user_is_not_an_org_member(
|
||||
mocker,
|
||||
client,
|
||||
mock_get_service_templates_when_no_templates_exist,
|
||||
mock_has_no_jobs,
|
||||
active_caseworking_user,
|
||||
|
||||
@@ -2908,7 +2908,7 @@ def test_dont_show_preview_letter_templates_for_bad_filetype(
|
||||
def test_route_permissions(
|
||||
mocker,
|
||||
notify_admin,
|
||||
client,
|
||||
client_request,
|
||||
api_user_active,
|
||||
service_one,
|
||||
mock_get_service_template,
|
||||
@@ -2943,7 +2943,7 @@ def test_route_permissions(
|
||||
def test_route_permissions_send_check_notifications(
|
||||
mocker,
|
||||
notify_admin,
|
||||
client,
|
||||
client_request,
|
||||
api_user_active,
|
||||
service_one,
|
||||
mock_send_notification,
|
||||
@@ -2953,12 +2953,12 @@ def test_route_permissions_send_check_notifications(
|
||||
response_code,
|
||||
method
|
||||
):
|
||||
with client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
session['recipient'] = '07700900001'
|
||||
session['placeholders'] = {'name': 'a'}
|
||||
validate_route_permission_with_client(
|
||||
mocker,
|
||||
client,
|
||||
client_request,
|
||||
method,
|
||||
response_code,
|
||||
url_for(
|
||||
@@ -2980,7 +2980,7 @@ def test_route_permissions_send_check_notifications(
|
||||
def test_route_permissions_sending(
|
||||
mocker,
|
||||
notify_admin,
|
||||
client,
|
||||
client_request,
|
||||
api_user_active,
|
||||
service_one,
|
||||
mock_get_service_template,
|
||||
|
||||
@@ -2015,7 +2015,7 @@ def test_ready_to_go_live(
|
||||
def test_route_permissions(
|
||||
mocker,
|
||||
notify_admin,
|
||||
client,
|
||||
client_request,
|
||||
api_user_active,
|
||||
service_one,
|
||||
single_reply_to_email_address,
|
||||
@@ -2050,7 +2050,7 @@ def test_route_permissions(
|
||||
def test_route_invalid_permissions(
|
||||
mocker,
|
||||
notify_admin,
|
||||
client,
|
||||
client_request,
|
||||
api_user_active,
|
||||
service_one,
|
||||
route,
|
||||
@@ -2077,7 +2077,7 @@ def test_route_invalid_permissions(
|
||||
def test_route_for_platform_admin(
|
||||
mocker,
|
||||
notify_admin,
|
||||
client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
service_one,
|
||||
single_reply_to_email_address,
|
||||
|
||||
@@ -2232,7 +2232,7 @@ def test_route_permissions(
|
||||
route,
|
||||
mocker,
|
||||
notify_admin,
|
||||
client,
|
||||
client_request,
|
||||
api_user_active,
|
||||
service_one,
|
||||
mock_get_service_template,
|
||||
@@ -2259,7 +2259,7 @@ def test_route_permissions(
|
||||
def test_route_permissions_for_choose_template(
|
||||
mocker,
|
||||
notify_admin,
|
||||
client,
|
||||
client_request,
|
||||
api_user_active,
|
||||
mock_get_template_folders,
|
||||
service_one,
|
||||
@@ -2290,7 +2290,7 @@ def test_route_invalid_permissions(
|
||||
route,
|
||||
mocker,
|
||||
notify_admin,
|
||||
client,
|
||||
client_request,
|
||||
api_user_active,
|
||||
service_one,
|
||||
mock_get_service_template,
|
||||
|
||||
@@ -103,7 +103,7 @@ def test_should_404_if_no_mobile_number_for_tour_start(
|
||||
def test_should_403_if_user_does_not_have_send_permissions_for_tour_start(
|
||||
mocker,
|
||||
notify_admin,
|
||||
client,
|
||||
client_request,
|
||||
api_user_active,
|
||||
mock_get_service_template_with_multiple_placeholders,
|
||||
service_one,
|
||||
@@ -258,7 +258,7 @@ def test_should_404_for_get_tour_step_0(
|
||||
def test_should_403_if_user_does_not_have_send_permissions_for_tour_step(
|
||||
mocker,
|
||||
notify_admin,
|
||||
client,
|
||||
client_request,
|
||||
api_user_active,
|
||||
mock_get_service_template_with_multiple_placeholders,
|
||||
service_one,
|
||||
|
||||
@@ -9,9 +9,9 @@ from app.models.webauthn_credential import RegistrationError, WebAuthnCredential
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def webauthn_authentication_post_data(fake_uuid, webauthn_credential, client):
|
||||
def webauthn_authentication_post_data(fake_uuid, webauthn_credential, client_request):
|
||||
|
||||
_set_up_webauthn_session(fake_uuid, client)
|
||||
_set_up_webauthn_session(fake_uuid, client_request)
|
||||
|
||||
credential_id = WebAuthnCredential(webauthn_credential).to_credential_data().credential_id
|
||||
|
||||
|
||||
Reference in New Issue
Block a user