Skip to content

Commit

Permalink
add 2 more IRCC seals (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
sastels authored Aug 27, 2021
1 parent e316f92 commit 5375abd
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 3 deletions.
32 changes: 32 additions & 0 deletions notifications_utils/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

TAG_IMG_IRCC_COAT_OF_ARMS = r"\[\[ircc-coat-arms\]\]" # matches [[ircc-coat-arms]]
TAG_IMG_IRCC_GLOBAL_AFFAIRS = r"\[\[ircc-ga-seal\]\]" # matches [[ircc-ga-seal]]
TAG_IMG_IRCC_IRCC_SEAL = r"\[\[ircc-seal\]\]" # matches [[ircc-seal]]
TAG_IMG_IRCC_GC_SEAL = r"\[\[ircc-gc-seal\]\]" # matches [[ircc-gc-seal]]

mistune._block_quote_leading_pattern = re.compile(r"^ *\^ ?", flags=re.M)
mistune.BlockGrammar.block_quote = re.compile(r"^( *\^[^\n]+(\n[^\n]+)*\n*)+")
Expand Down Expand Up @@ -670,6 +672,36 @@ def add_ircc_ga_seal(_content: str) -> str:
return add_img_tag(_content, TAG_IMG_IRCC_GLOBAL_AFFAIRS, img_loc, alt_text, 295, 281)


def add_ircc_seal(_content: str) -> str:
"""
Custom parser to add IRCC seal logo.
This is a custom temporary change not meant to exist for more than a few
weeks. This should either be removed or upgraded into a full-fledged
feature.
TODO: Review, remove/upgrade this functionality.
"""
img_loc = "https://assets.notification.canada.ca/gc-ircc-seal.png"
alt_text = "Immigration, Refugees and Citizenship Canada / Immigration, Réfugiés et Citoyenneté Canada"
return add_img_tag(_content, TAG_IMG_IRCC_IRCC_SEAL, img_loc, alt_text, 295, 281)


def add_ircc_gc_seal(_content: str) -> str:
"""
Custom parser to add Government of Canada seal logo.
This is a custom temporary change not meant to exist for more than a few
weeks. This should either be removed or upgraded into a full-fledged
feature.
TODO: Review, remove/upgrade this functionality.
"""
img_loc = "https://assets.notification.canada.ca/gc-ircc-gc-seal.png"
alt_text = "Government of Canada / Gouvernement du Canada"
return add_img_tag(_content, TAG_IMG_IRCC_GC_SEAL, img_loc, alt_text, 295, 281)


def add_ircc_coat_of_arms(_content: str) -> str:
"""
Custom parser to add IRCC coat of arms logo.
Expand Down
4 changes: 4 additions & 0 deletions notifications_utils/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
nl2li,
add_ircc_coat_of_arms,
add_ircc_ga_seal,
add_ircc_seal,
add_ircc_gc_seal,
add_language_divs,
add_prefix,
add_newlines_around_lang_tags,
Expand Down Expand Up @@ -753,6 +755,8 @@ def get_html_email_body(template_content, template_values, redact_missing_person
.then(add_language_divs)
.then(add_ircc_coat_of_arms)
.then(add_ircc_ga_seal)
.then(add_ircc_seal)
.then(add_ircc_gc_seal)
.then(do_nice_typography)
)

Expand Down
2 changes: 1 addition & 1 deletion notifications_utils/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "46.0.0"
__version__ = "46.1.0"
# GDS version '34.0.1'
44 changes: 44 additions & 0 deletions tests/test_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from notifications_utils.formatters import (
add_ircc_coat_of_arms,
add_ircc_ga_seal,
add_ircc_seal,
add_ircc_gc_seal,
add_language_divs,
remove_language_divs,
unlink_govuk_escaped,
Expand Down Expand Up @@ -1014,6 +1016,48 @@ def test_add_ga_seal(input: str, output_dict: List[Dict]):
assert "[[ircc-" not in parsed_input


@pytest.mark.parametrize(
"input,output_dict",
(
("abc 123", [{"string": "abc 123", "occurances": 1}]),
(
"Hi,\n[[ircc-seal]]\nBye",
[{"string": "Hi,", "occurances": 1}, {"string": "<img", "occurances": 1}, {"string": "Bye", "occurances": 1}],
),
(
"Hi,\n[[ircc-seal]]\nBye[[ircc-seal]]",
[{"string": "Hi,", "occurances": 1}, {"string": "<img", "occurances": 2}, {"string": "Bye", "occurances": 1}],
),
),
)
def test_add_ircc_seal(input: str, output_dict: List[Dict]):
parsed_input = add_ircc_seal(input)
for output in output_dict:
assert parsed_input.count(output["string"]) == output["occurances"]
assert "[[ircc-" not in parsed_input


@pytest.mark.parametrize(
"input,output_dict",
(
("abc 123", [{"string": "abc 123", "occurances": 1}]),
(
"Hi,\n[[ircc-gc-seal]]\nBye",
[{"string": "Hi,", "occurances": 1}, {"string": "<img", "occurances": 1}, {"string": "Bye", "occurances": 1}],
),
(
"Hi,\n[[ircc-gc-seal]]\nBye[[ircc-gc-seal]]",
[{"string": "Hi,", "occurances": 1}, {"string": "<img", "occurances": 2}, {"string": "Bye", "occurances": 1}],
),
),
)
def test_add_gc_seal(input: str, output_dict: List[Dict]):
parsed_input = add_ircc_gc_seal(input)
for output in output_dict:
assert parsed_input.count(output["string"]) == output["occurances"]
assert "[[ircc-" not in parsed_input


@pytest.mark.parametrize(
"input,output_dict",
(
Expand Down
10 changes: 8 additions & 2 deletions tests/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ def test_lang_tags_in_templates_good_content(good_content: str):
"[ircc-ga-seal]", # missing brackets
"[[ircc-coat-arms]", # missing bracket
"[ircc-coat-arms]", # missing brackets
"[[ircc-seal]", # missing bracket
"[ircc-seal]", # missing brackets
"[[ircc-gc-seal]", # missing bracket
"[ircc-gc-seal]", # missing brackets
],
)
def test_ircc_ga_tags_in_templates_bad_content(bad_content: str):
def test_ircc_tags_in_templates_bad_content(bad_content: str):
html = get_html_email_body(bad_content, {})
assert "<img" not in html
assert "[ircc-" in html
Expand All @@ -64,11 +68,13 @@ def test_ircc_ga_tags_in_templates_bad_content(bad_content: str):
"[[ircc-ga-seal]]\nEmail Body",
"Hi,\n[[ircc-ga-seal]]\nBye",
"Hi,\n\n[[ircc-ga-seal]]\n\nBye",
"Hi,\n\n[[ircc-seal]]\n\nBye",
"Hi,\n\n[[ircc-gc-seal]]\n\nBye",
"Hi,\n\n[[ircc-ga-seal]]\n\n# Title\nBye",
"Hi,\n\n[[ircc-coat-arms]]\n\n# Title\nBye",
],
)
def test_ircc_ga_tags_in_templates_good_content(good_content: str):
def test_ircc_tags_in_templates_good_content(good_content: str):
html = get_html_email_body(good_content, {})
assert "<img" in html
assert "[[ircc" not in html

0 comments on commit 5375abd

Please sign in to comment.