diff --git a/swh/web/browse/views/content.py b/swh/web/browse/views/content.py --- a/swh/web/browse/views/content.py +++ b/swh/web/browse/views/content.py @@ -326,11 +326,14 @@ origin_url=origin_url, ) - swh_objects = [ - SWHObjectInfo( - object_type=ObjectType.CONTENT, object_id=content_checksums.get("sha1_git") + swh_objects = [] + if content_checksums: + swh_objects.append( + SWHObjectInfo( + object_type=ObjectType.CONTENT, + object_id=content_checksums.get("sha1_git"), + ) ) - ] if directory_id: swh_objects.append( @@ -372,7 +375,7 @@ "browse/content.html", { "heading": heading, - "swh_object_id": swhids_info[0]["swhid"], + "swh_object_id": swhids_info[0]["swhid"] if swhids_info else "", "swh_object_name": "Content", "swh_object_metadata": content_metadata, "content": content, diff --git a/swh/web/tests/browse/views/test_content.py b/swh/web/tests/browse/views/test_content.py --- a/swh/web/tests/browse/views/test_content.py +++ b/swh/web/tests/browse/views/test_content.py @@ -5,6 +5,8 @@ import random +import pytest + from django.utils.html import escape from swh.model.swhids import ObjectType @@ -315,7 +317,15 @@ 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}) check_html_get_response(client, url, status_code=400, template_used="error.html")