Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_storage.py
Show First 20 Lines • Show All 463 Lines • ▼ Show 20 Lines | class TestStorage: | ||||
@given( | @given( | ||||
strategies.sets( | strategies.sets( | ||||
elements=strategies.sampled_from(["sha256", "sha1_git", "blake2s256"]), | elements=strategies.sampled_from(["sha256", "sha1_git", "blake2s256"]), | ||||
min_size=0, | min_size=0, | ||||
) | ) | ||||
) | ) | ||||
def test_content_missing(self, swh_storage, algos): | def test_content_missing(self, swh_storage, algos): | ||||
algos |= {"sha1"} | algos |= {"sha1"} | ||||
content, missing_content = [data.content2, data.missing_content] | content, missing_content = [data.content2, data.skipped_content] | ||||
swh_storage.content_add([content]) | swh_storage.content_add([content]) | ||||
test_contents = [content.to_dict()] | test_contents = [content.to_dict()] | ||||
missing_per_hash = defaultdict(list) | missing_per_hash = defaultdict(list) | ||||
for i in range(256): | for i in range(256): | ||||
test_content = missing_content.to_dict() | test_content = missing_content.to_dict() | ||||
for hash in algos: | for hash in algos: | ||||
test_content[hash] = bytes([i]) + test_content[hash][1:] | test_content[hash] = bytes([i]) + test_content[hash][1:] | ||||
Show All 13 Lines | class TestStorage: | ||||
@given( | @given( | ||||
strategies.sets( | strategies.sets( | ||||
elements=strategies.sampled_from(["sha256", "sha1_git", "blake2s256"]), | elements=strategies.sampled_from(["sha256", "sha1_git", "blake2s256"]), | ||||
min_size=0, | min_size=0, | ||||
) | ) | ||||
) | ) | ||||
def test_content_missing_unknown_algo(self, swh_storage, algos): | def test_content_missing_unknown_algo(self, swh_storage, algos): | ||||
algos |= {"sha1"} | algos |= {"sha1"} | ||||
content, missing_content = [data.content2, data.missing_content] | content, missing_content = [data.content2, data.skipped_content] | ||||
swh_storage.content_add([content]) | swh_storage.content_add([content]) | ||||
test_contents = [content.to_dict()] | test_contents = [content.to_dict()] | ||||
missing_per_hash = defaultdict(list) | missing_per_hash = defaultdict(list) | ||||
for i in range(16): | for i in range(16): | ||||
test_content = missing_content.to_dict() | test_content = missing_content.to_dict() | ||||
for hash in algos: | for hash in algos: | ||||
test_content[hash] = bytes([i]) + test_content[hash][1:] | test_content[hash] = bytes([i]) + test_content[hash][1:] | ||||
▲ Show 20 Lines • Show All 2,645 Lines • ▼ Show 20 Lines | def test_content_metadata_add(self, swh_storage, sample_data_model): | ||||
swh_storage.metadata_authority_add([authority]) | swh_storage.metadata_authority_add([authority]) | ||||
swh_storage.object_metadata_add(content_metadata) | swh_storage.object_metadata_add(content_metadata) | ||||
result = swh_storage.object_metadata_get( | result = swh_storage.object_metadata_get( | ||||
MetadataTargetType.CONTENT, content_swhid, authority | MetadataTargetType.CONTENT, content_swhid, authority | ||||
) | ) | ||||
assert result["next_page_token"] is None | assert result["next_page_token"] is None | ||||
assert ( | assert list(sorted(result["results"], key=lambda x: x.discovery_date,)) == list( | ||||
list(sorted(result["results"], key=lambda x: x.discovery_date,)) | content_metadata | ||||
== content_metadata | |||||
) | ) | ||||
def test_content_metadata_add_duplicate(self, swh_storage, sample_data_model): | def test_content_metadata_add_duplicate(self, swh_storage, sample_data_model): | ||||
"""Duplicates should be silently updated.""" | """Duplicates should be silently updated.""" | ||||
content = sample_data_model["content"][0] | content = sample_data_model["content"][0] | ||||
fetcher = sample_data_model["fetcher"][0] | fetcher = sample_data_model["fetcher"][0] | ||||
authority = sample_data_model["authority"][0] | authority = sample_data_model["authority"][0] | ||||
content_metadata, content_metadata2 = sample_data_model["content_metadata"][:2] | content_metadata, content_metadata2 = sample_data_model["content_metadata"][:2] | ||||
▲ Show 20 Lines • Show All 960 Lines • Show Last 20 Lines |