diff --git a/requirements-test.txt b/requirements-test.txt --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,3 +1,4 @@ pytest pytest-mock +pytest-postgresql swh.core[http] >= 0.0.61 diff --git a/swh/loader/svn/tests/conftest.py b/swh/loader/svn/tests/conftest.py --- a/swh/loader/svn/tests/conftest.py +++ b/swh/loader/svn/tests/conftest.py @@ -10,10 +10,12 @@ from typing import Any, Dict from swh.scheduler.tests.conftest import swh_app # noqa +from swh.storage.tests.conftest import * # noqa @pytest.fixture -def swh_loader_config() -> Dict[str, Any]: +def swh_loader_config(swh_storage_backend_config) -> Dict[str, Any]: + swh_storage_backend_config["journal_writer"] = {} return { "storage": { "cls": "pipeline", @@ -29,7 +31,7 @@ "release": 100, }, }, - {"cls": "memory"}, + swh_storage_backend_config, ], }, "check_revision": {"limit": 100, "status": False}, diff --git a/swh/loader/svn/tests/test_loader.py b/swh/loader/svn/tests/test_loader.py --- a/swh/loader/svn/tests/test_loader.py +++ b/swh/loader/svn/tests/test_loader.py @@ -319,56 +319,73 @@ assert visit_status.snapshot is None -class SvnLoaderTest4(BaseSvnLoaderTest): +def test_loader_svn_visit_with_changes(swh_config, datadir, tmp_path): """In this scenario, the repository has been updated with new changes. The loading visit should result in new objects stored and 1 new snapshot. """ + archive_name = "pkg-gourmet" + archive_path = os.path.join(datadir, f"{archive_name}.tgz") + repo_initial_url = prepare_repository_from_archive( + archive_path, archive_name, tmp_path + ) - def setUp(self): - # the svn repository pkg-gourmet has been updated with changes - super().setUp( - archive_name="pkg-gourmet-with-updates.tgz", snapshot=_LAST_SNP_REV - ) + # repo_initial_url becomes the origin_url we want to visit some more below + loader = SvnLoader(repo_initial_url) - def test_process_repository(self): - """Process updated repository should yield new objects + assert loader.load() == {"status": "eventful"} + visit_status1 = assert_last_visit_matches( + loader.storage, + repo_initial_url, + status="full", + type="svn", + snapshot=GOURMET_SNAPSHOT, + ) - """ - # when - assert self.loader.load() == {"status": "eventful"} + archive_path = os.path.join(datadir, "pkg-gourmet-with-updates.tgz") + repo_updated_url = prepare_repository_from_archive( + archive_path, "pkg-gourmet", tmp_path + ) - # then - # we got the previous run's last revision (rev 6) - # so 2 new - self.assertCountRevisions(5) - self.assertCountReleases(0) + loader = SvnLoader(repo_updated_url, origin_url=repo_initial_url,) - last_revision = "171dc35522bfd17dda4e90a542a0377fb2fc707a" - # cf. test_loader.org for explaining from where those hashes - # come from - expected_revisions = { - # revision hash | directory hash - "7f5bc909c29d4e93d8ccfdda516e51ed44930ee1": "752c52134dcbf2fff13c7be1ce4e9e5dbf428a59", # noqa - "38d81702cb28db4f1a6821e64321e5825d1f7fd6": "39c813fb4717a4864bacefbd90b51a3241ae4140", # noqa - "99c27ebbd43feca179ac0e895af131d8314cafe1": "3397ca7f709639cbd36b18a0d1b70bce80018c45", # noqa - "902f29b4323a9b9de3af6d28e72dd581e76d9397": "c4e12483f0a13e6851459295a4ae735eb4e4b5c4", # noqa - last_revision: "fd24a76c87a3207428e06612b49860fc78e9f6dc", # noqa - } + assert loader.load() == {"status": "eventful"} + visit_status2 = assert_last_visit_matches( + loader.storage, + repo_updated_url, + status="full", + type="svn", + snapshot=GOURMET_UPDATES_SNAPSHOT, + ) - self.assertRevisionsContain(expected_revisions) + assert visit_status1.date < visit_status2.date + assert visit_status1.snapshot != visit_status2.snapshot - self.assertCountSnapshots(1) - self.assertEqual(self.loader.visit_status(), "full") + stats = get_stats(loader.storage) + assert stats == { + "content": 22, + "directory": 28, + "origin": 1, + "origin_visit": 2, + "person": 2, + "release": 0, + "revision": 11, + "skipped_content": 0, + "snapshot": 2, + } - assert_last_visit_matches( - self.storage, - self.repo_url, - status="full", - type="svn", - snapshot=GOURMET_UPDATES_SNAPSHOT, - ) + expected_snapshot = { + "id": GOURMET_UPDATES_SNAPSHOT, + "branches": { + "HEAD": { + "target": "171dc35522bfd17dda4e90a542a0377fb2fc707a", + "target_type": "revision", + } + }, + } + + check_snapshot(expected_snapshot, loader.storage) class SvnLoaderTest5(BaseSvnLoaderTest):