mirror of
https://github.com/GSA/notifications-api.git
synced 2026-05-05 00:30:04 -04:00
Updated tests to match the formatting work done in the admin repo
Signed-off-by: Carlo Costino <carlo.costino@gsa.gov>
This commit is contained in:
@@ -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, ("<p>inset text</p>")],
|
||||
[
|
||||
("markdown_function", "expected"),
|
||||
[
|
||||
(notify_letter_preview_markdown, ("<p>inset text</p>")),
|
||||
(
|
||||
notify_email_markdown,
|
||||
(
|
||||
"<blockquote "
|
||||
@@ -179,12 +179,12 @@ def test_block_code(markdown_function, expected):
|
||||
'<p style="Margin: 0 0 20px 0; font-size: 19px; line-height: 25px; color: #0B0C0C;">inset text</p>'
|
||||
"</blockquote>"
|
||||
),
|
||||
],
|
||||
[
|
||||
),
|
||||
(
|
||||
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, "<h2>heading</h2>\n"],
|
||||
[
|
||||
("markdown_function", "expected"),
|
||||
[
|
||||
(notify_letter_preview_markdown, "<h2>heading</h2>\n"),
|
||||
(
|
||||
notify_email_markdown,
|
||||
(
|
||||
'<h2 style="Margin: 0 0 20px 0; padding: 0; font-size: 27px; '
|
||||
@@ -209,8 +209,8 @@ def test_block_quote(markdown_function, expected):
|
||||
"heading"
|
||||
"</h2>"
|
||||
),
|
||||
],
|
||||
[
|
||||
),
|
||||
(
|
||||
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, "<p>inset text</p>"],
|
||||
[
|
||||
("markdown_function", "expected"),
|
||||
[
|
||||
(notify_letter_preview_markdown, "<p>inset text</p>"),
|
||||
(
|
||||
notify_email_markdown,
|
||||
'<p style="Margin: 0 0 20px 0; font-size: 19px; line-height: 25px; color: #0B0C0C;">inset text</p>',
|
||||
],
|
||||
[
|
||||
),
|
||||
(
|
||||
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,
|
||||
("<p>a</p>" '<div class="page-break"> </div>' "<p>b</p>"),
|
||||
],
|
||||
[
|
||||
),
|
||||
(
|
||||
notify_email_markdown,
|
||||
(
|
||||
'<p style="Margin: 0 0 20px 0; font-size: 19px; line-height: 25px; color: #0B0C0C;">a</p>'
|
||||
'<hr style="border: 0; height: 1px; background: #B1B4B6; Margin: 30px 0 30px 0;">'
|
||||
'<p style="Margin: 0 0 20px 0; font-size: 19px; line-height: 25px; color: #0B0C0C;">b</p>'
|
||||
),
|
||||
],
|
||||
[
|
||||
),
|
||||
(
|
||||
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,
|
||||
("<ol>\n" "<li>one</li>\n" "<li>two</li>\n" "<li>three</li>\n" "</ol>\n"),
|
||||
],
|
||||
[
|
||||
),
|
||||
(
|
||||
notify_email_markdown,
|
||||
(
|
||||
'<table role="presentation" style="padding: 0 0 20px 0;">'
|
||||
@@ -301,12 +301,12 @@ def test_hrule(markdown_function, expected):
|
||||
"</tr>"
|
||||
"</table>"
|
||||
),
|
||||
],
|
||||
[
|
||||
),
|
||||
(
|
||||
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,27 +315,26 @@ 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
|
||||
("* one\n" "* two\n" "* three\n"), # tab
|
||||
("- one\n" "- two\n" "- three\n"), # dash as bullet
|
||||
pytest.param(
|
||||
("+ one\n" "+ two\n" "+ three\n"), # plus as bullet
|
||||
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,
|
||||
("<ul>\n" "<li>one</li>\n" "<li>two</li>\n" "<li>three</li>\n" "</ul>\n"),
|
||||
],
|
||||
[
|
||||
),
|
||||
(
|
||||
notify_email_markdown,
|
||||
(
|
||||
'<table role="presentation" style="padding: 0 0 20px 0;">'
|
||||
@@ -353,83 +352,83 @@ def test_ordered_list(markdown_function, expected):
|
||||
"</tr>"
|
||||
"</table>"
|
||||
),
|
||||
],
|
||||
[
|
||||
),
|
||||
(
|
||||
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,
|
||||
"<p>+ one</p><p>+ two</p><p>+ three</p>",
|
||||
],
|
||||
[
|
||||
),
|
||||
(
|
||||
notify_email_markdown,
|
||||
(
|
||||
'<p style="Margin: 0 0 20px 0; font-size: 19px; line-height: 25px; color: #0B0C0C;">+ one</p>'
|
||||
'<p style="Margin: 0 0 20px 0; font-size: 19px; line-height: 25px; color: #0B0C0C;">+ two</p>'
|
||||
'<p style="Margin: 0 0 20px 0; font-size: 19px; line-height: 25px; color: #0B0C0C;">+ three</p>'
|
||||
),
|
||||
],
|
||||
[
|
||||
),
|
||||
(
|
||||
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,
|
||||
("<p>" "line one<br>" "line two" "</p>" "<p>" "new paragraph" "</p>"),
|
||||
],
|
||||
[
|
||||
),
|
||||
(
|
||||
notify_email_markdown,
|
||||
(
|
||||
'<p style="Margin: 0 0 20px 0; font-size: 19px; line-height: 25px; color: #0B0C0C;">line one<br />'
|
||||
"line two</p>"
|
||||
'<p style="Margin: 0 0 20px 0; font-size: 19px; line-height: 25px; color: #0B0C0C;">new paragraph</p>'
|
||||
),
|
||||
],
|
||||
[
|
||||
),
|
||||
(
|
||||
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, ("<p>before</p>" "<p>after</p>")],
|
||||
[
|
||||
("markdown_function", "expected"),
|
||||
[
|
||||
(notify_letter_preview_markdown, ("<p>before</p>" "<p>after</p>")),
|
||||
(
|
||||
notify_email_markdown,
|
||||
(
|
||||
'<p style="Margin: 0 0 20px 0; font-size: 19px; line-height: 25px; color: #0B0C0C;">before</p>'
|
||||
'<p style="Margin: 0 0 20px 0; font-size: 19px; line-height: 25px; color: #0B0C0C;">after</p>'
|
||||
),
|
||||
],
|
||||
[
|
||||
),
|
||||
(
|
||||
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 +436,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",
|
||||
"<p><strong>example.com</strong></p>",
|
||||
],
|
||||
[
|
||||
),
|
||||
(
|
||||
notify_email_markdown,
|
||||
"http://example.com",
|
||||
(
|
||||
@@ -463,8 +462,8 @@ def test_table(markdown_function):
|
||||
'<a style="word-wrap: break-word; color: #1D70B8;" href="http://example.com">http://example.com</a>'
|
||||
"</p>"
|
||||
),
|
||||
],
|
||||
[
|
||||
),
|
||||
(
|
||||
notify_email_markdown,
|
||||
"""https://example.com"onclick="alert('hi')""",
|
||||
(
|
||||
@@ -475,105 +474,105 @@ def test_table(markdown_function):
|
||||
"</a>')"
|
||||
"</p>"
|
||||
),
|
||||
],
|
||||
[
|
||||
),
|
||||
(
|
||||
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, "<p>variable called `thing`</p>"],
|
||||
[
|
||||
("markdown_function", "expected"),
|
||||
[
|
||||
(notify_letter_preview_markdown, "<p>variable called `thing`</p>"),
|
||||
(
|
||||
notify_email_markdown,
|
||||
'<p style="Margin: 0 0 20px 0; font-size: 19px; line-height: 25px; color: #0B0C0C;">variable called `thing`</p>', # 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, "<p>something **important**</p>"],
|
||||
[
|
||||
("markdown_function", "expected"),
|
||||
[
|
||||
(notify_letter_preview_markdown, "<p>something **important**</p>"),
|
||||
(
|
||||
notify_email_markdown,
|
||||
'<p style="Margin: 0 0 20px 0; font-size: 19px; line-height: 25px; color: #0B0C0C;">something **important**</p>', # 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*",
|
||||
"<p>something *important*</p>",
|
||||
],
|
||||
[
|
||||
),
|
||||
(
|
||||
notify_email_markdown,
|
||||
"something *important*",
|
||||
'<p style="Margin: 0 0 20px 0; font-size: 19px; line-height: 25px; color: #0B0C0C;">something *important*</p>', # 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,
|
||||
'<p style="Margin: 0 0 20px 0; font-size: 19px; line-height: 25px; color: #0B0C0C;">foo ****** bar</p>',
|
||||
],
|
||||
[
|
||||
),
|
||||
(
|
||||
notify_plain_text_email_markdown,
|
||||
"\n\nfoo ****** bar",
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_nested_emphasis(markdown_function, expected):
|
||||
assert markdown_function("foo ****** bar") == expected
|
||||
@@ -581,24 +580,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("") == ("")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"markdown_function, expected",
|
||||
(
|
||||
[
|
||||
("markdown_function", "expected"),
|
||||
[
|
||||
(
|
||||
notify_letter_preview_markdown,
|
||||
("<p>Example: <strong>example.com</strong></p>"),
|
||||
],
|
||||
[
|
||||
),
|
||||
(
|
||||
notify_email_markdown,
|
||||
(
|
||||
'<p style="Margin: 0 0 20px 0; font-size: 19px; line-height: 25px; '
|
||||
@@ -606,25 +605,25 @@ def test_image(markdown_function):
|
||||
'<a style="word-wrap: break-word; color: #1D70B8;" href="http://example.com">Example</a>'
|
||||
"</p>"
|
||||
),
|
||||
],
|
||||
[
|
||||
),
|
||||
(
|
||||
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,
|
||||
("<p>Example: <strong>example.com</strong></p>"),
|
||||
],
|
||||
[
|
||||
),
|
||||
(
|
||||
notify_email_markdown,
|
||||
(
|
||||
'<p style="Margin: 0 0 20px 0; font-size: 19px; line-height: 25px; '
|
||||
@@ -634,12 +633,12 @@ def test_link(markdown_function, expected):
|
||||
"</a>"
|
||||
"</p>"
|
||||
),
|
||||
],
|
||||
[
|
||||
),
|
||||
(
|
||||
notify_plain_text_email_markdown,
|
||||
("\n" "\nExample (An example URL): http://example.com"),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_link_with_title(markdown_function, expected):
|
||||
assert (
|
||||
@@ -648,15 +647,15 @@ def test_link_with_title(markdown_function, expected):
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"markdown_function, expected",
|
||||
(
|
||||
[notify_letter_preview_markdown, "<p>~~Strike~~</p>"],
|
||||
[
|
||||
("markdown_function", "expected"),
|
||||
[
|
||||
(notify_letter_preview_markdown, "<p>~~Strike~~</p>"),
|
||||
(
|
||||
notify_email_markdown,
|
||||
'<p style="Margin: 0 0 20px 0; font-size: 19px; line-height: 25px; color: #0B0C0C;">~~Strike~~</p>',
|
||||
],
|
||||
[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
|
||||
|
||||
Reference in New Issue
Block a user