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 | ||||
import pytest | |||||
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, | ||||
▲ Show 20 Lines • Show All 294 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 | ||||
def test_content_request_errors(client, invalid_sha1, unknown_content): | @pytest.mark.django_db | ||||
@pytest.mark.parametrize("staff_user_logged_in", [False, True]) | |||||
def test_content_request_errors( | |||||
client, staff_user, invalid_sha1, unknown_content, staff_user_logged_in | |||||
): | |||||
if staff_user_logged_in: | |||||
client.force_login(staff_user) | |||||
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 297 Lines • Show Last 20 Lines |