diff --git a/tests/notifications_utils/test_countries.py b/tests/notifications_utils/test_countries.py index 473b2731b..f7d2f8f13 100644 --- a/tests/notifications_utils/test_countries.py +++ b/tests/notifications_utils/test_countries.py @@ -74,8 +74,8 @@ def test_crowdsourced_test_data(): @pytest.mark.parametrize( - "search, expected", - ( + ("search", "expected"), + [ ("u.s.a", "United States"), ("america", "United States"), ("United States America", "United States"), @@ -120,7 +120,7 @@ def test_crowdsourced_test_data(): ("Illes Balears", "Balearic Islands"), ("Corsica", "Corsica"), ("Corse", "Corsica"), - ), + ], ) def test_hand_crafted_synonyms(search, expected): assert Country(search).canonical_name == expected @@ -135,11 +135,11 @@ def test_auto_checking_for_country_starting_with_the(): @pytest.mark.parametrize( - "search, expected_error_message", - ( + ("search", "expected_error_message"), + [ ("Qumran", "Not a known country or territory (Qumran)"), ("Kumrahn", "Not a known country or territory (Kumrahn)"), - ), + ], ) def test_non_existant_countries(search, expected_error_message): with pytest.raises(KeyError) as error: @@ -149,8 +149,8 @@ def test_non_existant_countries(search, expected_error_message): @pytest.mark.parametrize( - "search, expected", - ( + ("search", "expected"), + [ ("u.s.a", "rest-of-world"), ("Rep of Ireland", "europe"), ("deutschland", "europe"), @@ -159,7 +159,7 @@ def test_non_existant_countries(search, expected_error_message): ("Guernsey", "united-kingdom"), ("isle-of-man", "united-kingdom"), ("ESPAÑA", "europe"), - ), + ], ) def test_get_postage(search, expected): assert Country(search).postage_zone == expected diff --git a/tests/notifications_utils/test_formatters.py b/tests/notifications_utils/test_formatters.py index c1acac5dc..097c15266 100644 --- a/tests/notifications_utils/test_formatters.py +++ b/tests/notifications_utils/test_formatters.py @@ -25,7 +25,7 @@ from notifications_utils.template import ( @pytest.mark.parametrize( - "url, expected_html", + ("url", "expected_html"), [ ( """https://example.com/"onclick="alert('hi')""", @@ -78,7 +78,7 @@ def test_escaping_govuk_in_email_templates(): @pytest.mark.parametrize( - "template_content,expected", + ("template_content", "expected"), [ # Cases that we add the breaking space ("GOV.UK", "GOV.\u200BUK"), @@ -136,7 +136,7 @@ def test_unlink_govuk_escaped(template_content, expected): @pytest.mark.parametrize( - "prefix, body, expected", + ("prefix", "body", "expected"), [ ("a", "b", "a: b"), (None, "b", "b"), @@ -173,7 +173,7 @@ def test_sms_encode(mocker): @pytest.mark.parametrize( - "items, kwargs, expected_output", + ("items", "kwargs", "expected_output"), [ ([1], {}, "‘1’"), ([1, 2], {}, "‘1’ and ‘2’"), @@ -205,8 +205,8 @@ def test_bleach_doesnt_try_to_make_valid_html_before_cleaning(): @pytest.mark.parametrize( - "content, expected_escaped", - ( + ("content", "expected_escaped"), + [ ("&?a;", "&?a;"), ("&>a;", "&>a;"), ("&*a;", "&*a;"), @@ -234,7 +234,7 @@ def test_bleach_doesnt_try_to_make_valid_html_before_cleaning(): # We let users use ( and ) because otherwise it’s # impossible to put brackets in the body of conditional placeholders ("((var??(in brackets)))", "((var??(in brackets)))"), - ), + ], ) def test_escaping_html_entities( content, @@ -244,7 +244,7 @@ def test_escaping_html_entities( @pytest.mark.parametrize( - "dirty, clean", + ("dirty", "clean"), [ ( "Hello ((name)) ,\n\nThis is a message", @@ -262,7 +262,7 @@ def test_removing_whitespace_before_commas(dirty, clean): @pytest.mark.parametrize( - "dirty, clean", + ("dirty", "clean"), [ ( "Hello ((name)) .\n\nThis is a message", @@ -280,7 +280,7 @@ def test_removing_whitespace_before_full_stops(dirty, clean): @pytest.mark.parametrize( - "dumb, smart", + ("dumb", "smart"), [ ( """And I said, "what about breakfast at Tiffany's"?""", @@ -301,7 +301,7 @@ def test_smart_quotes(dumb, smart): @pytest.mark.parametrize( - "nasty, nice", + ("nasty", "nice"), [ ( ( @@ -436,8 +436,8 @@ def test_normalise_whitespace(value): @pytest.mark.parametrize( - "content, expected_html", - ( + ("content", "expected_html"), + [ ( "http://example.com", 'http://example.com', @@ -545,15 +545,15 @@ def test_normalise_whitespace(value): "with-subdomain@test.example.com", "with-subdomain@test.example.com", ), - ), + ], ) def test_autolink_urls_matches_correctly(content, expected_html): assert autolink_urls(content) == expected_html @pytest.mark.parametrize( - "extra_kwargs, expected_html", - ( + ("extra_kwargs", "expected_html"), + [ ( {}, 'http://example.com', @@ -564,7 +564,7 @@ def test_autolink_urls_matches_correctly(content, expected_html): }, 'http://example.com', ), - ), + ], ) def test_autolink_urls_applies_correct_attributes(extra_kwargs, expected_html): assert autolink_urls("http://example.com", **extra_kwargs) == expected_html diff --git a/tests/notifications_utils/test_markdown.py b/tests/notifications_utils/test_markdown.py index 550f56b58..42c2f6b01 100644 --- a/tests/notifications_utils/test_markdown.py +++ b/tests/notifications_utils/test_markdown.py @@ -33,7 +33,7 @@ def test_makes_links_out_of_URLs(url): @pytest.mark.parametrize( - "input, output", + ("input", "output"), [ ( ("this is some text with a link http://example.com in the middle"), @@ -93,7 +93,7 @@ def test_handles_placeholders_in_urls(): @pytest.mark.parametrize( - "url, expected_html, expected_html_in_template", + ("url", "expected_html", "expected_html_in_template"), [ ( """https://example.com"onclick="alert('hi')""", @@ -125,7 +125,7 @@ def test_URLs_get_escaped(url, expected_html, expected_html_in_template): @pytest.mark.parametrize( - "markdown_function, expected_output", + ("markdown_function", "expected_output"), [ ( notify_email_markdown, @@ -154,22 +154,22 @@ def test_preserves_whitespace_when_making_links(markdown_function, expected_outp @pytest.mark.parametrize( - "markdown_function, expected", - ( - [notify_letter_preview_markdown, 'print("hello")'], - [notify_email_markdown, 'print("hello")'], - [notify_plain_text_email_markdown, 'print("hello")'], - ), + ("markdown_function", "expected"), + [ + (notify_letter_preview_markdown, 'print("hello")'), + (notify_email_markdown, 'print("hello")'), + (notify_plain_text_email_markdown, 'print("hello")'), + ], ) def test_block_code(markdown_function, expected): assert markdown_function('```\nprint("hello")\n```') == expected @pytest.mark.parametrize( - "markdown_function, expected", - ( - [notify_letter_preview_markdown, ("

inset text

")], - [ + ("markdown_function", "expected"), + [ + (notify_letter_preview_markdown, ("

inset text

")), + ( notify_email_markdown, ( "
inset text

' "
" ), - ], - [ + ), + ( notify_plain_text_email_markdown, ("\n" "\ninset text"), - ], - ), + ), + ], ) def test_block_quote(markdown_function, expected): assert markdown_function("^ inset text") == expected @@ -192,16 +192,16 @@ def test_block_quote(markdown_function, expected): @pytest.mark.parametrize( "heading", - ( + [ "# heading", "#heading", - ), + ], ) @pytest.mark.parametrize( - "markdown_function, expected", - ( - [notify_letter_preview_markdown, "

heading

\n"], - [ + ("markdown_function", "expected"), + [ + (notify_letter_preview_markdown, "

heading

\n"), + ( notify_email_markdown, ( '

" ), - ], - [ + ), + ( notify_plain_text_email_markdown, ( "\n" @@ -218,47 +218,47 @@ def test_block_quote(markdown_function, expected): "\nheading" "\n-----------------------------------------------------------------" ), - ], - ), + ), + ], ) def test_level_1_header(markdown_function, heading, expected): assert markdown_function(heading) == expected @pytest.mark.parametrize( - "markdown_function, expected", - ( - [notify_letter_preview_markdown, "

inset text

"], - [ + ("markdown_function", "expected"), + [ + (notify_letter_preview_markdown, "

inset text

"), + ( notify_email_markdown, '

inset text

', - ], - [ + ), + ( notify_plain_text_email_markdown, ("\n" "\ninset text"), - ], - ), + ), + ], ) def test_level_2_header(markdown_function, expected): assert markdown_function("## inset text") == (expected) @pytest.mark.parametrize( - "markdown_function, expected", - ( - [ + ("markdown_function", "expected"), + [ + ( notify_letter_preview_markdown, ("

a

" '
 
' "

b

"), - ], - [ + ), + ( notify_email_markdown, ( '

a

' '
' '

b

' ), - ], - [ + ), + ( notify_plain_text_email_markdown, ( "\n" @@ -268,8 +268,8 @@ def test_level_2_header(markdown_function, expected): "\n" "\nb" ), - ], - ), + ), + ], ) def test_hrule(markdown_function, expected): assert markdown_function("a\n\n***\n\nb") == expected @@ -277,13 +277,13 @@ def test_hrule(markdown_function, expected): @pytest.mark.parametrize( - "markdown_function, expected", - ( - [ + ("markdown_function", "expected"), + [ + ( notify_letter_preview_markdown, ("
    \n" "
  1. one
  2. \n" "
  3. two
  4. \n" "
  5. three
  6. \n" "
\n"), - ], - [ + ), + ( notify_email_markdown, ( '' @@ -301,12 +301,12 @@ def test_hrule(markdown_function, expected): "" "
" ), - ], - [ + ), + ( notify_plain_text_email_markdown, ("\n" "\n1. one" "\n2. two" "\n3. three"), - ], - ), + ), + ], ) def test_ordered_list(markdown_function, expected): assert markdown_function("1. one\n" "2. two\n" "3. three\n") == expected @@ -315,7 +315,7 @@ def test_ordered_list(markdown_function, expected): @pytest.mark.parametrize( "markdown", - ( + [ ("*one\n" "*two\n" "*three\n"), # no space ("* one\n" "* two\n" "* three\n"), # single space ("* one\n" "* two\n" "* three\n"), # two spaces @@ -326,16 +326,16 @@ def test_ordered_list(markdown_function, expected): marks=pytest.mark.xfail(raises=AssertionError), ), ("• one\n" "• two\n" "• three\n"), # bullet as bullet - ), + ], ) @pytest.mark.parametrize( - "markdown_function, expected", - ( - [ + ("markdown_function", "expected"), + [ + ( notify_letter_preview_markdown, ("\n"), - ], - [ + ), + ( notify_email_markdown, ( '' @@ -353,83 +353,83 @@ def test_ordered_list(markdown_function, expected): "" "
" ), - ], - [ + ), + ( notify_plain_text_email_markdown, ("\n" "\n• one" "\n• two" "\n• three"), - ], - ), + ), + ], ) def test_unordered_list(markdown, markdown_function, expected): assert markdown_function(markdown) == expected @pytest.mark.parametrize( - "markdown_function, expected", - ( - [ + ("markdown_function", "expected"), + [ + ( notify_letter_preview_markdown, "

+ one

+ two

+ three

", - ], - [ + ), + ( notify_email_markdown, ( '

+ one

' '

+ two

' '

+ three

' ), - ], - [ + ), + ( notify_plain_text_email_markdown, ("\n\n+ one" "\n\n+ two" "\n\n+ three"), - ], - ), + ), + ], ) def test_pluses_dont_render_as_lists(markdown_function, expected): assert markdown_function("+ one\n" "+ two\n" "+ three\n") == expected @pytest.mark.parametrize( - "markdown_function, expected", - ( - [ + ("markdown_function", "expected"), + [ + ( notify_letter_preview_markdown, ("

" "line one
" "line two" "

" "

" "new paragraph" "

"), - ], - [ + ), + ( notify_email_markdown, ( '

line one
' "line two

" '

new paragraph

' ), - ], - [ + ), + ( notify_plain_text_email_markdown, ("\n" "\nline one" "\nline two" "\n" "\nnew paragraph"), - ], - ), + ), + ], ) def test_paragraphs(markdown_function, expected): assert markdown_function("line one\n" "line two\n" "\n" "new paragraph") == expected @pytest.mark.parametrize( - "markdown_function, expected", - ( - [notify_letter_preview_markdown, ("

before

" "

after

")], - [ + ("markdown_function", "expected"), + [ + (notify_letter_preview_markdown, ("

before

" "

after

")), + ( notify_email_markdown, ( '

before

' '

after

' ), - ], - [ + ), + ( notify_plain_text_email_markdown, ("\n" "\nbefore" "\n" "\nafter"), - ], - ), + ), + ], ) def test_multiple_newlines_get_truncated(markdown_function, expected): assert markdown_function("before\n\n\n\n\n\nafter") == expected @@ -437,25 +437,25 @@ def test_multiple_newlines_get_truncated(markdown_function, expected): @pytest.mark.parametrize( "markdown_function", - ( + [ notify_letter_preview_markdown, notify_email_markdown, notify_plain_text_email_markdown, - ), + ], ) def test_table(markdown_function): assert markdown_function("col | col\n" "----|----\n" "val | val\n") == ("") @pytest.mark.parametrize( - "markdown_function, link, expected", - ( - [ + ("markdown_function", "link", "expected"), + [ + ( notify_letter_preview_markdown, "http://example.com", "

example.com

", - ], - [ + ), + ( notify_email_markdown, "http://example.com", ( @@ -463,8 +463,8 @@ def test_table(markdown_function): 'http://example.com' "

" ), - ], - [ + ), + ( notify_email_markdown, """https://example.com"onclick="alert('hi')""", ( @@ -475,105 +475,105 @@ def test_table(markdown_function): "')" "

" ), - ], - [ + ), + ( notify_plain_text_email_markdown, "http://example.com", ("\n" "\nhttp://example.com"), - ], - ), + ), + ], ) def test_autolink(markdown_function, link, expected): assert markdown_function(link) == expected @pytest.mark.parametrize( - "markdown_function, expected", - ( - [notify_letter_preview_markdown, "

variable called `thing`

"], - [ + ("markdown_function", "expected"), + [ + (notify_letter_preview_markdown, "

variable called `thing`

"), + ( notify_email_markdown, '

variable called `thing`

', # noqa E501 - ], - [ + ), + ( notify_plain_text_email_markdown, "\n\nvariable called `thing`", - ], - ), + ), + ], ) def test_codespan(markdown_function, expected): assert markdown_function("variable called `thing`") == expected @pytest.mark.parametrize( - "markdown_function, expected", - ( - [notify_letter_preview_markdown, "

something **important**

"], - [ + ("markdown_function", "expected"), + [ + (notify_letter_preview_markdown, "

something **important**

"), + ( notify_email_markdown, '

something **important**

', # noqa E501 - ], - [ + ), + ( notify_plain_text_email_markdown, "\n\nsomething **important**", - ], - ), + ), + ], ) def test_double_emphasis(markdown_function, expected): assert markdown_function("something **important**") == expected @pytest.mark.parametrize( - "markdown_function, text, expected", - ( - [ + ("markdown_function", "text", "expected"), + [ + ( notify_letter_preview_markdown, "something *important*", "

something *important*

", - ], - [ + ), + ( notify_email_markdown, "something *important*", '

something *important*

', # noqa E501 - ], - [ + ), + ( notify_plain_text_email_markdown, "something *important*", "\n\nsomething *important*", - ], - [ + ), + ( notify_plain_text_email_markdown, "something _important_", "\n\nsomething _important_", - ], - [ + ), + ( notify_plain_text_email_markdown, "before*after", "\n\nbefore*after", - ], - [ + ), + ( notify_plain_text_email_markdown, "before_after", "\n\nbefore_after", - ], - ), + ), + ], ) def test_emphasis(markdown_function, text, expected): assert markdown_function(text) == expected @pytest.mark.parametrize( - "markdown_function, expected", - ( - [ + ("markdown_function", "expected"), + [ + ( notify_email_markdown, '

foo ****** bar

', - ], - [ + ), + ( notify_plain_text_email_markdown, "\n\nfoo ****** bar", - ], - ), + ), + ], ) def test_nested_emphasis(markdown_function, expected): assert markdown_function("foo ****** bar") == expected @@ -581,24 +581,24 @@ def test_nested_emphasis(markdown_function, expected): @pytest.mark.parametrize( "markdown_function", - ( + [ notify_letter_preview_markdown, notify_email_markdown, notify_plain_text_email_markdown, - ), + ], ) def test_image(markdown_function): assert markdown_function("![alt text](http://example.com/image.png)") == ("") @pytest.mark.parametrize( - "markdown_function, expected", - ( - [ + ("markdown_function", "expected"), + [ + ( notify_letter_preview_markdown, ("

Example: example.com

"), - ], - [ + ), + ( notify_email_markdown, ( '

Example' "

" ), - ], - [ + ), + ( notify_plain_text_email_markdown, ("\n" "\nExample: http://example.com"), - ], - ), + ), + ], ) def test_link(markdown_function, expected): assert markdown_function("[Example](http://example.com)") == expected @pytest.mark.parametrize( - "markdown_function, expected", - ( - [ + ("markdown_function", "expected"), + [ + ( notify_letter_preview_markdown, ("

Example: example.com

"), - ], - [ + ), + ( notify_email_markdown, ( '

" "

" ), - ], - [ + ), + ( notify_plain_text_email_markdown, ("\n" "\nExample (An example URL): http://example.com"), - ], - ), + ), + ], ) def test_link_with_title(markdown_function, expected): assert ( @@ -648,15 +648,15 @@ def test_link_with_title(markdown_function, expected): @pytest.mark.parametrize( - "markdown_function, expected", - ( - [notify_letter_preview_markdown, "

~~Strike~~

"], - [ + ("markdown_function", "expected"), + [ + (notify_letter_preview_markdown, "

~~Strike~~

"), + ( notify_email_markdown, '

~~Strike~~

', - ], - [notify_plain_text_email_markdown, "\n\n~~Strike~~"], - ), + ), + (notify_plain_text_email_markdown, "\n\n~~Strike~~"), + ], ) def test_strikethrough(markdown_function, expected): assert markdown_function("~~Strike~~") == expected diff --git a/tests/notifications_utils/test_postal_address.py b/tests/notifications_utils/test_postal_address.py index f854944cd..f13f1c8dd 100644 --- a/tests/notifications_utils/test_postal_address.py +++ b/tests/notifications_utils/test_postal_address.py @@ -17,8 +17,8 @@ def test_raw_address(): @pytest.mark.parametrize( - "address, expected_country", - ( + ("address", "expected_country"), + [ ( """ 123 Example Street @@ -51,15 +51,15 @@ def test_raw_address(): """, Country("Germany"), ), - ), + ], ) def test_country(address, expected_country): assert PostalAddress(address).country == expected_country @pytest.mark.parametrize( - "address, enough_lines_expected", - ( + ("address", "enough_lines_expected"), + [ ( "", False, @@ -102,15 +102,15 @@ def test_country(address, expected_country): """, True, ), - ), + ], ) def test_has_enough_lines(address, enough_lines_expected): assert PostalAddress(address).has_enough_lines is enough_lines_expected @pytest.mark.parametrize( - "address, too_many_lines_expected", - ( + ("address", "too_many_lines_expected"), + [ ( "", False, @@ -171,15 +171,15 @@ def test_has_enough_lines(address, enough_lines_expected): """, True, ), - ), + ], ) def test_has_too_many_lines(address, too_many_lines_expected): assert PostalAddress(address).has_too_many_lines is too_many_lines_expected @pytest.mark.parametrize( - "address, expected_postcode", - ( + ("address", "expected_postcode"), + [ ( "", None, @@ -215,7 +215,7 @@ def test_has_too_many_lines(address, too_many_lines_expected): """, None, ), - ), + ], ) def test_postcode(address, expected_postcode): assert PostalAddress(address).has_valid_postcode is bool(expected_postcode) @@ -223,7 +223,7 @@ def test_postcode(address, expected_postcode): @pytest.mark.parametrize( - "address, expected_result", + ("address", "expected_result"), [ ( "", @@ -276,8 +276,8 @@ def test_has_invalid_characters(address, expected_result): @pytest.mark.parametrize( - "address, expected_international", - ( + ("address", "expected_international"), + [ ( "", False, @@ -313,15 +313,15 @@ def test_has_invalid_characters(address, expected_result): """, True, ), - ), + ], ) def test_international(address, expected_international): assert PostalAddress(address).international is expected_international @pytest.mark.parametrize( - "address, expected_normalised, expected_as_single_line", - ( + ("address", "expected_normalised", "expected_as_single_line"), + [ ( "", "", @@ -357,7 +357,7 @@ def test_international(address, expected_international): ("123 Example Straße\n" "Germany"), ("123 Example Straße, Germany"), ), - ), + ], ) def test_normalised(address, expected_normalised, expected_as_single_line): assert PostalAddress(address).normalised == expected_normalised @@ -365,8 +365,8 @@ def test_normalised(address, expected_normalised, expected_as_single_line): @pytest.mark.parametrize( - "address, expected_postage", - ( + ("address", "expected_postage"), + [ ( "", Postage.UK, @@ -401,7 +401,7 @@ def test_normalised(address, expected_normalised, expected_as_single_line): """, Postage.REST_OF_WORLD, ), - ), + ], ) def test_postage(address, expected_postage): assert PostalAddress(address).postage == expected_postage @@ -409,7 +409,7 @@ def test_postage(address, expected_postage): @pytest.mark.parametrize( "personalisation", - ( + [ { "address_line_1": "123 Example Street", "address_line_3": "City of Town", @@ -440,7 +440,7 @@ def test_postage(address, expected_postage): "Address-Line-7": "Sw1a 1aa", } ), - ), + ], ) def test_from_personalisation(personalisation): assert PostalAddress.from_personalisation(personalisation).normalised == ( @@ -461,8 +461,8 @@ def test_from_personalisation_handles_int(): @pytest.mark.parametrize( - "address, expected_personalisation", - ( + ("address", "expected_personalisation"), + [ ( "", { @@ -515,27 +515,27 @@ def test_from_personalisation_handles_int(): "postcode": "Eight", }, ), - ), + ], ) def test_as_personalisation(address, expected_personalisation): assert PostalAddress(address).as_personalisation == expected_personalisation @pytest.mark.parametrize( - "address, expected_bool", - ( + ("address", "expected_bool"), + [ ("", False), (" ", False), ("\n\n \n", False), ("a", True), - ), + ], ) def test_bool(address, expected_bool): assert bool(PostalAddress(address)) is expected_bool @pytest.mark.parametrize( - "postcode, normalised_postcode", + ("postcode", "normalised_postcode"), [ ("SW1 3EF", "SW13EF"), ("SW13EF", "SW13EF"), @@ -550,7 +550,7 @@ def test_normalise_postcode(postcode, normalised_postcode): @pytest.mark.parametrize( - "postcode, result", + ("postcode", "result"), [ # real standard UK poscodes ("SW1 3EF", True), @@ -592,7 +592,7 @@ def test_if_postcode_is_a_real_uk_postcode_normalises_before_checking_postcode(m @pytest.mark.parametrize( - "postcode, postcode_with_space", + ("postcode", "postcode_with_space"), [ ("SW13EF", "SW1 3EF"), ("SW1 3EF", "SW1 3EF"), @@ -615,8 +615,8 @@ def test_format_postcode_for_printing(postcode, postcode_with_space): @pytest.mark.parametrize( - "address, international, expected_valid", - ( + ("address", "international", "expected_valid"), + [ ( """ UK address @@ -703,7 +703,7 @@ def test_format_postcode_for_printing(postcode, postcode_with_space): False, False, ), - ), + ], ) def test_valid_with_international_parameter(address, international, expected_valid): postal_address = PostalAddress( @@ -759,11 +759,11 @@ def test_valid_with_invalid_characters(): @pytest.mark.parametrize( - "international, expected_valid", - ( + ("international", "expected_valid"), + [ (False, False), (True, True), - ), + ], ) def test_valid_from_personalisation_with_international_parameter( international, expected_valid diff --git a/tests/notifications_utils/test_recipient_csv.py b/tests/notifications_utils/test_recipient_csv.py index e11bb14ad..72457ee1d 100644 --- a/tests/notifications_utils/test_recipient_csv.py +++ b/tests/notifications_utils/test_recipient_csv.py @@ -43,7 +43,7 @@ def _index_rows(rows): @pytest.mark.parametrize( - "template_type, expected", + ("template_type", "expected"), ( ("email", ["email address"]), ("sms", ["phone number"]), @@ -72,7 +72,7 @@ def test_recipient_column_headers(template_type, expected): @pytest.mark.parametrize( - "file_contents,template_type,expected", + ("file_contents", "template_type", "expected"), [ ( "", @@ -275,7 +275,7 @@ def test_get_rows_only_iterates_over_file_once(mocker): @pytest.mark.parametrize( - "file_contents,template_type,expected", + ("file_contents", "template_type,expected"), [ ( """ @@ -341,7 +341,7 @@ def test_get_rows_with_errors(): @pytest.mark.parametrize( - "template_type, row_count, header, filler, row_with_error", + ("template_type", "row_count", "header", "filler", "row_with_error"), [ ( "email", @@ -370,7 +370,7 @@ def test_big_list_validates_right_through( @pytest.mark.parametrize( - "template_type, row_count, header, filler", + ("template_type", "row_count", "header", "filler"), [ ("email", 50, "email address\n", "test@example.com\n"), ("sms", 50, "phone number\n", "07900900123\n"), @@ -456,7 +456,7 @@ def test_empty_column_names(): @pytest.mark.parametrize( - "file_contents,template,expected_recipients,expected_personalisation", + ("file_contents", "template", "expected_recipients", "expected_personalisation"), [ ( """ @@ -504,7 +504,7 @@ def test_get_recipient( @pytest.mark.parametrize( - "file_contents,template,expected_recipients,expected_personalisation", + ("file_contents", "template", "expected_recipients", "expected_personalisation"), [ ( """ @@ -539,7 +539,7 @@ def test_get_recipient_respects_order( @pytest.mark.parametrize( - "file_contents,template_type,expected,expected_missing", + ("file_contents", "template_type", "expected", "expected_missing"), [ ("", "sms", [], set(["phone number", "name"])), ( @@ -612,7 +612,7 @@ def test_column_headers(file_contents, template_type, expected, expected_missing ], ) @pytest.mark.parametrize( - "file_contents,template_type", + ("file_contents", "template_type"), [ pytest.param("", "sms", marks=pytest.mark.xfail), pytest.param("name", "sms", marks=pytest.mark.xfail), @@ -660,7 +660,12 @@ def test_recipient_column(content, file_contents, template_type): @pytest.mark.parametrize( - "file_contents,template_type,rows_with_bad_recipients,rows_with_missing_data", + ( + "file_contents", + "template_type", + "rows_with_bad_recipients", + "rows_with_missing_data", + ), [ ( """ @@ -761,7 +766,7 @@ def test_bad_or_missing_data( @pytest.mark.parametrize( - "file_contents,rows_with_bad_recipients", + ("file_contents", "rows_with_bad_recipients"), [ ( """ @@ -811,7 +816,7 @@ def test_errors_when_too_many_rows(): @pytest.mark.parametrize( - "file_contents,template_type,guestlist,count_of_rows_with_errors", + ("file_contents", "template_type", "guestlist", "count_of_rows_with_errors"), [ ( """ @@ -938,7 +943,7 @@ def test_detects_rows_which_result_in_empty_messages(): @pytest.mark.parametrize( - "key, expected", + ("key", "expected"), sum( [ [(key, expected) for key in group] @@ -1002,8 +1007,8 @@ def test_ignores_spaces_and_case_in_placeholders(key, expected): @pytest.mark.parametrize( - "character, name", - ( + ("character", "name"), + [ (" ", "SPACE"), # these ones don’t have unicode names ("\n", None), # newline @@ -1017,7 +1022,7 @@ def test_ignores_spaces_and_case_in_placeholders(key, expected): ("\uFEFF", "ZERO WIDTH NO-BREAK SPACE"), # all the things (" \n\r\t\u000A\u000D\u180E\u200B\u200C\u200D\u2060\uFEFF", None), - ), + ], ) def test_ignores_leading_whitespace_in_file(character, name): if name is not None: @@ -1061,7 +1066,7 @@ def test_dont_error_if_too_many_recipients_not_specified(): @pytest.mark.parametrize( - "index, expected_row", + ("index", "expected_row"), [ ( 0, @@ -1131,13 +1136,13 @@ def test_multiple_sms_recipient_columns(international_sms): @pytest.mark.parametrize( "column_name", - ( + [ "phone_number", "phonenumber", "phone number", "phone-number", "p h o n e n u m b e r", - ), + ], ) def test_multiple_sms_recipient_columns_with_missing_data(column_name): recipients = RecipientCSV( @@ -1257,12 +1262,12 @@ def test_multi_line_placeholders_work(): @pytest.mark.parametrize( - "extra_args, expected_errors, expected_bad_rows", - ( + ("extra_args", "expected_errors", "expected_bad_rows"), + [ ({}, True, {0}), ({"allow_international_letters": False}, True, {0}), ({"allow_international_letters": True}, False, set()), - ), + ], ) def test_accepts_international_addresses_when_allowed( extra_args, expected_errors, expected_bad_rows diff --git a/tests/notifications_utils/test_template_change.py b/tests/notifications_utils/test_template_change.py index e0b8df892..12e0f85d3 100644 --- a/tests/notifications_utils/test_template_change.py +++ b/tests/notifications_utils/test_template_change.py @@ -6,7 +6,7 @@ from .test_base_template import ConcreteTemplate @pytest.mark.parametrize( - "old_template, new_template, should_differ", + ("old_template", "new_template", "should_differ"), [ ( ConcreteTemplate({"content": "((1)) ((2)) ((3))"}), @@ -50,7 +50,7 @@ def test_checking_for_difference_between_templates( @pytest.mark.parametrize( - "old_template, new_template, placeholders_added", + ("old_template", "new_template", "placeholders_added"), [ ( ConcreteTemplate({"content": "((1)) ((2)) ((3))"}), @@ -87,7 +87,7 @@ def test_placeholders_added(old_template, new_template, placeholders_added): @pytest.mark.parametrize( - "old_template, new_template, placeholders_removed", + ("old_template", "new_template", "placeholders_removed"), [ ( ConcreteTemplate({"content": "((1)) ((2)) ((3))"}), diff --git a/tests/notifications_utils/test_template_types.py b/tests/notifications_utils/test_template_types.py index 0a329aca2..73ec94966 100644 --- a/tests/notifications_utils/test_template_types.py +++ b/tests/notifications_utils/test_template_types.py @@ -32,8 +32,8 @@ from notifications_utils.template import ( @pytest.mark.parametrize( - "template_class, expected_error", - ( + ("template_class", "expected_error"), + [ pytest.param( Template, ("Can't instantiate abstract class Template with abstract method __str__"), @@ -104,7 +104,7 @@ from notifications_utils.template import ( sys.version_info < (3, 9), reason="‘method’ will be pluralised" ), ), - ), + ], ) def test_abstract_classes_cant_be_instantiated(template_class, expected_error): with pytest.raises(TypeError) as error: @@ -114,8 +114,8 @@ def test_abstract_classes_cant_be_instantiated(template_class, expected_error): @pytest.mark.parametrize( - "template_class, expected_error", - ( + ("template_class", "expected_error"), + [ ( HTMLEmailTemplate, ("Cannot initialise HTMLEmailTemplate with sms template_type"), @@ -128,7 +128,7 @@ def test_abstract_classes_cant_be_instantiated(template_class, expected_error): BroadcastPreviewTemplate, ("Cannot initialise BroadcastPreviewTemplate with sms template_type"), ), - ), + ], ) def test_errors_for_incompatible_template_type(template_class, expected_error): with pytest.raises(TypeError) as error: @@ -149,7 +149,7 @@ def test_html_email_inserts_body(): @pytest.mark.parametrize( - "content", ("DOCTYPE", "html", "body", "beta.notify.gov", "hello world") + "content", ["DOCTYPE", "html", "body", "beta.notify.gov", "hello world"] ) def test_default_template(content): assert content in str( @@ -163,7 +163,7 @@ def test_default_template(content): ) -@pytest.mark.parametrize("show_banner", (True, False)) +@pytest.mark.parametrize("show_banner", [True, False]) def test_govuk_banner(show_banner): email = HTMLEmailTemplate( { @@ -194,7 +194,7 @@ def test_brand_banner_shows(): @pytest.mark.parametrize( - "brand_logo, brand_text, brand_colour", + ("brand_logo", "brand_text", "brand_colour"), [ ("http://example.com/image.png", "Example", "red"), ("http://example.com/image.png", "Example", "#f00"), @@ -255,7 +255,7 @@ def test_alt_text_with_no_brand_text_and_govuk_banner_shown(): @pytest.mark.parametrize( - "brand_banner, brand_text, expected_alt_text", + ("brand_banner", "brand_text", "expected_alt_text"), [ (True, None, 'alt="Notify Logo"'), (True, "Example", 'alt=""'), @@ -278,9 +278,9 @@ def test_alt_text_with_no_govuk_banner(brand_banner, brand_text, expected_alt_te assert expected_alt_text in email -@pytest.mark.parametrize("complete_html", (True, False)) +@pytest.mark.parametrize("complete_html", [True, False]) @pytest.mark.parametrize( - "branding_should_be_present, brand_logo, brand_text, brand_colour", + ("branding_should_be_present", "brand_logo", "brand_text", "brand_colour"), [ (True, "http://example.com/image.png", "Example", "#f00"), (True, "http://example.com/image.png", "Example", None), @@ -289,7 +289,7 @@ def test_alt_text_with_no_govuk_banner(brand_banner, brand_text, expected_alt_te (False, "http://example.com/image.png", None, "#f00"), ], ) -@pytest.mark.parametrize("content", ("DOCTYPE", "html", "body")) +@pytest.mark.parametrize("content", ["DOCTYPE", "html", "body"]) def test_complete_html( complete_html, branding_should_be_present, @@ -351,7 +351,7 @@ def test_preheader_is_at_start_of_html_emails(): @pytest.mark.parametrize( - "content, values, expected_preheader", + ("content", "values", "expected_preheader"), [ ( ( @@ -426,22 +426,22 @@ def test_content_of_preheader_in_html_emails( @pytest.mark.parametrize( - "template_class, template_type, extra_args, result, markdown_renderer", + ("template_class", "template_type", "extra_args", "result", "markdown_renderer"), [ - [ + ( HTMLEmailTemplate, "email", {}, ("the quick brown fox\n" "\n" "jumped over the lazy dog\n"), "notifications_utils.template.notify_email_markdown", - ], - [ + ), + ( LetterPreviewTemplate, "letter", {}, ("the quick brown fox\n" "\n" "jumped over the lazy dog\n"), "notifications_utils.template.notify_letter_preview_markdown", - ], + ), ], ) def test_markdown_in_templates( @@ -471,7 +471,7 @@ def test_markdown_in_templates( @pytest.mark.parametrize( - "template_class, template_type, extra_attributes", + ("template_class", "template_type", "extra_attributes"), [ (HTMLEmailTemplate, "email", 'style="word-wrap: break-word; color: #1D70B8;"'), ( @@ -494,7 +494,7 @@ def test_markdown_in_templates( ], ) @pytest.mark.parametrize( - "url, url_with_entities_replaced", + ("url", "url_with_entities_replaced"), [ ("http://example.com", "http://example.com"), ("http://www.gov.uk/", "http://www.gov.uk/"), @@ -530,15 +530,15 @@ def test_makes_links_out_of_URLs( @pytest.mark.parametrize( - "template_class, template_type", - ( + ("template_class", "template_type"), + [ (SMSPreviewTemplate, "sms"), (BroadcastPreviewTemplate, "broadcast"), - ), + ], ) @pytest.mark.parametrize( - "url, url_with_entities_replaced", - ( + ("url", "url_with_entities_replaced"), + [ ("example.com", "example.com"), ("www.gov.uk/", "www.gov.uk/"), ("service.gov.uk", "service.gov.uk"), @@ -547,7 +547,7 @@ def test_makes_links_out_of_URLs( "service.gov.uk/blah.ext?q=a%20b%20c&order=desc#fragment", "service.gov.uk/blah.ext?q=a%20b%20c&order=desc#fragment", ), - ), + ], ) def test_makes_links_out_of_URLs_without_protocol_in_sms_and_broadcast( template_class, @@ -567,8 +567,8 @@ def test_makes_links_out_of_URLs_without_protocol_in_sms_and_broadcast( @pytest.mark.parametrize( - "content, html_snippet", - ( + ("content", "html_snippet"), + [ ( ( "You've been invited to a service. Click this link:\n" @@ -592,7 +592,7 @@ def test_makes_links_out_of_URLs_without_protocol_in_sms_and_broadcast( "" ), ), - ), + ], ) def test_HTML_template_has_URLs_replaced_with_links(content, html_snippet): assert html_snippet in str( @@ -601,7 +601,7 @@ def test_HTML_template_has_URLs_replaced_with_links(content, html_snippet): @pytest.mark.parametrize( - "template_content,expected", + ("template_content", "expected"), [ ("gov.uk", "gov.\u200Buk"), ("GOV.UK", "GOV.\u200BUK"), @@ -660,7 +660,7 @@ def test_stripping_of_unsupported_characters_in_email_templates(): @mock.patch("notifications_utils.template.add_prefix", return_value="") @pytest.mark.parametrize( - "template_class, prefix, body, expected_call", + ("template_class", "prefix", "body", "expected_call"), [ (SMSMessageTemplate, "a", "b", (Markup("b"), "a")), (SMSPreviewTemplate, "a", "b", (Markup("b"), "a")), @@ -705,7 +705,7 @@ def test_sms_message_adds_prefix( ], ) @pytest.mark.parametrize( - "show_prefix, prefix, body, sender, expected_call", + ("show_prefix", "prefix", "body", "sender", "expected_call"), [ (False, "a", "b", "c", (Markup("b"), None)), (True, "a", "b", None, (Markup("b"), "a")), @@ -761,14 +761,14 @@ def test_sms_message_preview_hides_sender_by_default(): @mock.patch("notifications_utils.template.sms_encode", return_value="downgraded") @pytest.mark.parametrize( - "template_class, extra_args, expected_call", - ( + ("template_class", "extra_args", "expected_call"), + [ (SMSMessageTemplate, {"prefix": "Service name"}, "Service name: Message"), (SMSPreviewTemplate, {"prefix": "Service name"}, "Service name: Message"), (BroadcastMessageTemplate, {}, "Message"), (BroadcastPreviewTemplate, {"prefix": "Service name"}, "Service name: Message"), (SMSBodyPreviewTemplate, {}, "Message"), - ), + ], ) def test_sms_messages_downgrade_non_sms( mock_sms_encode, @@ -788,10 +788,10 @@ def test_sms_messages_downgrade_non_sms( @pytest.mark.parametrize( "template_class", - ( + [ SMSPreviewTemplate, BroadcastPreviewTemplate, - ), + ], ) @mock.patch("notifications_utils.template.sms_encode", return_value="downgraded") def test_sms_messages_dont_downgrade_non_sms_if_setting_is_false( @@ -810,10 +810,10 @@ def test_sms_messages_dont_downgrade_non_sms_if_setting_is_false( @pytest.mark.parametrize( "template_class", - ( + [ SMSPreviewTemplate, BroadcastPreviewTemplate, - ), + ], ) @mock.patch("notifications_utils.template.nl2br") def test_sms_preview_adds_newlines(nl2br, template_class): @@ -862,13 +862,13 @@ def test_broadcast_message_normalises_newlines(content): @pytest.mark.parametrize( "template_class", - ( + [ SMSMessageTemplate, SMSBodyPreviewTemplate, BroadcastMessageTemplate, # Note: SMSPreviewTemplate and BroadcastPreviewTemplate not tested here # as both will render full HTML template, not just the body - ), + ], ) def test_phone_templates_normalise_whitespace(template_class): content = " Hi\u00A0there\u00A0 what's\u200D up\t" @@ -889,7 +889,7 @@ def test_phone_templates_normalise_whitespace(template_class): "notifications_utils.template.notify_letter_preview_markdown", return_value="Bar" ) @pytest.mark.parametrize( - "values, expected_address", + ("values", "expected_address"), [ ( {}, @@ -933,7 +933,7 @@ def test_phone_templates_normalise_whitespace(template_class): ], ) @pytest.mark.parametrize( - "contact_block, expected_rendered_contact_block", + ("contact_block", "expected_rendered_contact_block"), [ (None, ""), ("", ""), @@ -962,14 +962,14 @@ def test_phone_templates_normalise_whitespace(template_class): ], ) @pytest.mark.parametrize( - "extra_args, expected_logo_file_name, expected_logo_class", + ("extra_args", "expected_logo_file_name", "expected_logo_class"), [ ({}, None, None), ({"logo_file_name": "example.foo"}, "example.foo", "foo"), ], ) @pytest.mark.parametrize( - "additional_extra_args, expected_date", + ("additional_extra_args", "expected_date"), [ ({}, "12 December 2012"), ({"date": None}, "12 December 2012"), @@ -1044,7 +1044,7 @@ def test_letter_preview_renderer_without_mocks(jinja_template): @freeze_time("2012-12-12 12:12:12") @mock.patch("notifications_utils.template.LetterImageTemplate.jinja_template.render") @pytest.mark.parametrize( - ("page_count, expected_oversized, expected_page_numbers"), + ("page_count", "expected_oversized", "expected_page_numbers"), [ ( 1, @@ -1074,8 +1074,13 @@ def test_letter_preview_renderer_without_mocks(jinja_template): ], ) @pytest.mark.parametrize( - "postage_args, expected_show_postage, expected_postage_class_value, expected_postage_description", ( + "postage_args", + "expected_show_postage", + "expected_postage_class_value", + "expected_postage_description", + ), + [ pytest.param({}, False, None, None), pytest.param({"postage": None}, False, None, None), pytest.param({"postage": "first"}, True, "letter-postage-first", "first class"), @@ -1098,7 +1103,7 @@ def test_letter_preview_renderer_without_mocks(jinja_template): "third class", marks=pytest.mark.xfail(raises=TypeError), ), - ), + ], ) def test_letter_image_renderer( jinja_template, @@ -1147,13 +1152,13 @@ def test_letter_image_renderer( @mock.patch("notifications_utils.template.LetterImageTemplate.jinja_template.render") @pytest.mark.parametrize( "postage_argument", - ( + [ None, "first", "second", "europe", "rest-of-world", - ), + ], ) def test_letter_image_renderer_shows_international_post( jinja_template, @@ -1219,7 +1224,7 @@ def test_letter_image_renderer_pagination(page_image_url): @pytest.mark.parametrize( - "partial_call, expected_exception, expected_message", + ("partial_call", "expected_exception", "expected_message"), [ ( partial(LetterImageTemplate), @@ -1261,8 +1266,8 @@ def test_letter_image_renderer_requires_arguments( @pytest.mark.parametrize( - "postage, expected_attribute_value, expected_postage_text", - ( + ("postage", "expected_attribute_value", "expected_postage_text"), + [ (None, None, None), ( "first", @@ -1284,7 +1289,7 @@ def test_letter_image_renderer_requires_arguments( ["letter-postage", "letter-postage-international"], "Postage: international", ), - ), + ], ) def test_letter_image_renderer_passes_postage_to_html_attribute( postage, @@ -1315,20 +1320,20 @@ def test_letter_image_renderer_passes_postage_to_html_attribute( @pytest.mark.parametrize( "template_class", - ( + [ SMSBodyPreviewTemplate, SMSMessageTemplate, SMSPreviewTemplate, BroadcastMessageTemplate, BroadcastPreviewTemplate, - ), + ], ) @pytest.mark.parametrize( "template_json", - ( + [ {"content": ""}, {"content": "", "subject": "subject"}, - ), + ], ) def test_sms_templates_have_no_subject(template_class, template_json): template_json.update(template_type=template_class.template_type) @@ -1358,8 +1363,8 @@ def test_subject_line_gets_applied_to_correct_template_types(): @pytest.mark.parametrize( - "template_class, template_type, extra_args", - ( + ("template_class", "template_type", "extra_args"), + [ (EmailPreviewTemplate, "email", {}), (HTMLEmailTemplate, "email", {}), (PlainTextEmailTemplate, "email", {}), @@ -1373,7 +1378,7 @@ def test_subject_line_gets_applied_to_correct_template_types(): "page_count": 1, }, ), - ), + ], ) def test_subject_line_gets_replaced(template_class, template_type, extra_args): template = template_class( @@ -1386,8 +1391,8 @@ def test_subject_line_gets_replaced(template_class, template_type, extra_args): @pytest.mark.parametrize( - "template_class, template_type, extra_args", - ( + ("template_class", "template_type", "extra_args"), + [ (EmailPreviewTemplate, "email", {}), (HTMLEmailTemplate, "email", {}), (PlainTextEmailTemplate, "email", {}), @@ -1401,10 +1406,10 @@ def test_subject_line_gets_replaced(template_class, template_type, extra_args): "page_count": 1, }, ), - ), + ], ) @pytest.mark.parametrize( - "content, values, expected_count", + ("content", "values", "expected_count"), [ ("Content with ((placeholder))", {"placeholder": "something extra"}, 28), ("Content with ((placeholder))", {"placeholder": ""}, 12), @@ -1441,7 +1446,13 @@ def test_character_count_for_non_sms_templates( ], ) @pytest.mark.parametrize( - "content, values, prefix, expected_count_in_template, expected_count_in_notification", + ( + "content", + "values", + "prefix", + "expected_count_in_template", + "expected_count_in_notification", + ), [ # is an unsupported unicode character so should be replaced with a ? ("深", {}, None, 1, 1), @@ -1507,7 +1518,12 @@ def test_character_count_for_sms_templates( ], ) @pytest.mark.parametrize( - "content, values, expected_count_in_template, expected_count_in_notification", + ( + "content", + "values", + "expected_count_in_template", + "expected_count_in_notification", + ), [ # is an unsupported unicode character so should be replaced with a ? ("深", {}, 1, 1), @@ -1546,13 +1562,13 @@ def test_character_count_for_broadcast_templates( @pytest.mark.parametrize( "template_class", - ( + [ SMSMessageTemplate, BroadcastMessageTemplate, - ), + ], ) @pytest.mark.parametrize( - "msg, expected_sms_fragment_count", + ("msg", "expected_sms_fragment_count"), [ ( """This is a very long long long long long long long long long long @@ -1575,10 +1591,10 @@ def test_sms_fragment_count_accounts_for_unicode_and_welsh_characters( @pytest.mark.parametrize( "template_class", - ( + [ SMSMessageTemplate, BroadcastMessageTemplate, - ), + ], ) @pytest.mark.parametrize( ("msg", "expected_sms_fragment_count"), @@ -1697,10 +1713,10 @@ def test_is_message_empty_broadcast_templates( @pytest.mark.parametrize( ("template_class", "template_type"), - ( + [ (HTMLEmailTemplate, "email"), (LetterPrintTemplate, "letter"), - ), + ], ) @pytest.mark.parametrize( ("content", "values", "expected_result"), @@ -1735,11 +1751,11 @@ def test_is_message_empty_email_and_letter_templates( @pytest.mark.parametrize( - "template_class, template_type", - ( + ("template_class", "template_type"), + [ (HTMLEmailTemplate, "email"), (LetterPrintTemplate, "letter"), - ), + ], ) @pytest.mark.parametrize( ("content", "values"), @@ -2054,7 +2070,12 @@ def test_templates_handle_html_and_redacting( @pytest.mark.parametrize( - ("template_class", "template_type", "extra_args", "expected_remove_whitespace_calls"), + ( + "template_class", + "template_type", + "extra_args", + "expected_remove_whitespace_calls", + ), [ ( PlainTextEmailTemplate, @@ -2259,18 +2280,18 @@ def test_templates_make_quotes_smart_and_dashes_en( @pytest.mark.parametrize( "content", - ( + [ "first.o'last@example.com", "first.o’last@example.com", - ), + ], ) @pytest.mark.parametrize( "template_class", - ( + [ HTMLEmailTemplate, PlainTextEmailTemplate, EmailPreviewTemplate, - ), + ], ) def test_no_smart_quotes_in_email_addresses(template_class, content): template = template_class( diff --git a/tests/notifications_utils/test_timezones.py b/tests/notifications_utils/test_timezones.py index bfcf413f6..d92bb54b7 100644 --- a/tests/notifications_utils/test_timezones.py +++ b/tests/notifications_utils/test_timezones.py @@ -5,7 +5,7 @@ from notifications_utils.timezones import utc_string_to_aware_gmt_datetime @pytest.mark.parametrize( - "input_value,expectation", + ("input_value", "expectation"), [ ("foo", pytest.raises(dateutil.parser._parser.ParserError)), (100, pytest.raises(TypeError)), @@ -20,7 +20,7 @@ def test_utc_string_to_aware_gmt_datetime_rejects_bad_input(input_value, expecta @pytest.mark.parametrize( - "naive_time, expected_aware_hour", + ("naive_time", "expected_aware_hour"), [ ("2000-12-1 20:01", "15:01"), ("2000-06-1 20:01", "16:01"), diff --git a/tests/notifications_utils/test_url_safe_tokens.py b/tests/notifications_utils/test_url_safe_tokens.py index 624f80f9c..7b7a391c1 100644 --- a/tests/notifications_utils/test_url_safe_tokens.py +++ b/tests/notifications_utils/test_url_safe_tokens.py @@ -1,7 +1,6 @@ import urllib - +import pytest from itsdangerous import BadSignature, SignatureExpired -from pytest import fail from notifications_utils.url_safe_token import check_token, generate_token @@ -19,7 +18,7 @@ def test_should_throw_exception_when_token_is_tampered_with(): token = generate_token(str(uuid.uuid4()), "secret-key", "dangerous-salt") try: check_token(token + "qerqwer", "secret-key", "dangerous-salt", 30) - fail() + pytest.fail("Expected a BadSignature") except BadSignature: pass @@ -31,6 +30,6 @@ def test_return_none_when_token_is_expired(): token = urllib.parse.unquote(token) try: assert check_token(token, "secret-key", "dangerous-salt", max_age) is None - fail("Expected a SignatureExpired exception") + pytest.fail("Expected a SignatureExpired exception") except SignatureExpired: pass