diff --git a/app/__init__.py b/app/__init__.py index 4e6e8f21f..958a324f8 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -500,11 +500,9 @@ def setup_blueprints(application): updated, including the expiration date. If you have a dashboard open and in focus it'll refresh the expiration timer every two seconds, and you will never log out, which is behaviour we want to preserve. """ + from app.main import main as main_blueprint + from app.main import no_cookie as no_cookie_blueprint from app.status import status as status_blueprint - from app.main import ( - main as main_blueprint, - no_cookie as no_cookie_blueprint - ) main_blueprint.before_request(make_session_permanent) main_blueprint.after_request(save_service_or_org_after_request) @@ -517,6 +515,7 @@ def setup_blueprints(application): def setup_event_handlers(): from flask_login import user_logged_in + from app.event_handlers import on_user_logged_in user_logged_in.connect(on_user_logged_in) diff --git a/app/broadcast_areas/create-broadcast-areas-db.py b/app/broadcast_areas/create-broadcast-areas-db.py index 62366993d..f613895dd 100755 --- a/app/broadcast_areas/create-broadcast-areas-db.py +++ b/app/broadcast_areas/create-broadcast-areas-db.py @@ -7,7 +7,6 @@ from pathlib import Path import geojson from notifications_utils.formatters import formatted_list from notifications_utils.polygons import Polygons - from populations import ( BRYHER, CITY_OF_LONDON, @@ -68,7 +67,7 @@ def estimate_number_of_smartphones_in_area(country_or_ward_code): # We don’t have population figures for wards of the City of # London. We’ll leave it empty here and estimate on the fly # later based on physical area. - print(f' Population: N/A') # noqa: T001 + print(' Population: N/A') # noqa: T001 return None # For some reason Bryher is the only ward missing population data, so we diff --git a/app/main/forms.py b/app/main/forms.py index 8f12595aa..d453e0551 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -1354,14 +1354,14 @@ class LetterAddressForm(StripWhitespaceForm): if not address.has_valid_last_line: if self.allow_international_letters: raise ValidationError( - f'Last line of the address must be a UK postcode or another country' + 'Last line of the address must be a UK postcode or another country' ) if address.international: raise ValidationError( - f'You do not have permission to send letters to other countries' + 'You do not have permission to send letters to other countries' ) raise ValidationError( - f'Last line of the address must be a real UK postcode' + 'Last line of the address must be a real UK postcode' ) if address.has_invalid_characters: diff --git a/app/main/views/two_factor.py b/app/main/views/two_factor.py index 52f106dc4..8bbbe0ba1 100644 --- a/app/main/views/two_factor.py +++ b/app/main/views/two_factor.py @@ -91,7 +91,7 @@ def revalidate_email_sent(): # see http://flask.pocoo.org/snippets/62/ def _is_safe_redirect_url(target): - from urllib.parse import urlparse, urljoin + from urllib.parse import urljoin, urlparse host_url = urlparse(request.host_url) redirect_url = urlparse(urljoin(request.host_url, target)) return redirect_url.scheme in ('http', 'https') and \ diff --git a/app/notify_client/organisations_api_client.py b/app/notify_client/organisations_api_client.py index b94b45139..64ba5f8b7 100644 --- a/app/notify_client/organisations_api_client.py +++ b/app/notify_client/organisations_api_client.py @@ -78,9 +78,7 @@ class OrganisationsClient(NotifyAdminAPIClient): return self.get(url="/organisations/{}/services".format(org_id)) def remove_user_from_organisation(self, org_id, user_id): - endpoint = '/organisations/{}/users/{}'.format( - org_id=org_id, - user_id=user_id) + endpoint = '/organisations/{}/users/{}'.format(org_id, user_id) data = _attach_current_user({}) return self.delete(endpoint, data) diff --git a/application.py b/application.py index b2d4889be..1393b882f 100644 --- a/application.py +++ b/application.py @@ -1,4 +1,5 @@ from flask import Flask + from app import create_app application = Flask('app') diff --git a/get_zendesk_tickets.py b/get_zendesk_tickets.py index f6182eb57..708ef19d4 100644 --- a/get_zendesk_tickets.py +++ b/get_zendesk_tickets.py @@ -4,10 +4,11 @@ This can be run locally if you set the ZENDESK_API_KEY. Or the script can be run """ # flake8: noqa: T001 (print) -import os -import requests -import urllib.parse import csv +import os +import urllib.parse + +import requests # Group: 3rd Line--Notify Support NOTIFY_GROUP_ID = 360000036529 diff --git a/gunicorn_config.py b/gunicorn_config.py index 6f870d672..bd3d48eab 100644 --- a/gunicorn_config.py +++ b/gunicorn_config.py @@ -3,7 +3,6 @@ import sys import traceback import gunicorn - from gds_metrics.gunicorn import child_exit # noqa workers = 5 diff --git a/scripts/run_tests.sh b/scripts/run_tests.sh index dc3d949ee..0b1096e6b 100755 --- a/scripts/run_tests.sh +++ b/scripts/run_tests.sh @@ -27,7 +27,7 @@ fi flake8 . display_result $? 1 "Code style check" -isort --check-only -rc ./app ./tests +isort --check-only ./app ./tests display_result $? 2 "Import order check" npm test diff --git a/tests/app/main/views/organisations/test_organisation_invites.py b/tests/app/main/views/organisations/test_organisation_invites.py index 9a80301aa..7ac2eebb0 100644 --- a/tests/app/main/views/organisations/test_organisation_invites.py +++ b/tests/app/main/views/organisations/test_organisation_invites.py @@ -326,7 +326,7 @@ def test_org_user_registration( assert response.status_code == 302 assert response.location == url_for('main.verify', _external=True) - mock_get_user_by_email.called is False + assert mock_get_user_by_email.called is False mock_register_user.assert_called_once_with( 'Test User', session['invited_org_user']['email_address'], diff --git a/tests/app/main/views/test_manage_users.py b/tests/app/main/views/test_manage_users.py index f5ae9b2e8..f54473809 100644 --- a/tests/app/main/views/test_manage_users.py +++ b/tests/app/main/views/test_manage_users.py @@ -1648,7 +1648,7 @@ def test_edit_user_email_cannot_change_a_gov_email_address_to_a_non_gov_email_ad ) assert 'Enter a public sector email address' in page.select_one('.govuk-error-message').text with client_request.session_transaction() as session: - assert 'team_member_email_change-'.format(active_user_with_permissions['id']) not in session + assert 'team_member_email_change-{}'.format(active_user_with_permissions['id']) not in session def test_confirm_edit_user_email_page( diff --git a/tests/app/main/views/test_register.py b/tests/app/main/views/test_register.py index 576c4257e..2e55b24c3 100644 --- a/tests/app/main/views/test_register.py +++ b/tests/app/main/views/test_register.py @@ -161,7 +161,7 @@ def test_should_return_200_if_password_is_on_list_of_commonly_used_passwords( 'mobile_number': '+44123412345', 'password': 'password'}) - response.status_code == 200 + assert response.status_code == 200 assert 'Choose a password that’s harder to guess' in response.get_data(as_text=True) diff --git a/tests/app/main/views/test_send.py b/tests/app/main/views/test_send.py index 06a7c8c56..302896ffd 100644 --- a/tests/app/main/views/test_send.py +++ b/tests/app/main/views/test_send.py @@ -3807,7 +3807,7 @@ def test_check_notification_shows_back_link( name="Awkward letter", type_="letter", subject="We need to talk about ((thing))", - content=f"Hello ((address line 3))", + content="Hello ((address line 3))", )}, ) with client_request.session_transaction() as session: diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index 9e58fd35a..49bd9f282 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -1116,7 +1116,7 @@ def test_should_not_show_go_live_button_if_checklist_not_complete( assert normalize_spaces(page.select('main p')[1].text) == ( 'By requesting to go live you’re agreeing to our terms of use.' ) - page.select_one('[type=submit]').text.strip() == ('Request to go live') + assert page.select_one('main [type=submit]').text.strip() == ('Request to go live') else: assert not page.select('form') assert not page.select('main [type=submit]') @@ -1755,7 +1755,6 @@ def test_should_redirect_after_request_to_go_live( 'Request sent by test@user.gov.uk\n' ).format( service_id=SERVICE_ONE_ID, - displayed_volumes=displayed_volumes, formatted_displayed_volumes=formatted_displayed_volumes, ) @@ -4615,13 +4614,15 @@ def test_update_service_organisation_does_not_update_if_same_value( mock_get_organisations, mock_update_service_organisation, ): + org_id = "7aa5d4e9-4385-4488-a489-07812ba13383" + service_one['organisation'] = org_id response = platform_admin_client.post( url_for('.link_service_to_organisation', service_id=service_one['id']), - data={'organisations': '7aa5d4e9-4385-4488-a489-07812ba13383'}, + data={'organisations': org_id}, ) assert response.status_code == 302 - mock_update_service_organisation.called is False + assert mock_update_service_organisation.called is False @pytest.mark.parametrize('branding_type', ['email', 'letter']) @@ -5174,7 +5175,6 @@ def test_service_settings_links_to_branding_request_page_for_letters( single_sms_sender, mock_get_service_settings_page_common, ): - service_one["restricted"] is False service_one['permissions'].append('letter') page = client_request.get( '.service_settings', service_id=SERVICE_ONE_ID diff --git a/tests/app/main/views/test_templates.py b/tests/app/main/views/test_templates.py index fbcb227ae..f048365a2 100644 --- a/tests/app/main/views/test_templates.py +++ b/tests/app/main/views/test_templates.py @@ -1728,7 +1728,7 @@ def test_should_403_when_edit_template_with_process_type_of_priority_for_non_pla service_id=service_one['id'], template_id=template_id), data=data) assert response.status_code == 403 - mock_update_service_template.called == 0 + assert mock_update_service_template.called is False def test_should_403_when_create_template_with_process_type_of_priority_for_non_platform_admin( @@ -1757,7 +1757,7 @@ def test_should_403_when_create_template_with_process_type_of_priority_for_non_p service_id=service_one['id'], template_type='sms'), data=data) assert response.status_code == 403 - mock_update_service_template.called == 0 + assert mock_update_service_template.called is False @pytest.mark.parametrize('old_content, new_content, expected_paragraphs', [ diff --git a/tests/app/main/views/test_tour.py b/tests/app/main/views/test_tour.py index 58a136598..20aa01f08 100644 --- a/tests/app/main/views/test_tour.py +++ b/tests/app/main/views/test_tour.py @@ -180,7 +180,7 @@ def test_should_prefill_answers_for_get_tour_step( step_index=1 ) - page.select('.govuk-input')[0]['value'] == 'hello' + assert page.select('.govuk-input')[0]['value'] == 'hello' @pytest.mark.parametrize('template_type', ['email', 'letter', 'broadcast']) @@ -448,7 +448,9 @@ def test_post_final_tour_step_saves_data_and_redirects_to_check_notification( ) with client_request.session_transaction() as session: - session['placeholders'] == {'one': 'hello', 'two': 'hi', 'three': 'howdy', 'phone number': '07700 900762'} + assert session['placeholders'] == { + 'one': 'hello', 'two': 'hi', 'three': 'howdy', 'phone number': '07700 900762' + } def test_get_test_step_out_of_index_redirects_to_first_step( diff --git a/tests/app/main/views/test_two_factor.py b/tests/app/main/views/test_two_factor.py index 64204a870..8b38c4d8d 100644 --- a/tests/app/main/views/test_two_factor.py +++ b/tests/app/main/views/test_two_factor.py @@ -326,7 +326,7 @@ def test_valid_two_factor_email_link_shows_interstitial( assert 'action' not in form assert form['method'] == 'post' assert form['id'] == expected_form_id - assert page.select_one('main script').text.strip() == ( + assert page.select_one('main script').string.strip() == ( f'document.getElementById("{expected_form_id}").submit();' ) diff --git a/tests/app/models/test_base_model.py b/tests/app/models/test_base_model.py index 5ccabc850..46ea027b3 100644 --- a/tests/app/models/test_base_model.py +++ b/tests/app/models/test_base_model.py @@ -64,6 +64,7 @@ def test_model_doesnt_swallow_attribute_errors(json_response): class Custom(JSONModel): ALLOWED_PROPERTIES = set() + @property def foo(self): raise AttributeError('Something has gone wrong')