Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/common/test_templatetags.py
# Copyright (C) 2015-2019 The Software Heritage developers | # Copyright (C) 2015-2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import pytest | |||||
from swh.web.common.swh_templatetags import ( | from swh.web.common.swh_templatetags import ( | ||||
urlize_links_and_mails, urlize_header_links, safe_docstring_display | urlize_links_and_mails, urlize_header_links, safe_docstring_display | ||||
) | ) | ||||
def test_urlize_http_link(): | def test_urlize_http_link(): | ||||
link = 'https://example.com/api/1/abc/' | link = 'https://example.com/api/1/abc/' | ||||
expected_content = f'<a href="{link}">{link}</a>' | expected_content = f'<a href="{link}">{link}</a>' | ||||
Show All 17 Lines | def test_urlize_header_links(): | ||||
expected_content = ( | expected_content = ( | ||||
f'<<a href="{next_link}">{next_link}</a>>; rel="next"\n' | f'<<a href="{next_link}">{next_link}</a>>; rel="next"\n' | ||||
f'<<a href="{prev_link}">{prev_link}</a>>; rel="prev"') | f'<<a href="{prev_link}">{prev_link}</a>>; rel="prev"') | ||||
assert urlize_header_links(content) == expected_content | assert urlize_header_links(content) == expected_content | ||||
# remove deprecation warnings related to docutils | |||||
@pytest.mark.filterwarnings( | |||||
'ignore:.*U.*mode is deprecated:DeprecationWarning') | |||||
def test_safe_docstring_display(): | def test_safe_docstring_display(): | ||||
# update api link with html links content with links | # update api link with html links content with links | ||||
docstring = ( | docstring = ( | ||||
'This is my list header:\n\n' | 'This is my list header:\n\n' | ||||
' - Here is item 1, with a continuation\n' | ' - Here is item 1, with a continuation\n' | ||||
' line right here\n' | ' line right here\n' | ||||
' - Here is item 2\n\n' | ' - Here is item 2\n\n' | ||||
' Here is something that is not part of the list' | ' Here is something that is not part of the list' | ||||
) | ) | ||||
expected_docstring = ( | expected_docstring = ( | ||||
'<div class="swh-rst">' | |||||
'<p>This is my list header:</p>\n' | '<p>This is my list header:</p>\n' | ||||
'<ul class="docstring">\n' | '<ul class="simple">\n' | ||||
'<li>Here is item 1, with a continuation\n' | '<li><p>Here is item 1, with a continuation\n' | ||||
'line right here</li>\n' | 'line right here</p></li>\n' | ||||
'<li>Here is item 2</li>\n' | '<li><p>Here is item 2</p></li>\n' | ||||
'</ul>\n' | '</ul>\n' | ||||
'<p>Here is something that is not part of the list</p>\n' | '<p>Here is something that is not part of the list</p>\n' | ||||
'</div>' | |||||
) | ) | ||||
assert safe_docstring_display(docstring) == expected_docstring | assert safe_docstring_display(docstring) == expected_docstring |