Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/storage_tests.py
Show First 20 Lines • Show All 554 Lines • ▼ Show 20 Lines | def test_content_missing_per_sha1_git(self, swh_storage, sample_data): | ||||
contents = [ | contents = [ | ||||
cont.sha1_git, | cont.sha1_git, | ||||
cont2.sha1_git, | cont2.sha1_git, | ||||
missing_cont.sha1_git, | missing_cont.sha1_git, | ||||
missing_cont2.sha1_git, | missing_cont2.sha1_git, | ||||
] | ] | ||||
missing_contents = swh_storage.content_missing_per_sha1_git(contents) | missing_contents = swh_storage.content_missing_per_sha1_git(contents) | ||||
assert list(missing_contents) == [missing_cont.sha1_git, missing_cont2.sha1_git] | assert set(missing_contents) == {missing_cont.sha1_git, missing_cont2.sha1_git} | ||||
douardda: what do we lose with these unsorted comparisions? can this be a problem? | |||||
vlorentzAuthorUnsubmitted Done Inline Actionsnothing, this was already not guaranteed, and only worked in tests accidentally vlorentz: nothing, this was already not guaranteed, and only worked in tests accidentally | |||||
missing_contents = swh_storage.content_missing_per_sha1_git([]) | missing_contents = swh_storage.content_missing_per_sha1_git([]) | ||||
assert list(missing_contents) == [] | assert list(missing_contents) == [] | ||||
def test_content_get_partition(self, swh_storage, swh_contents): | def test_content_get_partition(self, swh_storage, swh_contents): | ||||
"""content_get_partition paginates results if limit exceeded""" | """content_get_partition paginates results if limit exceeded""" | ||||
expected_contents = [ | expected_contents = [ | ||||
attr.evolve(c, data=None) for c in swh_contents if c.status != "absent" | attr.evolve(c, data=None) for c in swh_contents if c.status != "absent" | ||||
▲ Show 20 Lines • Show All 805 Lines • ▼ Show 20 Lines | def test_extid_add_git(self, swh_storage, sample_data): | ||||
] | ] | ||||
assert swh_storage.extid_get_from_extid("git", gitids) == [] | assert swh_storage.extid_get_from_extid("git", gitids) == [] | ||||
assert swh_storage.extid_get_from_target(ObjectType.REVISION, gitids) == [] | assert swh_storage.extid_get_from_target(ObjectType.REVISION, gitids) == [] | ||||
summary = swh_storage.extid_add(extids) | summary = swh_storage.extid_add(extids) | ||||
assert summary == {"extid:add": len(gitids)} | assert summary == {"extid:add": len(gitids)} | ||||
assert swh_storage.extid_get_from_extid("git", gitids) == extids | assert set(swh_storage.extid_get_from_extid("git", gitids)) == set(extids) | ||||
assert swh_storage.extid_get_from_target(ObjectType.REVISION, gitids) == extids | assert set( | ||||
swh_storage.extid_get_from_target(ObjectType.REVISION, gitids) | |||||
) == set(extids) | |||||
assert swh_storage.extid_get_from_extid("hg", gitids) == [] | assert swh_storage.extid_get_from_extid("hg", gitids) == [] | ||||
assert swh_storage.extid_get_from_target(ObjectType.RELEASE, gitids) == [] | assert swh_storage.extid_get_from_target(ObjectType.RELEASE, gitids) == [] | ||||
# check ExtIDs have been added to the journal | # check ExtIDs have been added to the journal | ||||
extids_in_journal = [ | extids_in_journal = [ | ||||
obj | obj | ||||
for (obj_type, obj) in swh_storage.journal_writer.journal.objects | for (obj_type, obj) in swh_storage.journal_writer.journal.objects | ||||
Show All 34 Lines | def test_extid_add_hg(self, swh_storage, sample_data): | ||||
object_type=ObjectType.REVISION, | object_type=ObjectType.REVISION, | ||||
), | ), | ||||
) | ) | ||||
for hgid, swhid in zip(extids, swhids) | for hgid, swhid in zip(extids, swhids) | ||||
] | ] | ||||
summary = swh_storage.extid_add(extid_objs) | summary = swh_storage.extid_add(extid_objs) | ||||
assert summary == {"extid:add": len(swhids)} | assert summary == {"extid:add": len(swhids)} | ||||
assert swh_storage.extid_get_from_extid("hg", extids) == extid_objs | assert set(swh_storage.extid_get_from_extid("hg", extids)) == set(extid_objs) | ||||
assert ( | assert set( | ||||
swh_storage.extid_get_from_target(ObjectType.REVISION, swhids) == extid_objs | swh_storage.extid_get_from_target(ObjectType.REVISION, swhids) | ||||
) | ) == set(extid_objs) | ||||
assert swh_storage.extid_get_from_extid("git", extids) == [] | assert swh_storage.extid_get_from_extid("git", extids) == [] | ||||
assert swh_storage.extid_get_from_target(ObjectType.RELEASE, swhids) == [] | assert swh_storage.extid_get_from_target(ObjectType.RELEASE, swhids) == [] | ||||
# check ExtIDs have been added to the journal | # check ExtIDs have been added to the journal | ||||
extids_in_journal = [ | extids_in_journal = [ | ||||
obj | obj | ||||
for (obj_type, obj) in swh_storage.journal_writer.journal.objects | for (obj_type, obj) in swh_storage.journal_writer.journal.objects | ||||
Show All 21 Lines | def test_extid_add_twice(self, swh_storage, sample_data): | ||||
for gitid in gitids | for gitid in gitids | ||||
] | ] | ||||
summary = swh_storage.extid_add(extids) | summary = swh_storage.extid_add(extids) | ||||
assert summary == {"extid:add": len(gitids)} | assert summary == {"extid:add": len(gitids)} | ||||
# add them again, should be noop | # add them again, should be noop | ||||
summary = swh_storage.extid_add(extids) | summary = swh_storage.extid_add(extids) | ||||
# assert summary == {"extid:add": 0} | # assert summary == {"extid:add": 0} | ||||
assert swh_storage.extid_get_from_extid("git", gitids) == extids | assert set(swh_storage.extid_get_from_extid("git", gitids)) == set(extids) | ||||
assert swh_storage.extid_get_from_target(ObjectType.REVISION, gitids) == extids | assert set( | ||||
swh_storage.extid_get_from_target(ObjectType.REVISION, gitids) | |||||
) == set(extids) | |||||
def test_extid_add_extid_multicity(self, swh_storage, sample_data): | def test_extid_add_extid_multicity(self, swh_storage, sample_data): | ||||
ids = [ | ids = [ | ||||
revision.id | revision.id | ||||
for revision in sample_data.revisions | for revision in sample_data.revisions | ||||
if revision.type.value == "git" | if revision.type.value == "git" | ||||
] | ] | ||||
Show All 22 Lines | def test_extid_add_extid_multicity(self, swh_storage, sample_data): | ||||
object_id=extid, | object_id=extid, | ||||
object_type=ObjectType.REVISION, | object_type=ObjectType.REVISION, | ||||
), | ), | ||||
) | ) | ||||
for extid in ids | for extid in ids | ||||
] | ] | ||||
swh_storage.extid_add(extids2) | swh_storage.extid_add(extids2) | ||||
assert swh_storage.extid_get_from_extid("git", ids) == extids | assert set(swh_storage.extid_get_from_extid("git", ids)) == set(extids) | ||||
assert swh_storage.extid_get_from_extid("hg", ids) == extids2 | assert set(swh_storage.extid_get_from_extid("hg", ids)) == set(extids2) | ||||
assert set(swh_storage.extid_get_from_target(ObjectType.REVISION, ids)) == { | assert set(swh_storage.extid_get_from_target(ObjectType.REVISION, ids)) == { | ||||
*extids, | *extids, | ||||
*extids2, | *extids2, | ||||
} | } | ||||
def test_extid_add_target_multicity(self, swh_storage, sample_data): | def test_extid_add_target_multicity(self, swh_storage, sample_data): | ||||
ids = [ | ids = [ | ||||
Show All 25 Lines | def test_extid_add_target_multicity(self, swh_storage, sample_data): | ||||
object_type=ObjectType.RELEASE, | object_type=ObjectType.RELEASE, | ||||
), | ), | ||||
) | ) | ||||
for extid in ids | for extid in ids | ||||
] | ] | ||||
swh_storage.extid_add(extids2) | swh_storage.extid_add(extids2) | ||||
assert set(swh_storage.extid_get_from_extid("git", ids)) == {*extids, *extids2} | assert set(swh_storage.extid_get_from_extid("git", ids)) == {*extids, *extids2} | ||||
assert swh_storage.extid_get_from_target(ObjectType.REVISION, ids) == extids | assert set(swh_storage.extid_get_from_target(ObjectType.REVISION, ids)) == set( | ||||
assert swh_storage.extid_get_from_target(ObjectType.RELEASE, ids) == extids2 | extids | ||||
) | |||||
assert set(swh_storage.extid_get_from_target(ObjectType.RELEASE, ids)) == set( | |||||
extids2 | |||||
) | |||||
def test_extid_version_behavior(self, swh_storage, sample_data): | def test_extid_version_behavior(self, swh_storage, sample_data): | ||||
ids = [ | ids = [ | ||||
revision.id | revision.id | ||||
for revision in sample_data.revisions | for revision in sample_data.revisions | ||||
if revision.type.value == "git" | if revision.type.value == "git" | ||||
] | ] | ||||
▲ Show 20 Lines • Show All 3,987 Lines • Show Last 20 Lines |
what do we lose with these unsorted comparisions? can this be a problem?