Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/views/test_snapshot.py
Show All 13 Lines | |||||
from django.utils.html import escape | from django.utils.html import escape | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.model.model import OriginVisit, OriginVisitStatus, Snapshot | from swh.model.model import OriginVisit, OriginVisitStatus, Snapshot | ||||
from swh.storage.utils import now | from swh.storage.utils import now | ||||
from swh.web.browse.snapshot_context import process_snapshot_branches | from swh.web.browse.snapshot_context import process_snapshot_branches | ||||
from swh.web.common.utils import reverse | from swh.web.common.utils import reverse | ||||
from swh.web.tests.data import random_sha1 | from swh.web.tests.data import random_sha1 | ||||
from swh.web.tests.django_asserts import assert_contains, assert_not_contains | from swh.web.tests.django_asserts import assert_contains # , assert_not_contains | ||||
from swh.web.tests.strategies import new_origin, visit_dates | from swh.web.tests.strategies import new_origin, visit_dates | ||||
from swh.web.tests.utils import check_html_get_response | from swh.web.tests.utils import check_html_get_response | ||||
@pytest.mark.parametrize( | @pytest.mark.parametrize( | ||||
"browse_context,template_used", | "browse_context,template_used", | ||||
[ | [ | ||||
("log", "revision-log.html"), | ("log", "revision-log.html"), | ||||
▲ Show 20 Lines • Show All 189 Lines • ▼ Show 20 Lines | ): | ||||
) | ) | ||||
resp = check_html_get_response( | resp = check_html_get_response( | ||||
client, url, status_code=200, template_used="browse/branches.html" | client, url, status_code=200, template_used="browse/branches.html" | ||||
) | ) | ||||
assert_contains(resp, '<ul class="pagination') | assert_contains(resp, '<ul class="pagination') | ||||
def test_pull_request_branches_filtering( | |||||
client, origin_with_pull_request_branches, archive_data | |||||
): | |||||
origin_url = origin_with_pull_request_branches.url | |||||
# check no pull request branches are displayed in the Branches / Releases dropdown | |||||
url = reverse("browse-origin-directory", query_params={"origin_url": origin_url}) | |||||
resp = check_html_get_response( | |||||
client, url, status_code=200, template_used="browse/directory.html" | |||||
) | |||||
assert_not_contains(resp, "refs/pull/") | |||||
snapshot = archive_data.snapshot_get_latest(origin_url) | |||||
# check no pull request branches are displayed in the branches view | |||||
url = reverse( | |||||
"browse-snapshot-branches", | |||||
url_args={"snapshot_id": snapshot["id"]}, | |||||
query_params={"origin_url": origin_url}, | |||||
) | |||||
resp = check_html_get_response( | |||||
client, url, status_code=200, template_used="browse/branches.html" | |||||
) | |||||
assert_not_contains(resp, "refs/pull/") | |||||
def test_snapshot_browse_releases(client, archive_data, origin): | def test_snapshot_browse_releases(client, archive_data, origin): | ||||
origin_visits = archive_data.origin_visit_get(origin["url"]) | origin_visits = archive_data.origin_visit_get(origin["url"]) | ||||
visit = origin_visits[-1] | visit = origin_visits[-1] | ||||
snapshot = archive_data.snapshot_get(visit["snapshot"]) | snapshot = archive_data.snapshot_get(visit["snapshot"]) | ||||
snapshot_sizes = archive_data.snapshot_count_branches(snapshot["id"]) | snapshot_sizes = archive_data.snapshot_count_branches(snapshot["id"]) | ||||
snapshot_content = process_snapshot_branches(snapshot) | snapshot_content = process_snapshot_branches(snapshot) | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | for release in origin_releases: | ||||
) | ) | ||||
assert_contains(resp, '<a href="%s">' % escape(browse_release_url)) | assert_contains(resp, '<a href="%s">' % escape(browse_release_url)) | ||||
assert_contains(resp, '<a href="%s">' % escape(browse_revision_url)) | assert_contains(resp, '<a href="%s">' % escape(browse_revision_url)) | ||||
_check_origin_link(resp, origin_info["url"]) | _check_origin_link(resp, origin_info["url"]) | ||||
def test_snapshot_content_redirect(client, snapshot): | @pytest.mark.parametrize("browse_context", ["content", "directory"]) | ||||
def test_snapshot_content_redirect(client, browse_context, snapshot): | |||||
qry = {"extra-arg": "extra"} | qry = {"extra-arg": "extra"} | ||||
url = reverse( | url = reverse( | ||||
"browse-snapshot-content", url_args={"snapshot_id": snapshot}, query_params=qry | f"browse-snapshot-{browse_context}", | ||||
url_args={"snapshot_id": snapshot}, | |||||
query_params=qry, | |||||
) | ) | ||||
resp = check_html_get_response(client, url, status_code=301) | resp = check_html_get_response(client, url, status_code=301) | ||||
assert resp.url == reverse( | assert resp.url == reverse( | ||||
"browse-content", query_params={**{"snapshot_id": snapshot}, **qry} | f"browse-{browse_context}", query_params={**{"snapshot_id": snapshot}, **qry} | ||||
) | ) | ||||
def test_snapshot_content_legacy_redirect(client, snapshot): | @pytest.mark.parametrize("browse_context", ["content", "directory"]) | ||||
def test_snapshot_content_legacy_redirect(client, browse_context, snapshot): | |||||
qry = {"extra-arg": "extra"} | qry = {"extra-arg": "extra"} | ||||
url_args = {"snapshot_id": snapshot, "path": "test.txt"} | url_args = {"snapshot_id": snapshot, "path": "test.txt"} | ||||
url = reverse("browse-snapshot-content-legacy", url_args=url_args, query_params=qry) | url = reverse( | ||||
f"browse-snapshot-{browse_context}-legacy", url_args=url_args, query_params=qry | |||||
) | |||||
resp = check_html_get_response(client, url, status_code=301) | resp = check_html_get_response(client, url, status_code=301) | ||||
assert resp.url == reverse("browse-content", query_params={**url_args, **qry}) | assert resp.url == reverse( | ||||
f"browse-{browse_context}", query_params={**url_args, **qry} | |||||
) |