Skip to content

Commit

Permalink
squash 169
Browse files Browse the repository at this point in the history
  • Loading branch information
kalbfled committed Dec 6, 2024
1 parent 17ffb8c commit 2718324
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
4 changes: 2 additions & 2 deletions notifications_utils/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,13 @@ def hrule(md):

class NotifyHTMLRenderer(HTMLRenderer):
def link(self, text, url, title=None):
# print('LINK', text, url, title) # TODO
value = super().link(text, url, title)
# print('LINK', text, url, title, value) # TODO
return value[:3] + f'style="{LINK_STYLE}"' + value[2:]

def paragraph(self, text):
value = super().paragraph(text)
return value[:3] + f'style="{PARAGRAPH_STYLE}"' + value[2:]
return value[:2] + f' style="{PARAGRAPH_STYLE}"' + value[2:]


class NotifyMarkdownRenderer(MarkdownRenderer):
Expand Down
17 changes: 5 additions & 12 deletions tests/test_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
SMSPreviewTemplate
)

PARAGRAPH_TEXT = '<p style="Margin: 0 0 20px 0; font-size: 16px; line-height: 25px; color: #323A45;">{}</p>'
PARAGRAPH_TEXT = '<p style="Margin: 0 0 20px 0; font-size: 16px; line-height: 25px; color: #323A45;">{}</p>\n'


@pytest.mark.parametrize(
Expand All @@ -37,15 +37,11 @@
"http://www.gov.uk/",
"https://www.gov.uk/",
"http://service.gov.uk",
"http://service.gov.uk/blah.ext?q=a%20b%20c&order=desc#fragment",
pytest.param("http://service.gov.uk/blah.ext?q=one two three", marks=pytest.mark.xfail),
]
)
def test_makes_links_out_of_urls(url):
link = '<a style="word-wrap: break-word; color: #004795;" href="{}">{}</a>'.format(url, url)
assert (notify_html_markdown(url) == (
PARAGRAPH_TEXT
).format(link))
link = f'<a style="word-wrap: break-word; color: #004795;" href="{url}">{url}</a>'
assert notify_html_markdown(url) == PARAGRAPH_TEXT.format(link)


@pytest.mark.parametrize('input, output', [
Expand Down Expand Up @@ -82,13 +78,10 @@ def test_makes_links_out_of_urls_in_context(input, output):
"ftp://example.com",
"[email protected]",
"mailto:[email protected]",
"<a href=\"https://example.com\">Example</a>",
]
)
def test_doesnt_make_links_out_of_invalid_urls(url):
assert notify_html_markdown(url) == (
PARAGRAPH_TEXT
).format(url)
def test_makes_paragraphs_out_of_invalid_urls(url):
assert notify_html_markdown(url) == PARAGRAPH_TEXT.format(url)


def test_handles_placeholders_in_urls():
Expand Down

0 comments on commit 2718324

Please sign in to comment.