diff --git a/app/clients/document_download.py b/app/clients/document_download.py index 4c57983be..7211d716d 100644 --- a/app/clients/document_download.py +++ b/app/clients/document_download.py @@ -33,7 +33,7 @@ class DocumentDownloadClient: "document": file_contents, "is_csv": is_csv or False, }, - timeout=30 + timeout=30, ) response.raise_for_status() diff --git a/app/clients/performance_platform/performance_platform_client.py b/app/clients/performance_platform/performance_platform_client.py index 3bf83ba53..0c83f5168 100644 --- a/app/clients/performance_platform/performance_platform_client.py +++ b/app/clients/performance_platform/performance_platform_client.py @@ -29,7 +29,7 @@ class PerformancePlatformClient: self.performance_platform_url + payload["dataType"], json=payload, headers=headers, - timeout=30 + timeout=30, ) if resp.status_code == 200: diff --git a/app/cronitor.py b/app/cronitor.py index 92bf670fc..8f8ea888b 100644 --- a/app/cronitor.py +++ b/app/cronitor.py @@ -35,7 +35,7 @@ def cronitor(task_name): params={ "host": current_app.config["API_HOST_NAME"], }, - timeout=30 + timeout=30, ) resp.raise_for_status() except requests.RequestException as e: diff --git a/migrations/versions/0216_remove_colours.py b/migrations/versions/0216_remove_colours.py index 80a0def7e..4477df3a9 100644 --- a/migrations/versions/0216_remove_colours.py +++ b/migrations/versions/0216_remove_colours.py @@ -2,7 +2,7 @@ Revision ID: 0216_remove_colours Revises: 0215_email_brand_type Create Date: 2018-08-24 13:36:49.346156 - """ +""" import sqlalchemy as sa from alembic import op diff --git a/migrations/versions/0219_default_email_branding.py b/migrations/versions/0219_default_email_branding.py index b6b308dfe..c702b3b29 100644 --- a/migrations/versions/0219_default_email_branding.py +++ b/migrations/versions/0219_default_email_branding.py @@ -2,7 +2,7 @@ Revision ID: 0219_default_email_branding Revises: 0216_remove_colours Create Date: 2018-08-24 13:36:49.346156 - """ +""" from alembic import op from sqlalchemy import text diff --git a/migrations/versions/0220_email_brand_type_non_null.py b/migrations/versions/0220_email_brand_type_non_null.py index 3d7b9d239..7a0a3aff4 100644 --- a/migrations/versions/0220_email_brand_type_non_null.py +++ b/migrations/versions/0220_email_brand_type_non_null.py @@ -2,7 +2,7 @@ Revision ID: 0220_email_brand_type_non_null Revises: 0219_default_email_branding Create Date: 2018-08-24 13:36:49.346156 - """ +""" from alembic import op diff --git a/migrations/versions/0221_nullable_service_branding.py b/migrations/versions/0221_nullable_service_branding.py index 15fc5182e..ab8cb68ac 100644 --- a/migrations/versions/0221_nullable_service_branding.py +++ b/migrations/versions/0221_nullable_service_branding.py @@ -2,7 +2,7 @@ Revision ID: 0221_nullable_service_branding Revises: 0220_email_brand_type_non_null Create Date: 2018-08-24 13:36:49.346156 - """ +""" from alembic import op diff --git a/migrations/versions/0222_drop_service_branding.py b/migrations/versions/0222_drop_service_branding.py index 6197768fa..10b52cfe8 100644 --- a/migrations/versions/0222_drop_service_branding.py +++ b/migrations/versions/0222_drop_service_branding.py @@ -2,7 +2,7 @@ Revision ID: 0222_drop_service_branding Revises: 0221_nullable_service_branding Create Date: 2018-08-24 13:36:49.346156 - """ +""" import sqlalchemy as sa from alembic import op diff --git a/migrations/versions/0223_add_domain_constraint.py b/migrations/versions/0223_add_domain_constraint.py index d8ffee014..3c3afba81 100644 --- a/migrations/versions/0223_add_domain_constraint.py +++ b/migrations/versions/0223_add_domain_constraint.py @@ -2,7 +2,7 @@ Revision ID: 0223_add_domain_constraint Revises: 0222_drop_service_branding Create Date: 2018-08-24 13:36:49.346156 - """ +""" from alembic import op diff --git a/migrations/versions/0417_add_second_e2e_test_user.py b/migrations/versions/0417_add_second_e2e_test_user.py index 351ffa9de..b4f87f2d4 100644 --- a/migrations/versions/0417_add_second_e2e_test_user.py +++ b/migrations/versions/0417_add_second_e2e_test_user.py @@ -19,7 +19,9 @@ def upgrade(): email_address = os.getenv("NOTIFY_E2E_TEST_EMAIL_TWO") password = os.getenv("NOTIFY_E2E_TEST_PASSWORD_TWO") if not email_address or not password: - raise ValueError("Required variables [NOTIFY_E2E_TEST_EMAIL_TWO] and [NOTIFY_E2E_TEST_PASSWORD_TWO] missing!") + raise ValueError( + "Required variables [NOTIFY_E2E_TEST_EMAIL_TWO] and [NOTIFY_E2E_TEST_PASSWORD_TWO] missing!" + ) name = f"e2e_test_user_{uuid.uuid4()}" data = { "id": uuid.uuid4(), diff --git a/notifications_utils/formatters.py b/notifications_utils/formatters.py index a2cb7c3d7..c5bdef840 100644 --- a/notifications_utils/formatters.py +++ b/notifications_utils/formatters.py @@ -12,15 +12,15 @@ from notifications_utils.sanitise_text import SanitiseSMS from . import email_with_smart_quotes_regex OBSCURE_ZERO_WIDTH_WHITESPACE = ( - "\u180E" # Mongolian vowel separator - "\u200B" # zero width space - "\u200C" # zero width non-joiner - "\u200D" # zero width joiner + "\u180e" # Mongolian vowel separator + "\u200b" # zero width space + "\u200c" # zero width non-joiner + "\u200d" # zero width joiner "\u2060" # word joiner - "\uFEFF" # zero width non-breaking space + "\ufeff" # zero width non-breaking space ) -OBSCURE_FULL_WIDTH_WHITESPACE = "\u00A0" # non breaking space +OBSCURE_FULL_WIDTH_WHITESPACE = "\u00a0" # non breaking space ALL_WHITESPACE = ( string.whitespace + OBSCURE_ZERO_WIDTH_WHITESPACE + OBSCURE_FULL_WIDTH_WHITESPACE @@ -61,7 +61,7 @@ more_than_two_newlines_in_a_row = re.compile(r"\n{3,}") def unlink_govuk_escaped(message): return re.sub( govuk_not_a_link, - r"\1\2\3" + ".\u200B" + r"\4", # Unicode zero-width space + r"\1\2\3" + ".\u200b" + r"\4", # Unicode zero-width space message, ) diff --git a/notifications_utils/sanitise_text.py b/notifications_utils/sanitise_text.py index 750a2e49b..aec94aa6c 100644 --- a/notifications_utils/sanitise_text.py +++ b/notifications_utils/sanitise_text.py @@ -15,13 +15,13 @@ class SanitiseText: "’": "'", # RIGHT SINGLE QUOTATION MARK (U+2019) "“": '"', # LEFT DOUBLE QUOTATION MARK (U+201C) "”": '"', # RIGHT DOUBLE QUOTATION MARK (U+201D) - "\u180E": "", # Mongolian vowel separator - "\u200B": "", # zero width space - "\u200C": "", # zero width non-joiner - "\u200D": "", # zero width joiner + "\u180e": "", # Mongolian vowel separator + "\u200b": "", # zero width space + "\u200c": "", # zero width non-joiner + "\u200d": "", # zero width joiner "\u2060": "", # word joiner - "\uFEFF": "", # zero width non-breaking space - "\u00A0": " ", # NON BREAKING WHITE SPACE (U+200B) + "\ufeff": "", # zero width non-breaking space + "\u00a0": " ", # NON BREAKING WHITE SPACE (U+200B) "\t": " ", # TAB } diff --git a/tests/app/notifications/test_process_notification.py b/tests/app/notifications/test_process_notification.py index d62e8549c..c51c8e48e 100644 --- a/tests/app/notifications/test_process_notification.py +++ b/tests/app/notifications/test_process_notification.py @@ -278,7 +278,7 @@ def test_send_notification_to_queue_throws_exception_deletes_notification( with pytest.raises(Boto3Error): send_notification_to_queue(sample_notification, False) mocked.assert_called_once_with( - [(str(sample_notification.id))], queue="send-sms-tasks", countdown=60 + [str(sample_notification.id)], queue="send-sms-tasks", countdown=60 ) assert _get_notification_query_count() == 0 diff --git a/tests/app/organization/test_invite_rest.py b/tests/app/organization/test_invite_rest.py index 19ce7ccd6..37bcb5a9a 100644 --- a/tests/app/organization/test_invite_rest.py +++ b/tests/app/organization/test_invite_rest.py @@ -75,7 +75,7 @@ def test_create_invited_org_user( # assert len(notification.personalisation["url"]) > len(expected_start_of_invite_url) mocked.assert_called_once_with( - [(str(notification.id))], queue="notify-internal-tasks", countdown=60 + [str(notification.id)], queue="notify-internal-tasks", countdown=60 ) diff --git a/tests/app/service_invite/test_service_invite_rest.py b/tests/app/service_invite/test_service_invite_rest.py index c980c87a1..ebb50214e 100644 --- a/tests/app/service_invite/test_service_invite_rest.py +++ b/tests/app/service_invite/test_service_invite_rest.py @@ -92,7 +92,7 @@ def test_create_invited_user( ) mocked.assert_called_once_with( - [(str(notification.id))], queue="notify-internal-tasks", countdown=60 + [str(notification.id)], queue="notify-internal-tasks", countdown=60 ) diff --git a/tests/notifications_utils/test_field.py b/tests/notifications_utils/test_field.py index fcd50cf3a..e36fb0cb4 100644 --- a/tests/notifications_utils/test_field.py +++ b/tests/notifications_utils/test_field.py @@ -257,7 +257,7 @@ def test_what_will_trigger_conditional_placeholder(value): "list: ", ), ( - {"placeholder": [" ", " \t ", "\u180E"]}, + {"placeholder": [" ", " \t ", "\u180e"]}, "list: ", "list: ", ), diff --git a/tests/notifications_utils/test_formatters.py b/tests/notifications_utils/test_formatters.py index 61185d974..7c66d7bc0 100644 --- a/tests/notifications_utils/test_formatters.py +++ b/tests/notifications_utils/test_formatters.py @@ -66,7 +66,7 @@ def test_HTML_template_has_URLs_replaced_with_links(): def test_escaping_govuk_in_email_templates(): template_content = "GOV.UK" - expected = "GOV.\u200BUK" + expected = "GOV.\u200bUK" assert unlink_govuk_escaped(template_content) == expected template_json = { "content": template_content, @@ -81,23 +81,23 @@ def test_escaping_govuk_in_email_templates(): ("template_content", "expected"), [ # Cases that we add the breaking space - ("GOV.UK", "GOV.\u200BUK"), - ("gov.uk", "gov.\u200Buk"), + ("GOV.UK", "GOV.\u200bUK"), + ("gov.uk", "gov.\u200buk"), ( "content with space infront GOV.UK", - "content with space infront GOV.\u200BUK", + "content with space infront GOV.\u200bUK", ), - ("content with tab infront\tGOV.UK", "content with tab infront\tGOV.\u200BUK"), + ("content with tab infront\tGOV.UK", "content with tab infront\tGOV.\u200bUK"), ( "content with newline infront\nGOV.UK", - "content with newline infront\nGOV.\u200BUK", + "content with newline infront\nGOV.\u200bUK", ), - ("*GOV.UK", "*GOV.\u200BUK"), - ("#GOV.UK", "#GOV.\u200BUK"), - ("^GOV.UK", "^GOV.\u200BUK"), - (" #GOV.UK", " #GOV.\u200BUK"), - ("GOV.UK with CONTENT after", "GOV.\u200BUK with CONTENT after"), - ("#GOV.UK with CONTENT after", "#GOV.\u200BUK with CONTENT after"), + ("*GOV.UK", "*GOV.\u200bUK"), + ("#GOV.UK", "#GOV.\u200bUK"), + ("^GOV.UK", "^GOV.\u200bUK"), + (" #GOV.UK", " #GOV.\u200bUK"), + ("GOV.UK with CONTENT after", "GOV.\u200bUK with CONTENT after"), + ("#GOV.UK with CONTENT after", "#GOV.\u200bUK with CONTENT after"), # Cases that we don't add the breaking space ("https://gov.uk", "https://gov.uk"), ("https://www.gov.uk", "https://www.gov.uk"), @@ -366,7 +366,7 @@ def test_unicode_dash_lookup(): """ \t bar """, - " \u180E\u200B \u200C bar \u200D \u2060\uFEFF ", + " \u180e\u200b \u200c bar \u200d \u2060\ufeff ", ], ) def test_strip_all_whitespace(value): @@ -378,7 +378,7 @@ def test_strip_all_whitespace(value): [ "notifications-email", " \tnotifications-email \x0c ", - "\rn\u200Coti\u200Dfi\u200Bcati\u2060ons-\u180Eemai\uFEFFl\uFEFF", + "\rn\u200coti\u200dfi\u200bcati\u2060ons-\u180eemai\ufeffl\ufeff", ], ) def test_strip_and_remove_obscure_whitespace(value): @@ -421,12 +421,12 @@ def test_strip_unsupported_characters(): @pytest.mark.parametrize( "value", [ - "\u200C Your tax is\ndue\n\n", + "\u200c Your tax is\ndue\n\n", " Your tax is due ", # Non breaking spaces replaced by single spaces - "\u00A0Your\u00A0tax\u00A0 is\u00A0\u00A0due\u00A0", + "\u00a0Your\u00a0tax\u00a0 is\u00a0\u00a0due\u00a0", # zero width spaces are removed - "\u180EYour \u200Btax\u200C is \u200D\u2060due \uFEFF", + "\u180eYour \u200btax\u200c is \u200d\u2060due \ufeff", # tabs are replaced by single spaces "\tYour tax\tis due ", ], diff --git a/tests/notifications_utils/test_postal_address.py b/tests/notifications_utils/test_postal_address.py index 3e29f193f..54f47bb54 100644 --- a/tests/notifications_utils/test_postal_address.py +++ b/tests/notifications_utils/test_postal_address.py @@ -559,7 +559,7 @@ def test_normalise_postcode(postcode, normalised_postcode): ("N5 1AA", True), ("SO14 6WB", True), ("so14 6wb", True), - ("so14\u00A06wb", True), + ("so14\u00a06wb", True), # invalida / incomplete postcodes ("N5", False), ("SO144 6WB", False), @@ -600,7 +600,7 @@ def test_if_postcode_is_a_real_uk_postcode_normalises_before_checking_postcode(m ("N5 3EF", "N5 3EF"), ("N53EF ", "N5 3EF"), ("n53Ef", "N5 3EF"), - ("n5 \u00A0 \t 3Ef", "N5 3EF"), + ("n5 \u00a0 \t 3Ef", "N5 3EF"), ("SO146WB", "SO14 6WB"), ("BFPO2", "BFPO 2"), ("BFPO232", "BFPO 232"), diff --git a/tests/notifications_utils/test_recipient_csv.py b/tests/notifications_utils/test_recipient_csv.py index ba93ec1aa..eabc636df 100644 --- a/tests/notifications_utils/test_recipient_csv.py +++ b/tests/notifications_utils/test_recipient_csv.py @@ -877,14 +877,14 @@ def test_ignores_spaces_and_case_in_placeholders(key, expected): ("\n", None), # newline ("\r", None), # carriage return ("\t", None), # tab - ("\u180E", "MONGOLIAN VOWEL SEPARATOR"), - ("\u200B", "ZERO WIDTH SPACE"), - ("\u200C", "ZERO WIDTH NON-JOINER"), - ("\u200D", "ZERO WIDTH JOINER"), + ("\u180e", "MONGOLIAN VOWEL SEPARATOR"), + ("\u200b", "ZERO WIDTH SPACE"), + ("\u200c", "ZERO WIDTH NON-JOINER"), + ("\u200d", "ZERO WIDTH JOINER"), ("\u2060", "WORD JOINER"), - ("\uFEFF", "ZERO WIDTH NO-BREAK SPACE"), + ("\ufeff", "ZERO WIDTH NO-BREAK SPACE"), # all the things - (" \n\r\t\u000A\u000D\u180E\u200B\u200C\u200D\u2060\uFEFF", None), + (" \n\r\t\u000a\u000d\u180e\u200b\u200c\u200d\u2060\ufeff", None), ], ) def test_ignores_leading_whitespace_in_file(character, name): diff --git a/tests/notifications_utils/test_recipient_validation.py b/tests/notifications_utils/test_recipient_validation.py index cc6c2a676..e56964325 100644 --- a/tests/notifications_utils/test_recipient_validation.py +++ b/tests/notifications_utils/test_recipient_validation.py @@ -344,7 +344,7 @@ def test_validate_email_address_accepts_valid(email_address): " email@domain.com ", "\temail@domain.com", "\temail@domain.com\n", - "\u200Bemail@domain.com\u200B", + "\u200bemail@domain.com\u200b", ], ) def test_validate_email_address_strips_whitespace(email): diff --git a/tests/notifications_utils/test_sanitise_text.py b/tests/notifications_utils/test_sanitise_text.py index e8bdf04dd..3dc14298a 100644 --- a/tests/notifications_utils/test_sanitise_text.py +++ b/tests/notifications_utils/test_sanitise_text.py @@ -17,7 +17,7 @@ params, ids = zip( ("…", "..."), "compatibility transform unicode char (HORIZONTAL ELLIPSIS (U+2026)", ), - (("\u200B", ""), "compatibility transform unicode char (ZERO WIDTH SPACE (U+200B)"), + (("\u200b", ""), "compatibility transform unicode char (ZERO WIDTH SPACE (U+200B)"), ( ("‘", "'"), "compatibility transform unicode char (LEFT SINGLE QUOTATION MARK (U+2018)",