Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/views/test_origin.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 | ||||
from datetime import datetime | |||||
import random | import random | ||||
import re | import re | ||||
import string | import string | ||||
from django.utils.html import escape | from django.utils.html import escape | ||||
from hypothesis import given | from hypothesis import given | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.model.model import Snapshot | from swh.model.model import ( | ||||
Snapshot, | |||||
SnapshotBranch, | |||||
TargetType, | |||||
) | |||||
from swh.web.browse.snapshot_context import process_snapshot_branches | from swh.web.browse.snapshot_context import process_snapshot_branches | ||||
from swh.web.common.exc import NotFoundExc | from swh.web.common.exc import NotFoundExc | ||||
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 ( | from swh.web.common.utils import ( | ||||
reverse, | reverse, | ||||
gen_path_info, | gen_path_info, | ||||
format_utc_iso_date, | format_utc_iso_date, | ||||
parse_timestamp, | parse_timestamp, | ||||
) | ) | ||||
from swh.web.config import get_config | from swh.web.config import get_config | ||||
from swh.web.tests.data import get_content, random_sha1 | from swh.web.tests.data import get_content, random_sha1 | ||||
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 ( | from swh.web.tests.strategies import ( | ||||
origin, | origin, | ||||
origin_with_multiple_visits, | origin_with_multiple_visits, | ||||
new_origin, | new_origin, | ||||
new_snapshot, | new_snapshot, | ||||
visit_dates, | visit_dates, | ||||
revisions, | revisions, | ||||
origin_with_releases, | origin_with_releases, | ||||
release as existing_release, | release as existing_release, | ||||
unknown_revision, | |||||
) | ) | ||||
@given(origin_with_multiple_visits()) | @given(origin_with_multiple_visits()) | ||||
def test_origin_visits_browse(client, archive_data, origin): | def test_origin_visits_browse(client, archive_data, origin): | ||||
url = reverse("browse-origin-visits", url_args={"origin_url": origin["url"]}) | url = reverse("browse-origin-visits", url_args={"origin_url": origin["url"]}) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
▲ Show 20 Lines • Show All 598 Lines • ▼ Show 20 Lines | def test_origin_release_browse_not_found(client, origin): | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 404 | assert resp.status_code == 404 | ||||
assert re.search( | assert re.search( | ||||
f"Release {invalid_release_name}.*not found", resp.content.decode("utf-8") | f"Release {invalid_release_name}.*not found", resp.content.decode("utf-8") | ||||
) | ) | ||||
@given(new_origin(), unknown_revision()) | |||||
def test_origin_browse_directory_branch_with_non_resolvable_revision( | |||||
client, archive_data, new_origin, unknown_revision | |||||
): | |||||
branch_name = "master" | |||||
snapshot = Snapshot( | |||||
branches={ | |||||
branch_name.encode(): SnapshotBranch( | |||||
target=hash_to_bytes(unknown_revision), target_type=TargetType.REVISION, | |||||
) | |||||
} | |||||
) | |||||
new_origin = archive_data.origin_add([new_origin])[0] | |||||
archive_data.snapshot_add([snapshot]) | |||||
visit = archive_data.origin_visit_add(new_origin["url"], datetime.now(), type="git") | |||||
archive_data.origin_visit_update( | |||||
new_origin["url"], visit.visit, status="full", snapshot=snapshot.id | |||||
) | |||||
url = reverse( | |||||
"browse-origin-directory", | |||||
url_args={"origin_url": new_origin["url"]}, | |||||
query_params={"branch": branch_name}, | |||||
) | |||||
resp = client.get(url) | |||||
assert resp.status_code == 200 | |||||
assert_contains( | |||||
resp, f"Revision {unknown_revision } could not be found in the archive." | |||||
) | |||||
def _origin_content_view_test_helper( | def _origin_content_view_test_helper( | ||||
client, | client, | ||||
origin_info, | origin_info, | ||||
origin_visits, | origin_visits, | ||||
origin_branches, | origin_branches, | ||||
origin_releases, | origin_releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
content, | content, | ||||
▲ Show 20 Lines • Show All 405 Lines • Show Last 20 Lines |