Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/views/test_snapshot.py
# Copyright (C) 2021 The Software Heritage developers | # Copyright (C) 2021 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 re | import re | ||||
import string | import string | ||||
from dateutil import parser | from dateutil import parser | ||||
from hypothesis import given | from hypothesis import given | ||||
import pytest | import pytest | ||||
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 ( | ||||
ObjectType, | |||||
OriginVisit, | |||||
OriginVisitStatus, | |||||
Release, | |||||
Snapshot, | |||||
SnapshotBranch, | |||||
TargetType, | |||||
) | |||||
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 | ||||
▲ Show 20 Lines • Show All 299 Lines • ▼ Show 20 Lines | |||||
def test_snapshot_content_legacy_redirect(client, snapshot): | def test_snapshot_content_legacy_redirect(client, 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("browse-snapshot-content-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("browse-content", query_params={**url_args, **qry}) | ||||
def test_browse_snapshot_log_no_revisions(client, archive_data, directory): | |||||
release_name = "v1.0.0" | |||||
release = Release( | |||||
name=release_name.encode(), | |||||
message=f"release {release_name}".encode(), | |||||
target=hash_to_bytes(directory), | |||||
target_type=ObjectType.DIRECTORY, | |||||
synthetic=True, | |||||
) | |||||
archive_data.release_add([release]) | |||||
snapshot = Snapshot( | |||||
branches={ | |||||
b"HEAD": SnapshotBranch( | |||||
target=release_name.encode(), target_type=TargetType.ALIAS | |||||
), | |||||
release_name.encode(): SnapshotBranch( | |||||
target=release.id, target_type=TargetType.RELEASE | |||||
), | |||||
}, | |||||
) | |||||
archive_data.snapshot_add([snapshot]) | |||||
url = reverse("browse-snapshot-log", url_args={"snapshot_id": snapshot.id.hex()}) | |||||
resp = check_html_get_response( | |||||
client, url, status_code=404, template_used="error.html" | |||||
) | |||||
assert_contains( | |||||
resp, | |||||
"No revisions history found in the current snapshot context.", | |||||
status_code=404, | |||||
) |