Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/views/test_directory.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, RELEASE, REVISION, SNAPSHOT | from swh.model.identifiers import DIRECTORY, RELEASE, REVISION, SNAPSHOT | ||||
from swh.web.browse.snapshot_context import process_snapshot_branches | from swh.web.browse.snapshot_context import process_snapshot_branches | ||||
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 gen_path_info, reverse | from swh.web.common.utils import gen_path_info, reverse | ||||
▲ Show 20 Lines • Show All 194 Lines • ▼ Show 20 Lines | def test_content_origin_snapshot_release_browse(client, archive_data, origin): | ||||
) | ) | ||||
assert_contains(resp, snp_swhid) | assert_contains(resp, snp_swhid) | ||||
def _check_origin_snapshot_related_html(resp, origin, snapshot, branches, releases): | def _check_origin_snapshot_related_html(resp, origin, snapshot, branches, releases): | ||||
browse_origin_url = reverse( | browse_origin_url = reverse( | ||||
"browse-origin", query_params={"origin_url": origin["url"]} | "browse-origin", query_params={"origin_url": origin["url"]} | ||||
) | ) | ||||
assert_contains( | |||||
resp, | assert_contains(resp, f'href="{browse_origin_url}"') | ||||
textwrap.indent( | |||||
( | |||||
"Browse archived directory for origin\n" | |||||
f'<a href="{browse_origin_url}">\n' | |||||
f" {origin['url']}\n" | |||||
f"</a>" | |||||
), | |||||
" " * 6, | |||||
), | |||||
) | |||||
origin_branches_url = reverse( | origin_branches_url = reverse( | ||||
"browse-origin-branches", | "browse-origin-branches", | ||||
query_params={"origin_url": origin["url"], "snapshot": snapshot["id"]}, | query_params={"origin_url": origin["url"], "snapshot": snapshot["id"]}, | ||||
) | ) | ||||
assert_contains( | assert_contains(resp, f'href="{escape(origin_branches_url)}"') | ||||
resp, | assert_contains(resp, f"Branches ({len(branches)})") | ||||
'<a href="%s">Branches (%s)</a>' % (escape(origin_branches_url), len(branches)), | |||||
) | |||||
origin_releases_url = reverse( | origin_releases_url = reverse( | ||||
"browse-origin-releases", | "browse-origin-releases", | ||||
query_params={"origin_url": origin["url"], "snapshot": snapshot["id"]}, | query_params={"origin_url": origin["url"], "snapshot": snapshot["id"]}, | ||||
) | ) | ||||
assert_contains( | assert_contains(resp, f'href="{escape(origin_releases_url)}"') | ||||
resp, | assert_contains(resp, f"Releases ({len(releases)})") | ||||
'<a href="%s">Releases (%s)</a>' % (escape(origin_releases_url), len(releases)), | |||||
) | |||||
assert_contains(resp, '<li class="swh-branch">', count=len(branches)) | assert_contains(resp, '<li class="swh-branch">', count=len(branches)) | ||||
assert_contains(resp, '<li class="swh-release">', count=len(releases)) | assert_contains(resp, '<li class="swh-release">', count=len(releases)) | ||||
def _directory_view_checks( | def _directory_view_checks( | ||||
client, | client, | ||||
root_directory_sha1, | root_directory_sha1, | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | for p in path_info: | ||||
) | ) | ||||
assert_contains(resp, '<a href="%s">%s</a>' % (dir_url, p["name"])) | assert_contains(resp, '<a href="%s">%s</a>' % (dir_url, p["name"])) | ||||
assert_contains(resp, "vault-cook-directory") | assert_contains(resp, "vault-cook-directory") | ||||
swh_dir_id = get_swh_persistent_id(DIRECTORY, directory_entries[0]["dir_id"]) | swh_dir_id = get_swh_persistent_id(DIRECTORY, directory_entries[0]["dir_id"]) | ||||
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, | |||||
textwrap.indent( | |||||
( | |||||
f"Browse archived directory\n" | |||||
f'<a href="{swh_dir_id_url}">\n' | |||||
f" {swh_dir_id}\n" | |||||
f"</a>" | |||||
), | |||||
" " * 4, | |||||
), | |||||
) | |||||
swhid_context = {} | swhid_context = {} | ||||
if root_directory_sha1 != directory_entries[0]["dir_id"]: | if root_directory_sha1 != directory_entries[0]["dir_id"]: | ||||
swhid_context["anchor"] = get_swh_persistent_id(DIRECTORY, root_directory_sha1) | swhid_context["anchor"] = get_swh_persistent_id(DIRECTORY, root_directory_sha1) | ||||
swhid_context["path"] = f"/{path}/" if path else "/" | swhid_context["path"] = f"/{path}/" if path else "/" | ||||
if root_directory_sha1 != directory_entries[0]["dir_id"]: | if root_directory_sha1 != directory_entries[0]["dir_id"]: | ||||
swhid_context["anchor"] = get_swh_persistent_id(DIRECTORY, root_directory_sha1) | swhid_context["anchor"] = get_swh_persistent_id(DIRECTORY, root_directory_sha1) | ||||
swh_dir_id = get_swh_persistent_id( | swh_dir_id = get_swh_persistent_id( | ||||
DIRECTORY, directory_entries[0]["dir_id"], metadata=swhid_context | DIRECTORY, directory_entries[0]["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) |