Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_storage.py
Show First 20 Lines • Show All 874 Lines • ▼ Show 20 Lines | def test_content_missing(self, algos): | ||||
) | ) | ||||
for hash in algos: | for hash in algos: | ||||
self.assertCountEqual( | self.assertCountEqual( | ||||
self.storage.content_missing(test_contents, key_hash=hash), | self.storage.content_missing(test_contents, key_hash=hash), | ||||
missing_per_hash[hash] | missing_per_hash[hash] | ||||
) | ) | ||||
def test_content_missing__marked_missing(self): | |||||
cont2 = self.cont2.copy() | |||||
cont2['status'] = 'missing' | |||||
del cont2['data'] | |||||
self.storage.content_add([cont2]) | |||||
test_content = { | |||||
algo: cont2[algo] | |||||
for algo in ('sha1', 'sha1_git', 'sha256', 'blake2s256')} | |||||
self.assertCountEqual( | |||||
self.storage.content_missing([test_content]), | |||||
[cont2['sha1']] | |||||
) | |||||
@pytest.mark.property_based | |||||
@given(strategies.sets( | |||||
elements=strategies.sampled_from( | |||||
['sha256', 'sha1_git', 'blake2s256']), | |||||
min_size=0)) | |||||
def test_content_missing_unknown_algo(self, algos): | |||||
algos |= {'sha1'} | |||||
cont2 = self.cont2 | |||||
missing_cont = self.missing_cont | |||||
self.storage.content_add([cont2]) | |||||
test_contents = [cont2] | |||||
missing_per_hash = defaultdict(list) | |||||
for i in range(16): | |||||
test_content = missing_cont.copy() | |||||
for hash in algos: | |||||
test_content[hash] = bytes([i]) + test_content[hash][1:] | |||||
missing_per_hash[hash].append(test_content[hash]) | |||||
test_content['nonexisting_algo'] = b'\x00' | |||||
test_contents.append(test_content) | |||||
self.assertCountEqual( | |||||
self.storage.content_missing(test_contents), | |||||
missing_per_hash['sha1'] | |||||
) | |||||
for hash in algos: | |||||
self.assertCountEqual( | |||||
self.storage.content_missing(test_contents, key_hash=hash), | |||||
missing_per_hash[hash] | |||||
) | |||||
def test_content_missing_per_sha1(self): | def test_content_missing_per_sha1(self): | ||||
# given | # given | ||||
cont2 = self.cont2 | cont2 = self.cont2 | ||||
missing_cont = self.missing_cont | missing_cont = self.missing_cont | ||||
self.storage.content_add([cont2]) | self.storage.content_add([cont2]) | ||||
# when | # when | ||||
gen = self.storage.content_missing_per_sha1([cont2['sha1'], | gen = self.storage.content_missing_per_sha1([cont2['sha1'], | ||||
missing_cont['sha1']]) | missing_cont['sha1']]) | ||||
▲ Show 20 Lines • Show All 2,900 Lines • Show Last 20 Lines |