Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/svn/tests/test_loader.py
# Copyright (C) 2016-2021 The Software Heritage developers | # Copyright (C) 2016-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 General Public License version 3, or any later version | # License: GNU 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 os | import os | ||||
import pytest | import pytest | ||||
from subvertpy import SubversionException | from subvertpy import SubversionException | ||||
from swh.loader.svn.loader import SvnLoader, SvnLoaderFromRemoteDump | from swh.loader.svn.loader import SvnLoader, SvnLoaderFromRemoteDump | ||||
from swh.loader.svn.utils import init_svn_repo_from_dump | |||||
from swh.loader.tests import ( | from swh.loader.tests import ( | ||||
assert_last_visit_matches, | assert_last_visit_matches, | ||||
check_snapshot, | check_snapshot, | ||||
get_stats, | get_stats, | ||||
prepare_repository_from_archive, | prepare_repository_from_archive, | ||||
) | ) | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.model.model import Snapshot, SnapshotBranch, TargetType | from swh.model.model import Snapshot, SnapshotBranch, TargetType | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | def test_loader_svnrdump_not_found(swh_storage, tmp_path, mocker): | ||||
assert loader.load() == {"status": "uneventful"} | assert loader.load() == {"status": "uneventful"} | ||||
assert_last_visit_matches( | assert_last_visit_matches( | ||||
swh_storage, unknown_repo_url, status="not_found", type="svn", | swh_storage, unknown_repo_url, status="not_found", type="svn", | ||||
) | ) | ||||
def test_loader_svnrdump_no_such_revision(swh_storage, tmp_path, datadir): | |||||
"""Visit multiple times an origin with the remote loader should not raise. | |||||
It used to fail the ingestion on the second visit with a "No such revision x, | |||||
160006" message. | |||||
""" | |||||
archive_dump = os.path.join(datadir, "penguinsdbtools2018.dump.gz") | |||||
loading_path = str(tmp_path / "loading") | |||||
# Prepare the dump as a local svn repository for test purposes | |||||
temp_dir, repo_path = init_svn_repo_from_dump( | |||||
archive_dump, root_dir=tmp_path, gzip=True | |||||
) | |||||
repo_url = f"file://{repo_path}" | |||||
loader = SvnLoaderFromRemoteDump( | |||||
swh_storage, repo_url, destination_path=loading_path | |||||
) | |||||
assert loader.load() == {"status": "eventful"} | |||||
actual_visit = assert_last_visit_matches( | |||||
swh_storage, repo_url, status="full", type="svn", | |||||
) | |||||
loader2 = SvnLoaderFromRemoteDump( | |||||
swh_storage, repo_url, destination_path=loading_path | |||||
) | |||||
# Visiting a second time the same repository should be uneventful... | |||||
assert loader2.load() == {"status": "uneventful"} | |||||
actual_visit2 = assert_last_visit_matches( | |||||
swh_storage, repo_url, status="full", type="svn", | |||||
) | |||||
assert actual_visit.snapshot is not None | |||||
# ... with the same snapshot as the first visit | |||||
assert actual_visit2.snapshot == actual_visit.snapshot | |||||
def test_loader_svn_new_visit(swh_storage, datadir, tmp_path): | def test_loader_svn_new_visit(swh_storage, datadir, tmp_path): | ||||
"""Eventful visit should yield 1 snapshot""" | """Eventful visit should yield 1 snapshot""" | ||||
archive_name = "pkg-gourmet" | archive_name = "pkg-gourmet" | ||||
archive_path = os.path.join(datadir, f"{archive_name}.tgz") | archive_path = os.path.join(datadir, f"{archive_name}.tgz") | ||||
repo_url = prepare_repository_from_archive(archive_path, archive_name, tmp_path) | repo_url = prepare_repository_from_archive(archive_path, archive_name, tmp_path) | ||||
loader = SvnLoader(swh_storage, repo_url, destination_path=tmp_path) | loader = SvnLoader(swh_storage, repo_url, destination_path=tmp_path) | ||||
▲ Show 20 Lines • Show All 587 Lines • Show Last 20 Lines |