Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/views/test_release.py
# Copyright (C) 2018-2020 The Software Heritage developers | # Copyright (C) 2018-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 hypothesis import given | from hypothesis import given | ||||
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 | from swh.web.common.utils import reverse, format_utc_iso_date | ||||
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 release, origin_with_releases, unknown_release | from swh.web.tests.strategies import release, origin_with_releases, unknown_release | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | def _release_browse_checks(resp, release_data, archive_data, origin_info=None): | ||||
assert_contains(resp, target_type) | assert_contains(resp, target_type) | ||||
assert_contains(resp, '<a href="%s">%s</a>' % (target_url, target)) | assert_contains(resp, '<a href="%s">%s</a>' % (target_url, target)) | ||||
swh_rel_id = get_swh_persistent_id("release", release_id) | swh_rel_id = get_swh_persistent_id("release", release_id) | ||||
swh_rel_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_rel_id}) | swh_rel_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_rel_id}) | ||||
assert_contains(resp, swh_rel_id) | assert_contains(resp, swh_rel_id) | ||||
assert_contains(resp, swh_rel_id_url) | assert_contains(resp, swh_rel_id_url) | ||||
if origin_info: | |||||
browse_origin_url = reverse( | |||||
"browse-origin", query_params={"origin_url": origin_info["url"]} | |||||
) | |||||
title = ( | |||||
f"Browse archived release for origin\n" | |||||
f'<a href="{browse_origin_url}">\n' | |||||
f' {origin_info["url"]}\n' | |||||
f"</a>" | |||||
) | |||||
indent = " " * 6 | |||||
else: | |||||
title = ( | |||||
f"Browse archived release\n" | |||||
f'<a href="{swh_rel_id_url}">\n' | |||||
f" {swh_rel_id}\n" | |||||
f"</a>" | |||||
) | |||||
indent = " " * 4 | |||||
assert_contains( | |||||
resp, textwrap.indent(title, indent), | |||||
) | |||||
if release_data["target_type"] == "revision": | if release_data["target_type"] == "revision": | ||||
if origin_info: | if origin_info: | ||||
directory_url = reverse( | directory_url = reverse( | ||||
"browse-origin-directory", | "browse-origin-directory", | ||||
query_params={ | query_params={ | ||||
"origin_url": origin_info["url"], | "origin_url": origin_info["url"], | ||||
"release": release_data["name"], | "release": release_data["name"], | ||||
}, | }, | ||||
) | ) | ||||
else: | else: | ||||
rev = archive_data.revision_get(release_data["target"]) | rev = archive_data.revision_get(release_data["target"]) | ||||
directory_url = reverse( | directory_url = reverse( | ||||
"browse-directory", url_args={"sha1_git": rev["directory"]} | "browse-directory", url_args={"sha1_git": rev["directory"]} | ||||
) | ) | ||||
assert_contains(resp, directory_url) | assert_contains(resp, directory_url) |