Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/svn/tests/test_loader.py
# Copyright (C) 2016-2020 The Software Heritage developers | # Copyright (C) 2016-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 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 copy | import copy | ||||
import os | import os | ||||
import subprocess | |||||
from typing import Optional | |||||
from swh.loader.core.tests import BaseLoaderTest | from swh.loader.core.tests import BaseLoaderTest | ||||
from swh.loader.tests.common import assert_last_visit_matches | from swh.loader.tests.common import assert_last_visit_matches | ||||
ardumont: Maybe those need to move to swh.loader.tests.common instead now... | |||||
from swh.loader.package.tests.common import check_snapshot, get_stats | |||||
from swh.loader.svn.loader import ( | from swh.loader.svn.loader import ( | ||||
DEFAULT_BRANCH, | DEFAULT_BRANCH, | ||||
SvnLoader, | SvnLoader, | ||||
SvnLoaderFromRemoteDump, | SvnLoaderFromRemoteDump, | ||||
build_swh_snapshot, | build_swh_snapshot, | ||||
) | ) | ||||
from swh.model import hashutil | from swh.model import hashutil | ||||
▲ Show 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | ): | ||||
self.svn_mirror_url, | self.svn_mirror_url, | ||||
destination_path=self.destination_path, | destination_path=self.destination_path, | ||||
start_from_scratch=start_from_scratch, | start_from_scratch=start_from_scratch, | ||||
swh_revision=swh_revision, | swh_revision=swh_revision, | ||||
) | ) | ||||
self.storage = self.loader.storage | self.storage = self.loader.storage | ||||
class SvnLoaderTest1(BaseSvnLoaderTest): | def prepare_repository_from_archive( | ||||
"""Load an unknown svn repository results in new data. | archive_path: str, filename: Optional[str] = None, tmp_path: str = "/tmp" | ||||
) -> str: | |||||
# uncompress folder/repositories/dump for the loader to ingest | |||||
subprocess.check_output(["tar", "xf", archive_path, "-C", tmp_path]) | |||||
# build the origin url (or some derivative form) | |||||
_fname = filename if filename else os.path.basename(archive_path) | |||||
repo_url = f"file://{tmp_path}/{_fname}" | |||||
Done Inline ActionsThat's coming from [1] which I intend more or less to rewrite slowly and when we need to. ardumont: That's coming from [1] which I intend more or less to rewrite slowly and when we need to.
At… | |||||
return repo_url | |||||
def test_loader_svn_new_visit(swh_config, datadir, tmp_path): | |||||
archive_name = "pkg-gourmet" | |||||
archive_path = os.path.join(datadir, f"{archive_name}.tgz") | |||||
repo_url = prepare_repository_from_archive(archive_path, archive_name, tmp_path) | |||||
""" | loader = SvnLoader(repo_url, destination_path=tmp_path) | ||||
def test_load(self): | assert loader.load() == {"status": "eventful"} | ||||
"""Load a new repository results in new swh object and snapshot | |||||
""" | assert_last_visit_matches( | ||||
# when | loader.storage, repo_url, status="full", type="svn", snapshot=GOURMET_SNAPSHOT, | ||||
assert self.loader.load() == {"status": "eventful"} | ) | ||||
# then | |||||
self.assertCountRevisions(6) | |||||
self.assertCountReleases(0) | |||||
last_revision = "4876cb10aec6f708f7466dddf547567b65f6c39c" | stats = get_stats(loader.storage) | ||||
# cf. test_loader.org for explaining from where those hashes | assert stats == { | ||||
# come from | "content": 19, | ||||
expected_revisions = { | "directory": 17, | ||||
# revision hash | directory hash | "origin": 1, | ||||
"0d7dd5f751cef8fe17e8024f7d6b0e3aac2cfd71": "669a71cce6c424a81ba42b7dc5d560d32252f0ca", # noqa | "origin_visit": 1, | ||||
"95edacc8848369d6fb1608e887d6d2474fd5224f": "008ac97a1118560797c50e3392fa1443acdaa349", # noqa | "person": 1, | ||||
"fef26ea45a520071711ba2b9d16a2985ee837021": "3780effbe846a26751a95a8c95c511fb72be15b4", # noqa | "release": 0, | ||||
"3f51abf3b3d466571be0855dfa67e094f9ceff1b": "ffcca9b09c5827a6b8137322d4339c8055c3ee1e", # noqa | "revision": 6, | ||||
"a3a577948fdbda9d1061913b77a1588695eadb41": "7dc52cc04c3b8bd7c085900d60c159f7b846f866", # noqa | "skipped_content": 0, | ||||
last_revision: "0deab3023ac59398ae467fc4bff5583008af1ee2", # noqa | "snapshot": 1, | ||||
} | } | ||||
self.assertRevisionsContain(expected_revisions) | expected_snapshot = { | ||||
self.assertCountSnapshots(1) | "id": GOURMET_SNAPSHOT, | ||||
self.assertEqual(self.loader.visit_status(), "full") | "branches": { | ||||
"HEAD": { | |||||
"target": "4876cb10aec6f708f7466dddf547567b65f6c39c", | |||||
"target_type": "revision", | |||||
} | |||||
}, | |||||
} | |||||
assert_last_visit_matches( | check_snapshot(expected_snapshot, loader.storage) | ||||
self.storage, | |||||
self.repo_url, | |||||
status="full", | |||||
type="svn", | |||||
snapshot=GOURMET_SNAPSHOT, | |||||
) | |||||
_LAST_SNP_REV = { | _LAST_SNP_REV = { | ||||
"snapshot": Snapshot.from_dict({"id": GOURMET_FLAG_SNAPSHOT, "branches": {}}), | "snapshot": Snapshot.from_dict({"id": GOURMET_FLAG_SNAPSHOT, "branches": {}}), | ||||
"revision": { | "revision": { | ||||
"id": hashutil.hash_to_bytes("4876cb10aec6f708f7466dddf547567b65f6c39c"), | "id": hashutil.hash_to_bytes("4876cb10aec6f708f7466dddf547567b65f6c39c"), | ||||
"parents": ( | "parents": ( | ||||
hashutil.hash_to_bytes("a3a577948fdbda9d1061913b77a1588695eadb41"), | hashutil.hash_to_bytes("a3a577948fdbda9d1061913b77a1588695eadb41"), | ||||
▲ Show 20 Lines • Show All 805 Lines • Show Last 20 Lines |
Maybe those need to move to swh.loader.tests.common instead now...