Rename "app_" fixture to "notify_admin"

This naming was introduced in 2016 without explanation [1]. I find it
confusing because:

- It's reminiscent of "_app", which is a Python convention indicating
the variable is internal, so maybe avoid using it.

- It suggests there's some other "app" fixture I should be using (there
isn't, though).

The Python style guide describes using an underscore suffix to avoid
clashes with inbuilt names [1], which is sort of applicable if we need
to import the "app" module [2]. However, we can also avoid clashes by
choosing a different name, without the strange underscore.

[1]: 3b1d521c10
[2]: 78824f54fd/tests/app/main/views/test_forgot_password.py (L5)
This commit is contained in:
Ben Thorner
2021-05-12 14:57:21 +01:00
parent 03295eb828
commit 5bfce61bcf
30 changed files with 163 additions and 164 deletions

View File

@@ -3,8 +3,8 @@ import pytest
from app.main.forms import ServiceContactDetailsForm
def test_form_fails_validation_with_no_radio_buttons_selected(app_):
with app_.test_request_context(method='POST', data={}):
def test_form_fails_validation_with_no_radio_buttons_selected(notify_admin):
with notify_admin.test_request_context(method='POST', data={}):
form = ServiceContactDetailsForm()
assert not form.validate_on_submit()
@@ -21,14 +21,14 @@ def test_form_fails_validation_with_no_radio_buttons_selected(app_):
('email_address', 'phone_number', '0207 123 4567'),
])
def test_form_fails_validation_when_radio_button_selected_and_text_box_filled_in_do_not_match(
app_,
notify_admin,
selected_radio_button,
selected_text_box,
text_box_data
):
data = {'contact_details_type': selected_radio_button, selected_text_box: text_box_data}
with app_.test_request_context(method='POST', data=data):
with notify_admin.test_request_context(method='POST', data=data):
form = ServiceContactDetailsForm()
assert not form.validate_on_submit()
@@ -42,7 +42,7 @@ def test_form_fails_validation_when_radio_button_selected_and_text_box_filled_in
('phone_number', 'www.invalid-url.com', 'invalid-email.com', '0207 123 4567'),
])
def test_form_only_validates_the_field_which_matches_the_selected_radio_button(
app_,
notify_admin,
selected_field,
url,
email_address,
@@ -53,16 +53,16 @@ def test_form_only_validates_the_field_which_matches_the_selected_radio_button(
'email_address': email_address,
'phone_number': phone_number}
with app_.test_request_context(method='POST', data=data):
with notify_admin.test_request_context(method='POST', data=data):
form = ServiceContactDetailsForm()
assert form.validate_on_submit()
def test_form_url_validation_fails_with_invalid_url_field(app_):
def test_form_url_validation_fails_with_invalid_url_field(notify_admin):
data = {'contact_details_type': 'url', 'url': 'www.example.com'}
with app_.test_request_context(method='POST', data=data):
with notify_admin.test_request_context(method='POST', data=data):
form = ServiceContactDetailsForm()
assert not form.validate_on_submit()
@@ -70,10 +70,10 @@ def test_form_url_validation_fails_with_invalid_url_field(app_):
assert len(form.errors['url']) == 1
def test_form_email_validation_fails_with_invalid_email_address_field(app_):
def test_form_email_validation_fails_with_invalid_email_address_field(notify_admin):
data = {'contact_details_type': 'email_address', 'email_address': '1@co'}
with app_.test_request_context(method='POST', data=data):
with notify_admin.test_request_context(method='POST', data=data):
form = ServiceContactDetailsForm()
assert not form.validate_on_submit()
@@ -81,10 +81,10 @@ def test_form_email_validation_fails_with_invalid_email_address_field(app_):
assert len(form.errors['email_address']) == 2
def test_form_phone_number_validation_fails_with_invalid_phone_number_field(app_):
def test_form_phone_number_validation_fails_with_invalid_phone_number_field(notify_admin):
data = {'contact_details_type': 'phone_number', 'phone_number': '1235 A'}
with app_.test_request_context(method='POST', data=data):
with notify_admin.test_request_context(method='POST', data=data):
form = ServiceContactDetailsForm()
assert not form.validate_on_submit()