Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/bzr/tests/test_loader.py
# Copyright (C) 2022 The Software Heritage developers | # Copyright (C) 2022 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 | ||||
from pathlib import Path | from pathlib import Path | ||||
from breezy.builtins import cmd_uncommit | from breezy.builtins import cmd_uncommit | ||||
import pytest | import pytest | ||||
import swh.loader.bzr.loader as loader_mod | |||||
from swh.loader.bzr.loader import BazaarLoader, BzrDirectory | from swh.loader.bzr.loader import BazaarLoader, BzrDirectory | ||||
from swh.loader.tests import ( | from swh.loader.tests import ( | ||||
assert_last_visit_matches, | assert_last_visit_matches, | ||||
get_stats, | get_stats, | ||||
prepare_repository_from_archive, | prepare_repository_from_archive, | ||||
) | ) | ||||
from swh.model.from_disk import Content | from swh.model.from_disk import Content | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | assert revision.to_dict() == { | ||||
(b"time_offset_seconds", b"3600"), | (b"time_offset_seconds", b"3600"), | ||||
(b"bug", b"fixed https://launchpad.net/bugs/1234"), | (b"bug", b"fixed https://launchpad.net/bugs/1234"), | ||||
(b"bug", b"fixed https://bz.example.com/?show_bug=4321"), | (b"bug", b"fixed https://bz.example.com/?show_bug=4321"), | ||||
), | ), | ||||
} | } | ||||
def test_needs_upgrade(swh_storage, datadir, tmp_path, mocker): | def test_needs_upgrade(swh_storage, datadir, tmp_path, mocker): | ||||
"""Old bzr repository format should fail the ingestion (upgrade necessary)""" | |||||
archive_path = Path(datadir, "needs-upgrade.tgz") | archive_path = Path(datadir, "needs-upgrade.tgz") | ||||
repo_url = prepare_repository_from_archive(archive_path, "needs-upgrade", tmp_path) | repo_url = prepare_repository_from_archive(archive_path, "needs-upgrade", tmp_path) | ||||
init_spy = mocker.spy(loader_mod.RepositoryNeedsUpgrade, "__init__") | |||||
init_spy.assert_not_called() | |||||
res = BazaarLoader(swh_storage, repo_url, directory=repo_url).load() | res = BazaarLoader(swh_storage, repo_url, directory=repo_url).load() | ||||
init_spy.assert_called() | |||||
assert res == {"status": "failed"} | assert res == {"status": "failed"} | ||||
def test_no_branch(swh_storage, datadir, tmp_path): | def test_no_branch(swh_storage, datadir, tmp_path): | ||||
"""This should only happen with a broken clone, so the expected result is failure""" | """This should only happen with a broken clone, so the expected result is failure""" | ||||
archive_path = Path(datadir, "no-branch.tgz") | archive_path = Path(datadir, "no-branch.tgz") | ||||
repo_url = prepare_repository_from_archive(archive_path, "no-branch", tmp_path) | repo_url = prepare_repository_from_archive(archive_path, "no-branch", tmp_path) | ||||
▲ Show 20 Lines • Show All 261 Lines • Show Last 20 Lines |