Normalize whitespace in test arguments

We have a bunch of different styles of handling when function
definitions span multiple lines, which they almost always do with tests.

Here’s why an argument per line, single indent is best:
- cleaner diffs when you change the name of a method (one line change
  instead of multiple lines)
- works better on narrow screens, eg Github’s diff view, or with two
  terminals side by side on a laptop screen
- works with any editor’s indenting shortcuts, no need for an IDE

Also, trailing comma in the list of arguments is good because adding a
new argument to a method becomes a one line, not two line diff.
This commit is contained in:
Chris Hill-Scott
2017-02-03 10:42:01 +00:00
parent b9d88cccc3
commit 929dc45224
28 changed files with 1547 additions and 1103 deletions

View File

@@ -4,9 +4,11 @@ from tests.conftest import SERVICE_ONE_ID
from unittest.mock import ANY
def test_should_render_two_factor_page(app_,
api_user_active,
mock_get_user_by_email):
def test_should_render_two_factor_page(
app_,
api_user_active,
mock_get_user_by_email,
):
with app_.test_request_context():
with app_.test_client() as client:
# TODO this lives here until we work out how to
@@ -20,13 +22,15 @@ def test_should_render_two_factor_page(app_,
assert '''Weve sent you a text message with a security code.''' in response.get_data(as_text=True)
def test_should_login_user_and_redirect_to_service_dashboard(app_,
api_user_active,
mock_get_user,
mock_get_user_by_email,
mock_check_verify_code,
mock_get_services_with_one_service,
mock_events):
def test_should_login_user_and_redirect_to_service_dashboard(
app_,
api_user_active,
mock_get_user,
mock_get_user_by_email,
mock_check_verify_code,
mock_get_services_with_one_service,
mock_events,
):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
@@ -45,12 +49,14 @@ def test_should_login_user_and_redirect_to_service_dashboard(app_,
mock_events.assert_called_with('sucessful_login', ANY)
def test_should_login_user_and_should_redirect_to_next_url(app_,
api_user_active,
mock_get_user,
mock_get_user_by_email,
mock_check_verify_code,
mock_get_services):
def test_should_login_user_and_should_redirect_to_next_url(
app_,
api_user_active,
mock_get_user,
mock_get_user_by_email,
mock_check_verify_code,
mock_get_services,
):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
@@ -67,12 +73,14 @@ def test_should_login_user_and_should_redirect_to_next_url(app_,
)
def test_should_login_user_and_not_redirect_to_external_url(app_,
api_user_active,
mock_get_user,
mock_get_user_by_email,
mock_check_verify_code,
mock_get_services_with_one_service):
def test_should_login_user_and_not_redirect_to_external_url(
app_,
api_user_active,
mock_get_user,
mock_get_user_by_email,
mock_check_verify_code,
mock_get_services_with_one_service,
):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
@@ -89,12 +97,14 @@ def test_should_login_user_and_not_redirect_to_external_url(app_,
)
def test_should_login_user_and_redirect_to_choose_services(app_,
api_user_active,
mock_get_user,
mock_get_user_by_email,
mock_check_verify_code,
mock_get_services):
def test_should_login_user_and_redirect_to_choose_services(
app_,
api_user_active,
mock_get_user,
mock_get_user_by_email,
mock_check_verify_code,
mock_get_services,
):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
@@ -108,10 +118,12 @@ def test_should_login_user_and_redirect_to_choose_services(app_,
assert response.location == url_for('main.choose_service', _external=True)
def test_should_return_200_with_sms_code_error_when_sms_code_is_wrong(app_,
api_user_active,
mock_get_user_by_email,
mock_check_verify_code_code_not_found):
def test_should_return_200_with_sms_code_error_when_sms_code_is_wrong(
app_,
api_user_active,
mock_get_user_by_email,
mock_check_verify_code_code_not_found,
):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
@@ -124,12 +136,14 @@ def test_should_return_200_with_sms_code_error_when_sms_code_is_wrong(app_,
assert 'Code not found' in response.get_data(as_text=True)
def test_should_login_user_when_multiple_valid_codes_exist(app_,
api_user_active,
mock_get_user,
mock_get_user_by_email,
mock_check_verify_code,
mock_get_services_with_one_service):
def test_should_login_user_when_multiple_valid_codes_exist(
app_,
api_user_active,
mock_get_user,
mock_get_user_by_email,
mock_check_verify_code,
mock_get_services_with_one_service,
):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
@@ -141,12 +155,14 @@ def test_should_login_user_when_multiple_valid_codes_exist(app_,
assert response.status_code == 302
def test_remember_me_set(app_,
api_user_active,
mock_get_user,
mock_get_user_by_email,
mock_check_verify_code,
mock_get_services_with_one_service):
def test_remember_me_set(
app_,
api_user_active,
mock_get_user,
mock_get_user_by_email,
mock_check_verify_code,
mock_get_services_with_one_service,
):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
@@ -158,12 +174,14 @@ def test_remember_me_set(app_,
assert response.status_code == 302
def test_two_factor_should_set_password_when_new_password_exists_in_session(app_,
api_user_active,
mock_get_user,
mock_check_verify_code,
mock_get_services_with_one_service,
mock_update_user):
def test_two_factor_should_set_password_when_new_password_exists_in_session(
app_,
api_user_active,
mock_get_user,
mock_check_verify_code,
mock_get_services_with_one_service,
mock_update_user,
):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
@@ -184,12 +202,14 @@ def test_two_factor_should_set_password_when_new_password_exists_in_session(app_
mock_update_user.assert_called_once_with(api_user_active)
def test_two_factor_reset_login_count_called(app_,
api_user_locked,
mock_get_locked_user,
mock_update_user,
mock_check_verify_code,
mock_get_services_with_one_service):
def test_two_factor_reset_login_count_called(
app_,
api_user_locked,
mock_get_locked_user,
mock_update_user,
mock_check_verify_code,
mock_get_services_with_one_service,
):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
@@ -212,9 +232,11 @@ def test_two_factor_reset_login_count_called(app_,
mock_update_user.assert_called_with(api_user_locked)
def test_two_factor_should_redirect_to_sign_in_if_user_not_in_session(app_,
api_user_active,
mock_get_user):
def test_two_factor_should_redirect_to_sign_in_if_user_not_in_session(
app_,
api_user_active,
mock_get_user,
):
with app_.test_request_context():
with app_.test_client() as client:
@@ -224,12 +246,13 @@ def test_two_factor_should_redirect_to_sign_in_if_user_not_in_session(app_,
assert response.location == url_for('main.sign_in', _external=True)
def test_two_factor_should_activate_pending_user(app_,
mocker,
api_user_pending,
mock_check_verify_code,
mock_update_user
):
def test_two_factor_should_activate_pending_user(
app_,
mocker,
api_user_pending,
mock_check_verify_code,
mock_update_user,
):
mocker.patch('app.user_api_client.get_user', return_value=api_user_pending)
mocker.patch('app.service_api_client.get_services', return_value={'data': []})
with app_.test_request_context():