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

@@ -28,10 +28,10 @@ from tests.conftest import (
service_json(active=True),
None
], ids=['active_service', 'no_service'])
def test_active_service_can_be_modified(app_, method, user, service):
def test_active_service_can_be_modified(notify_admin, method, user, service):
api_client = NotifyAdminAPIClient()
with app_.test_request_context() as request_context, app_.test_client() as client:
with notify_admin.test_request_context() as request_context, notify_admin.test_client() as client:
client.login(user)
request_context.service = Service(service)
@@ -47,10 +47,10 @@ def test_active_service_can_be_modified(app_, method, user, service):
'post',
'delete'
])
def test_inactive_service_cannot_be_modified_by_normal_user(app_, api_user_active, method):
def test_inactive_service_cannot_be_modified_by_normal_user(notify_admin, api_user_active, method):
api_client = NotifyAdminAPIClient()
with app_.test_request_context() as request_context, app_.test_client() as client:
with notify_admin.test_request_context() as request_context, notify_admin.test_client() as client:
client.login(api_user_active)
request_context.service = Service(service_json(active=False))
@@ -66,10 +66,10 @@ def test_inactive_service_cannot_be_modified_by_normal_user(app_, api_user_activ
'post',
'delete'
])
def test_inactive_service_can_be_modified_by_platform_admin(app_, platform_admin_user, method):
def test_inactive_service_can_be_modified_by_platform_admin(notify_admin, platform_admin_user, method):
api_client = NotifyAdminAPIClient()
with app_.test_request_context() as request_context, app_.test_client() as client:
with notify_admin.test_request_context() as request_context, notify_admin.test_client() as client:
client.login(platform_admin_user)
request_context.service = Service(service_json(active=False))
@@ -80,10 +80,10 @@ def test_inactive_service_can_be_modified_by_platform_admin(app_, platform_admin
assert ret == request.return_value
def test_generate_headers_sets_standard_headers(app_):
def test_generate_headers_sets_standard_headers(notify_admin):
api_client = NotifyAdminAPIClient()
with set_config(app_, 'ROUTE_SECRET_KEY_1', 'proxy-secret'):
api_client.init_app(app_)
with set_config(notify_admin, 'ROUTE_SECRET_KEY_1', 'proxy-secret'):
api_client.init_app(notify_admin)
# with patch('app.notify_client.has_request_context', return_value=False):
headers = api_client.generate_headers('api_token')
@@ -95,11 +95,11 @@ def test_generate_headers_sets_standard_headers(app_):
assert headers['X-Custom-Forwarder'] == 'proxy-secret'
def test_generate_headers_sets_request_id_if_in_request_context(app_):
def test_generate_headers_sets_request_id_if_in_request_context(notify_admin):
api_client = NotifyAdminAPIClient()
api_client.init_app(app_)
api_client.init_app(notify_admin)
with app_.test_request_context() as request_context:
with notify_admin.test_request_context() as request_context:
headers = api_client.generate_headers('api_token')
assert set(headers.keys()) == {