Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/tests/test_loader.py
Show First 20 Lines • Show All 196 Lines • ▼ Show 20 Lines | storage.extid_get_from_extid.assert_has_calls( | ||||
[ | [ | ||||
call("extid-type1", [b"extid-of-v1.0", b"extid-of-v2.0"]), | call("extid-type1", [b"extid-of-v1.0", b"extid-of-v2.0"]), | ||||
call("extid-type2", [b"extid-of-v3.0", b"extid-of-v4.0"]), | call("extid-type2", [b"extid-of-v3.0", b"extid-of-v4.0"]), | ||||
], | ], | ||||
any_order=True, | any_order=True, | ||||
) | ) | ||||
def test_load_skip_extids() -> None: | def test_load_extids() -> None: | ||||
"""Checks PackageLoader.load() skips iff it should.""" | """Checks PackageLoader.load() skips iff it should, and writes (only) | ||||
the new ExtIDs""" | |||||
storage = get_storage("memory") | storage = get_storage("memory") | ||||
origin = "http://example.org" | origin = "http://example.org" | ||||
rev1_swhid = CoreSWHID(object_type=ObjectType.REVISION, object_id=b"a" * 20) | rev1_swhid = CoreSWHID(object_type=ObjectType.REVISION, object_id=b"a" * 20) | ||||
rev2_swhid = CoreSWHID(object_type=ObjectType.REVISION, object_id=b"b" * 20) | rev2_swhid = CoreSWHID(object_type=ObjectType.REVISION, object_id=b"b" * 20) | ||||
rev3_swhid = CoreSWHID(object_type=ObjectType.REVISION, object_id=b"c" * 20) | rev3_swhid = CoreSWHID(object_type=ObjectType.REVISION, object_id=b"c" * 20) | ||||
rev4_swhid = CoreSWHID(object_type=ObjectType.REVISION, object_id=b"d" * 20) | rev4_swhid = CoreSWHID(object_type=ObjectType.REVISION, object_id=b"d" * 20) | ||||
dir_swhid = CoreSWHID(object_type=ObjectType.DIRECTORY, object_id=b"e" * 20) | dir_swhid = CoreSWHID(object_type=ObjectType.DIRECTORY, object_id=b"e" * 20) | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | snapshot = Snapshot( | ||||
), | ), | ||||
b"branch-v4.0": SnapshotBranch( | b"branch-v4.0": SnapshotBranch( | ||||
target_type=TargetType.REVISION, target=rev4_swhid.object_id | target_type=TargetType.REVISION, target=rev4_swhid.object_id | ||||
), | ), | ||||
} | } | ||||
) | ) | ||||
assert snapshot_get_latest(storage, origin) == snapshot | assert snapshot_get_latest(storage, origin) == snapshot | ||||
extids = storage.extid_get_from_target( | |||||
ObjectType.REVISION, | |||||
[ | |||||
rev1_swhid.object_id, | |||||
rev2_swhid.object_id, | |||||
rev3_swhid.object_id, | |||||
rev4_swhid.object_id, | |||||
], | |||||
) | |||||
assert set(extids) == { | |||||
# What we inserted at the beginning of the test: | |||||
ExtID("extid-type1", b"extid-of-v1.0", rev1_swhid), | |||||
ExtID("extid-type2", b"extid-of-v2.0", rev2_swhid), | |||||
# Added by the loader: | |||||
ExtID("extid-type1", b"extid-of-v2.0", rev4_swhid), | |||||
ExtID("extid-type2", b"extid-of-v3.0", rev4_swhid), | |||||
ExtID("extid-type2", b"extid-of-v4.0", rev4_swhid), | |||||
} | |||||
def test_manifest_extid(): | def test_manifest_extid(): | ||||
"""Compute primary key should return the right identity | """Compute primary key should return the right identity | ||||
""" | """ | ||||
@attr.s | @attr.s | ||||
class TestPackageInfo(BasePackageInfo): | class TestPackageInfo(BasePackageInfo): | ||||
Show All 37 Lines |