Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/common/test_utils.py
# Copyright (C) 2017-2020 The Software Heritage developers | # Copyright (C) 2017-2020 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 datetime | import datetime | ||||
from urllib.parse import quote | from urllib.parse import quote | ||||
import docutils | |||||
from pkg_resources import parse_version | |||||
import pytest | import pytest | ||||
from django.conf.urls import url | from django.conf.urls import url | ||||
from django.test.utils import override_settings | from django.test.utils import override_settings | ||||
from django.urls.exceptions import NoReverseMatch | from django.urls.exceptions import NoReverseMatch | ||||
from swh.web.common import utils | from swh.web.common import utils | ||||
from swh.web.common.exc import BadInputExc | from swh.web.common.exc import BadInputExc | ||||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | rst = ( | ||||
"\n" | "\n" | ||||
"1. This is a numbered list.\n" | "1. This is a numbered list.\n" | ||||
"2. It has two items too.\n" | "2. It has two items too.\n" | ||||
"\n" | "\n" | ||||
"#. This is a numbered list.\n" | "#. This is a numbered list.\n" | ||||
"#. It has two items too.\n" | "#. It has two items too.\n" | ||||
) | ) | ||||
if parse_version(docutils.__version__) >= parse_version("0.17"): | |||||
(section_open, section_close) = ("section", "section") | |||||
else: | |||||
(section_open, section_close) = ('div class="section"', "div") | |||||
expected_html = ( | expected_html = ( | ||||
'<div class="swh-rst"><h1 class="title">Section</h1>\n' | f'<div class="swh-rst"><h1 class="title">Section</h1>\n' | ||||
"<p><strong>Some strong text</strong></p>\n" | f"<p><strong>Some strong text</strong></p>\n" | ||||
'<div class="section" id="subsection">\n' | f'<{section_open} id="subsection">\n' | ||||
"<h2>Subsection</h2>\n" | f"<h2>Subsection</h2>\n" | ||||
'<ul class="simple">\n' | f'<ul class="simple">\n' | ||||
"<li><p>This is a bulleted list.</p></li>\n" | f"<li><p>This is a bulleted list.</p></li>\n" | ||||
"<li><p>It has two items, the second\n" | f"<li><p>It has two items, the second\n" | ||||
"item uses two lines.</p></li>\n" | f"item uses two lines.</p></li>\n" | ||||
"</ul>\n" | f"</ul>\n" | ||||
'<ol class="arabic simple">\n' | f'<ol class="arabic simple">\n' | ||||
"<li><p>This is a numbered list.</p></li>\n" | f"<li><p>This is a numbered list.</p></li>\n" | ||||
"<li><p>It has two items too.</p></li>\n" | f"<li><p>It has two items too.</p></li>\n" | ||||
"<li><p>This is a numbered list.</p></li>\n" | f"<li><p>This is a numbered list.</p></li>\n" | ||||
"<li><p>It has two items too.</p></li>\n" | f"<li><p>It has two items too.</p></li>\n" | ||||
"</ol>\n" | f"</ol>\n" | ||||
"</div>\n" | f"</{section_close}>\n" | ||||
"</div>" | f"</div>" | ||||
) | ) | ||||
assert utils.rst_to_html(rst) == expected_html | assert utils.rst_to_html(rst) == expected_html | ||||
def sample_test_view(request, string, number): | def sample_test_view(request, string, number): | ||||
pass | pass | ||||
▲ Show 20 Lines • Show All 85 Lines • Show Last 20 Lines |