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 textwrap | 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.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 | ||||
from swh.web.tests.strategies import origin, revision, unknown_revision, new_origin | from swh.web.tests.strategies import origin, revision, unknown_revision, new_origin | ||||
@given(revision()) | @given(revision()) | ||||
def test_revision_browse(client, archive_data, revision): | def test_revision_browse(client, archive_data, revision): | ||||
Show All 27 Lines | def test_revision_browse(client, archive_data, revision): | ||||
message_lines = revision_data["message"].split("\n") | message_lines = revision_data["message"].split("\n") | ||||
assert_contains(resp, format_utc_iso_date(author_date)) | assert_contains(resp, format_utc_iso_date(author_date)) | ||||
assert_contains(resp, format_utc_iso_date(committer_date)) | assert_contains(resp, format_utc_iso_date(committer_date)) | ||||
assert_contains(resp, escape(message_lines[0])) | assert_contains(resp, escape(message_lines[0])) | ||||
assert_contains(resp, escape("\n".join(message_lines[1:]))) | assert_contains(resp, escape("\n".join(message_lines[1:]))) | ||||
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}) | ||||
assert_contains( | assert_contains( | ||||
resp, | resp, | ||||
textwrap.indent( | textwrap.indent( | ||||
( | ( | ||||
f"Browse archived revision\n" | f"Browse archived revision\n" | ||||
f'<a href="{swh_rev_id_url}">\n' | f'<a href="{swh_rev_id_url}">\n' | ||||
f" {swh_rev_id}\n" | f" {swh_rev_id}\n" | ||||
f"</a>" | f"</a>" | ||||
), | ), | ||||
" " * 4, | " " * 4, | ||||
), | ), | ||||
) | ) | ||||
swhid_context = {"anchor": swh_rev_id, "path": "/"} | |||||
swh_dir_id = get_swh_persistent_id(DIRECTORY, dir_id, metadata=swhid_context) | |||||
swh_dir_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_dir_id}) | |||||
assert_contains(resp, swh_dir_id) | |||||
assert_contains(resp, swh_dir_id_url) | |||||
@given(origin()) | @given(origin()) | ||||
def test_revision_origin_browse(client, archive_data, origin): | def test_revision_origin_browse(client, archive_data, origin): | ||||
snapshot = archive_data.snapshot_get_latest(origin["url"]) | snapshot = archive_data.snapshot_get_latest(origin["url"]) | ||||
revision = archive_data.snapshot_get_head(snapshot) | revision = archive_data.snapshot_get_head(snapshot) | ||||
revision_data = archive_data.revision_get(revision) | revision_data = archive_data.revision_get(revision) | ||||
dir_id = revision_data["directory"] | dir_id = revision_data["directory"] | ||||
Show All 18 Lines | for parent in revision_data["parents"]: | ||||
url_args={"sha1_git": parent}, | url_args={"sha1_git": parent}, | ||||
query_params={"origin_url": origin["url"]}, | query_params={"origin_url": origin["url"]}, | ||||
) | ) | ||||
assert_contains(resp, '<a href="%s">%s</a>' % (parent_url, parent[:7])) | assert_contains(resp, '<a href="%s">%s</a>' % (parent_url, parent[:7])) | ||||
assert_contains(resp, "vault-cook-directory") | assert_contains(resp, "vault-cook-directory") | ||||
assert_contains(resp, "vault-cook-revision") | assert_contains(resp, "vault-cook-revision") | ||||
swh_rev_id = get_swh_persistent_id("revision", revision) | swhid_context = { | ||||
"origin": origin["url"], | |||||
"visit": get_swh_persistent_id(SNAPSHOT, snapshot["id"]), | |||||
} | |||||
swh_rev_id = get_swh_persistent_id(REVISION, revision, metadata=swhid_context) | |||||
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}) | ||||
assert_contains(resp, swh_rev_id) | assert_contains(resp, swh_rev_id) | ||||
assert_contains(resp, swh_rev_id_url) | assert_contains(resp, swh_rev_id_url) | ||||
swh_dir_id = get_swh_persistent_id("directory", dir_id) | swhid_context["anchor"] = get_swh_persistent_id(REVISION, revision) | ||||
swhid_context["path"] = "/" | |||||
swh_dir_id = get_swh_persistent_id(DIRECTORY, dir_id, metadata=swhid_context) | |||||
swh_dir_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_dir_id}) | swh_dir_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_dir_id}) | ||||
assert_contains(resp, swh_dir_id) | assert_contains(resp, swh_dir_id) | ||||
assert_contains(resp, swh_dir_id_url) | assert_contains(resp, swh_dir_id_url) | ||||
assert_contains(resp, "swh-take-new-snapshot") | assert_contains(resp, "swh-take-new-snapshot") | ||||
@given(revision()) | @given(revision()) | ||||
▲ Show 20 Lines • Show All 104 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 = 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}) | ||||
assert_contains( | assert_contains( | ||||
resp, | resp, | ||||
textwrap.indent( | textwrap.indent( | ||||
( | ( | ||||
f"Browse archived revisions history\n" | f"Browse archived revisions history\n" | ||||
f'<a href="{swh_rev_id_url}">\n' | f'<a href="{swh_rev_id_url}">\n' | ||||
▲ Show 20 Lines • Show All 44 Lines • Show Last 20 Lines |