import pytest
from notifications_utils.field import Field
@pytest.mark.parametrize(
(
"content",
"values",
"expected_stripped",
"expected_escaped",
"expected_passthrough",
),
[
(
"string with html",
{},
"string with html",
"string <em>with</em> html",
"string with html",
),
(
"string ((with)) html",
{},
"string ((with)) html",
"string ((<em>with</em>)) html",
"string ((with)) html",
),
(
"string ((placeholder)) html",
{"placeholder": "without"},
"string without html",
"string <em>without</em> html",
"string without html",
),
(
"string ((conditional??placeholder)) html",
{},
"string ((conditional??placeholder)) html",
(
"string "
""
"((<em>conditional</em>??"
"<em>placeholder</em>)) "
"html"
),
(
"string "
""
"((conditional??"
"placeholder)) "
"html"
),
),
(
"string ((conditional??placeholder)) html",
{"conditional": True},
"string placeholder html",
"string <em>placeholder</em> html",
"string placeholder html",
),
(
"string & entity",
{},
"string & entity",
"string & entity",
"string & entity",
),
],
)
def test_field_handles_html(
content, values, expected_stripped, expected_escaped, expected_passthrough
):
assert str(Field(content, values)) == expected_stripped
assert str(Field(content, values, html="strip")) == expected_stripped
assert str(Field(content, values, html="escape")) == expected_escaped
assert str(Field(content, values, html="passthrough")) == expected_passthrough