Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/svn/tests/test_loader.py
Show First 20 Lines • Show All 314 Lines • ▼ Show 20 Lines | def test_load(self): | ||||
self.assertEqual(self.loader.visit_status(), "partial") | self.assertEqual(self.loader.visit_status(), "partial") | ||||
visit_status = assert_last_visit_matches( | visit_status = assert_last_visit_matches( | ||||
self.storage, self.repo_url, status="partial", type="svn" | self.storage, self.repo_url, status="partial", type="svn" | ||||
) | ) | ||||
assert visit_status.snapshot is None | 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. | """In this scenario, the repository has been updated with new changes. | ||||
The loading visit should result in new objects stored and 1 new | The loading visit should result in new objects stored and 1 new | ||||
snapshot. | snapshot. | ||||
""" | """ | ||||
archive_name = "pkg-gourmet" | |||||
def setUp(self): | archive_path = os.path.join(datadir, f"{archive_name}.tgz") | ||||
# the svn repository pkg-gourmet has been updated with changes | repo_initial_url = prepare_repository_from_archive( | ||||
super().setUp( | archive_path, archive_name, tmp_path | ||||
archive_name="pkg-gourmet-with-updates.tgz", snapshot=_LAST_SNP_REV | |||||
) | ) | ||||
def test_process_repository(self): | # repo_initial_url becomes the origin_url we want to visit some more below | ||||
"""Process updated repository should yield new objects | loader = SvnLoader(repo_initial_url) | ||||
""" | |||||
# when | |||||
assert self.loader.load() == {"status": "eventful"} | |||||
# then | |||||
# we got the previous run's last revision (rev 6) | |||||
# so 2 new | |||||
self.assertCountRevisions(5) | |||||
self.assertCountReleases(0) | |||||
last_revision = "171dc35522bfd17dda4e90a542a0377fb2fc707a" | assert loader.load() == {"status": "eventful"} | ||||
# cf. test_loader.org for explaining from where those hashes | visit_status1 = assert_last_visit_matches( | ||||
# come from | loader.storage, | ||||
expected_revisions = { | repo_initial_url, | ||||
# revision hash | directory hash | status="full", | ||||
"7f5bc909c29d4e93d8ccfdda516e51ed44930ee1": "752c52134dcbf2fff13c7be1ce4e9e5dbf428a59", # noqa | type="svn", | ||||
"38d81702cb28db4f1a6821e64321e5825d1f7fd6": "39c813fb4717a4864bacefbd90b51a3241ae4140", # noqa | snapshot=GOURMET_SNAPSHOT, | ||||
"99c27ebbd43feca179ac0e895af131d8314cafe1": "3397ca7f709639cbd36b18a0d1b70bce80018c45", # noqa | ) | ||||
"902f29b4323a9b9de3af6d28e72dd581e76d9397": "c4e12483f0a13e6851459295a4ae735eb4e4b5c4", # noqa | |||||
last_revision: "fd24a76c87a3207428e06612b49860fc78e9f6dc", # noqa | |||||
} | |||||
self.assertRevisionsContain(expected_revisions) | archive_path = os.path.join(datadir, "pkg-gourmet-with-updates.tgz") | ||||
repo_updated_url = prepare_repository_from_archive( | |||||
archive_path, "pkg-gourmet", tmp_path | |||||
) | |||||
self.assertCountSnapshots(1) | loader = SvnLoader(repo_updated_url, origin_url=repo_initial_url,) | ||||
self.assertEqual(self.loader.visit_status(), "full") | |||||
assert_last_visit_matches( | assert loader.load() == {"status": "eventful"} | ||||
self.storage, | visit_status2 = assert_last_visit_matches( | ||||
self.repo_url, | loader.storage, | ||||
repo_updated_url, | |||||
status="full", | status="full", | ||||
type="svn", | type="svn", | ||||
snapshot=GOURMET_UPDATES_SNAPSHOT, | snapshot=GOURMET_UPDATES_SNAPSHOT, | ||||
) | ) | ||||
assert visit_status1.date < visit_status2.date | |||||
assert visit_status1.snapshot != visit_status2.snapshot | |||||
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, | |||||
} | |||||
expected_snapshot = { | |||||
"id": GOURMET_UPDATES_SNAPSHOT, | |||||
"branches": { | |||||
"HEAD": { | |||||
"target": "171dc35522bfd17dda4e90a542a0377fb2fc707a", | |||||
"target_type": "revision", | |||||
} | |||||
}, | |||||
} | |||||
check_snapshot(expected_snapshot, loader.storage) | |||||
class SvnLoaderTest5(BaseSvnLoaderTest): | class SvnLoaderTest5(BaseSvnLoaderTest): | ||||
"""Context: | """Context: | ||||
- Repository already injected with successful data | - Repository already injected with successful data | ||||
- New visit from scratch done with successful load | - New visit from scratch done with successful load | ||||
""" | """ | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | def test_load(self): | ||||
self.storage, | self.storage, | ||||
self.repo_url, | self.repo_url, | ||||
status="full", | status="full", | ||||
type="svn", | type="svn", | ||||
snapshot=GOURMET_UPDATES_SNAPSHOT, | snapshot=GOURMET_UPDATES_SNAPSHOT, | ||||
) | ) | ||||
class SvnLoaderTest6(BaseSvnLoaderTest): | |||||
"""Context: | |||||
- repository already visited with load successful | |||||
- Changes on existing repository | |||||
- New Visit done with successful new data | |||||
""" | |||||
def setUp(self): | |||||
last_snp_rev = { | |||||
"snapshot": None, | |||||
"revision": { | |||||
"id": hashutil.hash_to_bytes( | |||||
"4876cb10aec6f708f7466dddf547567b65f6c39c" | |||||
), | |||||
"parents": ( | |||||
hashutil.hash_to_bytes("a3a577948fdbda9d1061913b77a1588695eadb41"), | |||||
), | |||||
"directory": hashutil.hash_to_bytes( | |||||
"0deab3023ac59398ae467fc4bff5583008af1ee2" | |||||
), | |||||
"target_type": "revision", | |||||
"metadata": { | |||||
"extra_headers": [ | |||||
[ | |||||
"svn_repo_uuid", | |||||
"3187e211-bb14-4c82-9596-0b59d67cd7f4", | |||||
], # noqa | |||||
["svn_revision", "6"], | |||||
] | |||||
}, | |||||
}, | |||||
} | |||||
super().setUp( | |||||
archive_name="pkg-gourmet-with-updates.tgz", snapshot=last_snp_rev | |||||
) | |||||
def test_load(self): | |||||
"""Load from partial previous visit result in new changes | |||||
""" | |||||
# when | |||||
assert self.loader.load() == {"status": "eventful"} | |||||
# then | |||||
# we got the previous run's last revision (rev 6) | |||||
# so 2 new | |||||
self.assertCountRevisions(5) | |||||
self.assertCountReleases(0) | |||||
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 | |||||
} | |||||
self.assertRevisionsContain(expected_revisions) | |||||
self.assertCountSnapshots(1) | |||||
self.assertEqual(self.loader.visit_status(), "full") | |||||
assert_last_visit_matches( | |||||
self.storage, | |||||
self.repo_url, | |||||
status="full", | |||||
type="svn", | |||||
snapshot=GOURMET_UPDATES_SNAPSHOT, | |||||
) | |||||
class SvnLoaderTest7(BaseSvnLoaderTest): | class SvnLoaderTest7(BaseSvnLoaderTest): | ||||
"""Context: | """Context: | ||||
- repository already visited with load successful | - repository already visited with load successful | ||||
- Changes on existing repository | - Changes on existing repository | ||||
- New Visit done with successful new data | - New Visit done with successful new data | ||||
""" | """ | ||||
▲ Show 20 Lines • Show All 521 Lines • Show Last 20 Lines |