Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/common/test_templatetags.py
# Copyright (C) 2015-2018 The Software Heritage developers | # Copyright (C) 2015-2018 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 | ||||
from nose.tools import istest | |||||
from swh.web.common import swh_templatetags | from swh.web.common import swh_templatetags | ||||
from swh.web.tests.testcase import SWHWebTestCase | from swh.web.tests.testcase import SWHWebTestCase | ||||
class SWHTemplateTagsTest(SWHWebTestCase): | class SWHTemplateTagsTest(SWHWebTestCase): | ||||
@istest | def test_urlize_api_links_api(self): | ||||
def urlize_api_links_api(self): | |||||
# update api link with html links content with links | # update api link with html links content with links | ||||
content = '{"url": "/api/1/abc/"}' | content = '{"url": "/api/1/abc/"}' | ||||
expected_content = ('{"url": "<a href="/api/1/abc/">/api/1/abc/</a>"}') | expected_content = ('{"url": "<a href="/api/1/abc/">/api/1/abc/</a>"}') | ||||
self.assertEquals(swh_templatetags.urlize_links_and_mails(content), | self.assertEquals(swh_templatetags.urlize_links_and_mails(content), | ||||
expected_content) | expected_content) | ||||
@istest | def test_urlize_api_links_browse(self): | ||||
def urlize_api_links_browse(self): | |||||
# update /browse link with html links content with links | # update /browse link with html links content with links | ||||
content = '{"url": "/browse/def/"}' | content = '{"url": "/browse/def/"}' | ||||
expected_content = ('{"url": "<a href="/browse/def/">' | expected_content = ('{"url": "<a href="/browse/def/">' | ||||
'/browse/def/</a>"}') | '/browse/def/</a>"}') | ||||
self.assertEquals(swh_templatetags.urlize_links_and_mails(content), | self.assertEquals(swh_templatetags.urlize_links_and_mails(content), | ||||
expected_content) | expected_content) | ||||
@istest | def test_urlize_header_links(self): | ||||
def urlize_header_links(self): | |||||
# update api link with html links content with links | # update api link with html links content with links | ||||
content = """</api/1/abc/>; rel="next" | content = """</api/1/abc/>; rel="next" | ||||
</api/1/def/>; rel="prev" | </api/1/def/>; rel="prev" | ||||
""" | """ | ||||
expected_content = """<<a href="/api/1/abc/">/api/1/abc/</a>>; rel="next" | expected_content = """<<a href="/api/1/abc/">/api/1/abc/</a>>; rel="next" | ||||
<<a href="/api/1/def/">/api/1/def/</a>>; rel="prev" | <<a href="/api/1/def/">/api/1/def/</a>>; rel="prev" | ||||
""" | """ | ||||
self.assertEquals(swh_templatetags.urlize_header_links(content), | self.assertEquals(swh_templatetags.urlize_header_links(content), | ||||
expected_content) | expected_content) | ||||
@istest | def test_safe_docstring_display(self): | ||||
def safe_docstring_display(self): | |||||
# update api link with html links content with links | # update api link with html links content with links | ||||
docstring = """This is my list header: | docstring = """This is my list header: | ||||
- Here is item 1, with a continuation | - Here is item 1, with a continuation | ||||
line right here | line right here | ||||
- Here is item 2 | - Here is item 2 | ||||
Here is something that is not part of the list""" | Here is something that is not part of the list""" | ||||
Show All 12 Lines |