Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/views/test_content.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 textwrap | |||||
from django.utils.html import escape | from django.utils.html import escape | ||||
from hypothesis import given | from hypothesis import given | ||||
from swh.web.browse.utils import ( | from swh.web.browse.utils import ( | ||||
get_mimetype_and_encoding_for_content, | get_mimetype_and_encoding_for_content, | ||||
prepare_content_for_display, | prepare_content_for_display, | ||||
_re_encode_content, | _re_encode_content, | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | if mimetype.startswith("text/"): | ||||
assert_contains(resp, '<code class="%s">' % content_display["language"]) | assert_contains(resp, '<code class="%s">' % content_display["language"]) | ||||
assert_contains(resp, escape(content_display["content_data"])) | assert_contains(resp, escape(content_display["content_data"])) | ||||
assert_contains(resp, url_raw) | assert_contains(resp, url_raw) | ||||
swh_cnt_id = get_swh_persistent_id("content", sha1_git) | swh_cnt_id = get_swh_persistent_id("content", sha1_git) | ||||
swh_cnt_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_cnt_id}) | swh_cnt_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_cnt_id}) | ||||
assert_contains(resp, swh_cnt_id) | assert_contains(resp, swh_cnt_id) | ||||
assert_contains(resp, swh_cnt_id_url) | assert_contains(resp, swh_cnt_id_url) | ||||
assert_contains( | |||||
resp, | |||||
textwrap.indent( | |||||
( | |||||
f"Browse archived content\n" | |||||
f'<a href="{swh_cnt_id_url}">\n' | |||||
f" {swh_cnt_id}\n" | |||||
f"</a>" | |||||
), | |||||
" " * 4, | |||||
), | |||||
) | |||||
@given(content_text_no_highlight()) | @given(content_text_no_highlight()) | ||||
def test_content_view_text_no_highlight(client, archive_data, content): | def test_content_view_text_no_highlight(client, archive_data, content): | ||||
sha1_git = content["sha1_git"] | sha1_git = content["sha1_git"] | ||||
url = reverse("browse-content", url_args={"query_string": content["sha1"]}) | url = reverse("browse-content", url_args={"query_string": content["sha1"]}) | ||||
▲ Show 20 Lines • Show All 319 Lines • Show Last 20 Lines |