Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/views/test_revision.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 random | import random | ||||
import textwrap | |||||
from django.utils.html import escape | from django.utils.html import escape | ||||
from hypothesis import given | from hypothesis import given | ||||
from swh.model.identifiers import DIRECTORY, REVISION, SNAPSHOT | from swh.model.identifiers import DIRECTORY, REVISION, SNAPSHOT | ||||
from swh.web.common.identifiers import get_swh_persistent_id | from swh.web.common.identifiers import get_swh_persistent_id | ||||
from swh.web.common.utils import reverse, format_utc_iso_date, parse_timestamp | from swh.web.common.utils import reverse, format_utc_iso_date, parse_timestamp | ||||
from swh.web.tests.django_asserts import assert_contains, assert_template_used | from swh.web.tests.django_asserts import assert_contains, assert_template_used | ||||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | assert_contains( | ||||
resp, '<a class="page-link" href="%s">Newer</a>' % escape(prev_page_url) | resp, '<a class="page-link" href="%s">Newer</a>' % escape(prev_page_url) | ||||
) | ) | ||||
if len(revision_log_sorted) > 3 * per_page: | if len(revision_log_sorted) > 3 * per_page: | ||||
assert_contains( | assert_contains( | ||||
resp, '<a class="page-link" href="%s">Older</a>' % escape(next_page_url), | resp, '<a class="page-link" href="%s">Older</a>' % escape(next_page_url), | ||||
) | ) | ||||
swh_rev_id = get_swh_persistent_id(REVISION, revision) | |||||
swh_rev_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_rev_id}) | |||||
assert_contains( | |||||
resp, | |||||
textwrap.indent( | |||||
( | |||||
f"Browse archived revisions history\n" | |||||
f'<a href="{swh_rev_id_url}">\n' | |||||
f" {swh_rev_id}\n" | |||||
f"</a>" | |||||
), | |||||
" " * 4, | |||||
), | |||||
) | |||||
@given(revision(), unknown_revision(), new_origin()) | @given(revision(), unknown_revision(), new_origin()) | ||||
def test_revision_request_errors(client, revision, unknown_revision, new_origin): | def test_revision_request_errors(client, revision, unknown_revision, new_origin): | ||||
url = reverse("browse-revision", url_args={"sha1_git": unknown_revision}) | url = reverse("browse-revision", url_args={"sha1_git": unknown_revision}) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 404 | assert resp.status_code == 404 | ||||
assert_template_used(resp, "error.html") | assert_template_used(resp, "error.html") | ||||
assert_contains( | assert_contains( | ||||
▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | ): | ||||
swh_rev_id = get_swh_persistent_id(REVISION, revision) | swh_rev_id = get_swh_persistent_id(REVISION, revision) | ||||
swh_rev_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_rev_id}) | swh_rev_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_rev_id}) | ||||
if origin_url: | if origin_url: | ||||
browse_origin_url = reverse( | browse_origin_url = reverse( | ||||
"browse-origin", query_params={"origin_url": origin_url} | "browse-origin", query_params={"origin_url": origin_url} | ||||
) | ) | ||||
title = ( | assert_contains(resp, f'href="{browse_origin_url}"') | ||||
f"Browse archived revision for origin\n" | |||||
f'<a href="{browse_origin_url}">\n' | |||||
f" {origin_url}\n" | |||||
f"</a>" | |||||
) | |||||
indent = " " * 6 | |||||
elif snapshot: | elif snapshot: | ||||
swh_snp_id = get_swh_persistent_id("snapshot", snapshot["id"]) | swh_snp_id = get_swh_persistent_id("snapshot", snapshot["id"]) | ||||
swh_snp_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_snp_id}) | swh_snp_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_snp_id}) | ||||
title = ( | assert_contains(resp, f'href="{swh_snp_id_url}"') | ||||
f"Browse archived revision for snapshot\n" | |||||
f'<a href="{swh_snp_id_url}">\n' | |||||
f" {swh_snp_id}\n" | |||||
f"</a>" | |||||
) | |||||
indent = " " * 6 | |||||
else: | |||||
title = ( | |||||
f"Browse archived revision\n" | |||||
f'<a href="{swh_rev_id_url}">\n' | |||||
f" {swh_rev_id}\n" | |||||
f"</a>" | |||||
) | |||||
indent = " " * 4 | |||||
assert_contains( | |||||
resp, textwrap.indent(title, indent), | |||||
) | |||||
swhid_context = {} | swhid_context = {} | ||||
if origin_url: | if origin_url: | ||||
swhid_context["origin"] = origin_url | swhid_context["origin"] = origin_url | ||||
if snapshot: | if snapshot: | ||||
swhid_context["visit"] = get_swh_persistent_id(SNAPSHOT, snapshot["id"]) | swhid_context["visit"] = get_swh_persistent_id(SNAPSHOT, snapshot["id"]) | ||||
swh_rev_id = get_swh_persistent_id(REVISION, revision, metadata=swhid_context) | swh_rev_id = get_swh_persistent_id(REVISION, revision, metadata=swhid_context) | ||||
Show All 11 Lines |