Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/test_snapshot_context.py
# Copyright (C) 2020-2021 The Software Heritage developers | # Copyright (C) 2020-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 | ||||
from hypothesis import given | |||||
from swh.model.swhids import ObjectType | from swh.model.swhids import ObjectType | ||||
from swh.web.browse.snapshot_context import ( | from swh.web.browse.snapshot_context import ( | ||||
_get_release, | _get_release, | ||||
get_origin_visit_snapshot, | get_origin_visit_snapshot, | ||||
get_snapshot_content, | get_snapshot_content, | ||||
get_snapshot_context, | get_snapshot_context, | ||||
) | ) | ||||
from swh.web.browse.utils import gen_revision_url | from swh.web.browse.utils import gen_revision_url | ||||
from swh.web.common.identifiers import gen_swhid | from swh.web.common.identifiers import gen_swhid | ||||
from swh.web.common.origin_visits import get_origin_visit, get_origin_visits | from swh.web.common.origin_visits import get_origin_visit, get_origin_visits | ||||
from swh.web.common.typing import ( | from swh.web.common.typing import ( | ||||
SnapshotBranchInfo, | SnapshotBranchInfo, | ||||
SnapshotContext, | SnapshotContext, | ||||
SnapshotReleaseInfo, | SnapshotReleaseInfo, | ||||
) | ) | ||||
from swh.web.common.utils import format_utc_iso_date, reverse | from swh.web.common.utils import format_utc_iso_date, reverse | ||||
from swh.web.tests.strategies import snapshot | |||||
def test_get_origin_visit_snapshot_simple(archive_data, origin_with_multiple_visits): | def test_get_origin_visit_snapshot_simple(archive_data, origin_with_multiple_visits): | ||||
visits = archive_data.origin_visit_get(origin_with_multiple_visits["url"]) | visits = archive_data.origin_visit_get(origin_with_multiple_visits["url"]) | ||||
for visit in visits: | for visit in visits: | ||||
snapshot = archive_data.snapshot_get(visit["snapshot"]) | snapshot = archive_data.snapshot_get(visit["snapshot"]) | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | for visit in visits: | ||||
origin_visit_branches = get_origin_visit_snapshot( | origin_visit_branches = get_origin_visit_snapshot( | ||||
origin_with_multiple_visits, visit_id=visit["visit"] | origin_with_multiple_visits, visit_id=visit["visit"] | ||||
) | ) | ||||
assert origin_visit_branches == (branches, releases, aliases) | assert origin_visit_branches == (branches, releases, aliases) | ||||
@given(snapshot()) | |||||
def test_get_snapshot_context_no_origin(archive_data, snapshot): | def test_get_snapshot_context_no_origin(archive_data, snapshot): | ||||
for browse_context, kwargs in ( | for browse_context, kwargs in ( | ||||
("content", {"snapshot_id": snapshot, "path": "/some/path"}), | ("content", {"snapshot_id": snapshot, "path": "/some/path"}), | ||||
("directory", {"snapshot_id": snapshot}), | ("directory", {"snapshot_id": snapshot}), | ||||
("log", {"snapshot_id": snapshot}), | ("log", {"snapshot_id": snapshot}), | ||||
): | ): | ||||
▲ Show 20 Lines • Show All 312 Lines • Show Last 20 Lines |