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 | |||||
from subvertpy import SubversionException | |||||
from swh.loader.svn.loader import SvnLoader, SvnLoaderFromRemoteDump | from swh.loader.svn.loader import SvnLoader, SvnLoaderFromRemoteDump | ||||
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 | ||||
Show All 15 Lines | branches={ | ||||
b"HEAD": SnapshotBranch( | b"HEAD": SnapshotBranch( | ||||
target=hash_to_bytes("171dc35522bfd17dda4e90a542a0377fb2fc707a"), | target=hash_to_bytes("171dc35522bfd17dda4e90a542a0377fb2fc707a"), | ||||
target_type=TargetType.REVISION, | target_type=TargetType.REVISION, | ||||
) | ) | ||||
}, | }, | ||||
) | ) | ||||
def test_loader_svn_not_found_no_mock(swh_config, tmp_path): | |||||
"""Given an unknown repository, the loader visit ends up in status not_found""" | |||||
unknown_repo_url = "unknown-repository" | |||||
loader = SvnLoader(unknown_repo_url, destination_path=tmp_path) | |||||
assert loader.load() == {"status": "uneventful"} | |||||
assert_last_visit_matches( | |||||
loader.storage, unknown_repo_url, status="not_found", type="svn", | |||||
) | |||||
@pytest.mark.parametrize( | |||||
"exception_msg", ["Unable to connect to a repository at URL", "Unknown URL type",] | |||||
) | |||||
def test_loader_svn_not_found(swh_config, tmp_path, exception_msg, mocker): | |||||
"""Given unknown repository issues, the loader visit ends up in status not_found""" | |||||
mock = mocker.patch("swh.loader.svn.loader.SvnRepo") | |||||
mock.side_effect = SubversionException(exception_msg, 0) | |||||
unknown_repo_url = "unknown-repository" | |||||
loader = SvnLoader(unknown_repo_url, destination_path=tmp_path) | |||||
assert loader.load() == {"status": "uneventful"} | |||||
assert_last_visit_matches( | |||||
loader.storage, unknown_repo_url, status="not_found", type="svn", | |||||
) | |||||
@pytest.mark.parametrize( | |||||
"exception", | |||||
[ | |||||
SubversionException("Irrelevant message, considered a failure", 10), | |||||
SubversionException("Present but fails to read, considered a failure", 20), | |||||
vlorentz: "somehow" | |||||
ValueError("considered a failure"), | |||||
], | |||||
) | |||||
def test_loader_svn_failures(swh_config, tmp_path, exception, mocker): | |||||
"""Given any errors raised, the loader visit ends up in status failed""" | |||||
mock = mocker.patch("swh.loader.svn.loader.SvnRepo") | |||||
mock.side_effect = exception | |||||
existing_repo_url = "existing-repo-url" | |||||
loader = SvnLoader(existing_repo_url, destination_path=tmp_path) | |||||
assert loader.load() == {"status": "failed"} | |||||
assert_last_visit_matches( | |||||
loader.storage, existing_repo_url, status="failed", type="svn", | |||||
) | |||||
def test_loader_svn_new_visit(swh_config, datadir, tmp_path): | def test_loader_svn_new_visit(swh_config, 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(repo_url, destination_path=tmp_path) | loader = SvnLoader(repo_url, destination_path=tmp_path) | ||||
▲ Show 20 Lines • Show All 581 Lines • Show Last 20 Lines |
"somehow"