Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/views/test_content.py
# Copyright (C) 2017-2021 The Software Heritage developers | # Copyright (C) 2017-2021 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 random | import random | ||||
from hypothesis import given | |||||
from django.utils.html import escape | from django.utils.html import escape | ||||
from swh.model.swhids import ObjectType | from swh.model.swhids import ObjectType | ||||
from swh.web.browse.snapshot_context import process_snapshot_branches | from swh.web.browse.snapshot_context import process_snapshot_branches | ||||
from swh.web.browse.utils import ( | from swh.web.browse.utils import ( | ||||
_re_encode_content, | _re_encode_content, | ||||
get_mimetype_and_encoding_for_content, | get_mimetype_and_encoding_for_content, | ||||
prepare_content_for_display, | prepare_content_for_display, | ||||
) | ) | ||||
from swh.web.common.exc import NotFoundExc | from swh.web.common.exc import NotFoundExc | ||||
from swh.web.common.identifiers import gen_swhid | from swh.web.common.identifiers import gen_swhid | ||||
from swh.web.common.utils import gen_path_info, reverse | from swh.web.common.utils import gen_path_info, reverse | ||||
from swh.web.tests.django_asserts import assert_contains, assert_not_contains | from swh.web.tests.django_asserts import assert_contains, assert_not_contains | ||||
from swh.web.tests.strategies import invalid_sha1, unknown_content | |||||
from swh.web.tests.utils import check_html_get_response, check_http_get_response | from swh.web.tests.utils import check_html_get_response, check_http_get_response | ||||
def test_content_view_text(client, archive_data, content_text): | def test_content_view_text(client, archive_data, content_text): | ||||
sha1_git = content_text["sha1_git"] | sha1_git = content_text["sha1_git"] | ||||
url = reverse( | url = reverse( | ||||
"browse-content", | "browse-content", | ||||
▲ Show 20 Lines • Show All 281 Lines • ▼ Show 20 Lines | resp = check_http_get_response( | ||||
client, url, status_code=200, content_type="application/octet-stream" | client, url, status_code=200, content_type="application/octet-stream" | ||||
) | ) | ||||
assert resp["Content-Type"] == "application/octet-stream" | assert resp["Content-Type"] == "application/octet-stream" | ||||
assert resp["Content-disposition"] == "attachment; filename=%s" % filename | assert resp["Content-disposition"] == "attachment; filename=%s" % filename | ||||
assert resp.content == content_data | assert resp.content == content_data | ||||
@given(invalid_sha1(), unknown_content()) | |||||
def test_content_request_errors(client, invalid_sha1, unknown_content): | def test_content_request_errors(client, invalid_sha1, unknown_content): | ||||
url = reverse("browse-content", url_args={"query_string": invalid_sha1}) | url = reverse("browse-content", url_args={"query_string": invalid_sha1}) | ||||
check_html_get_response(client, url, status_code=400, template_used="error.html") | check_html_get_response(client, url, status_code=400, template_used="error.html") | ||||
url = reverse("browse-content", url_args={"query_string": unknown_content["sha1"]}) | url = reverse("browse-content", url_args={"query_string": unknown_content["sha1"]}) | ||||
check_html_get_response( | check_html_get_response( | ||||
client, url, status_code=404, template_used="browse/content.html" | client, url, status_code=404, template_used="browse/content.html" | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 298 Lines • Show Last 20 Lines |