Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_storage.py
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | def setUp(self): | ||||
'length': 3, | 'length': 3, | ||||
'sha1': hash_to_bytes( | 'sha1': hash_to_bytes( | ||||
'34973274ccef6ab4dfaaf86599792fa9c3fe4689'), | '34973274ccef6ab4dfaaf86599792fa9c3fe4689'), | ||||
'sha1_git': hash_to_bytes( | 'sha1_git': hash_to_bytes( | ||||
'd81cc0710eb6cf9efd5b920a8453e1e07157b6cd'), | 'd81cc0710eb6cf9efd5b920a8453e1e07157b6cd'), | ||||
'sha256': hash_to_bytes( | 'sha256': hash_to_bytes( | ||||
'673650f936cb3b0a2f93ce09d81be107' | '673650f936cb3b0a2f93ce09d81be107' | ||||
'48b1b203c19e8176b4eefc1964a0cf3a'), | '48b1b203c19e8176b4eefc1964a0cf3a'), | ||||
'blake2s256': hash_to_bytes('d5fe1939576527e42cfd76a9455a2' | |||||
'432fe7f56669564577dd93c4280e76d661d'), | |||||
'status': 'visible', | 'status': 'visible', | ||||
} | } | ||||
self.cont2 = { | self.cont2 = { | ||||
'data': b'4242\n', | 'data': b'4242\n', | ||||
'length': 5, | 'length': 5, | ||||
'sha1': hash_to_bytes( | 'sha1': hash_to_bytes( | ||||
'61c2b3a30496d329e21af70dd2d7e097046d07b7'), | '61c2b3a30496d329e21af70dd2d7e097046d07b7'), | ||||
'sha1_git': hash_to_bytes( | 'sha1_git': hash_to_bytes( | ||||
'36fade77193cb6d2bd826161a0979d64c28ab4fa'), | '36fade77193cb6d2bd826161a0979d64c28ab4fa'), | ||||
'sha256': hash_to_bytes( | 'sha256': hash_to_bytes( | ||||
'859f0b154fdb2d630f45e1ecae4a8629' | '859f0b154fdb2d630f45e1ecae4a8629' | ||||
'15435e663248bb8461d914696fc047cd'), | '15435e663248bb8461d914696fc047cd'), | ||||
'blake2s256': hash_to_bytes('849c20fad132b7c2d62c15de310adfe87be' | |||||
'94a379941bed295e8141c6219810d'), | |||||
'status': 'visible', | 'status': 'visible', | ||||
} | } | ||||
self.cont3 = { | self.cont3 = { | ||||
'data': b'424242\n', | 'data': b'424242\n', | ||||
'length': 7, | 'length': 7, | ||||
'sha1': hash_to_bytes( | 'sha1': hash_to_bytes( | ||||
'3e21cc4942a4234c9e5edd8a9cacd1670fe59f13'), | '3e21cc4942a4234c9e5edd8a9cacd1670fe59f13'), | ||||
'sha1_git': hash_to_bytes( | 'sha1_git': hash_to_bytes( | ||||
'c932c7649c6dfa4b82327d121215116909eb3bea'), | 'c932c7649c6dfa4b82327d121215116909eb3bea'), | ||||
'sha256': hash_to_bytes( | 'sha256': hash_to_bytes( | ||||
'92fb72daf8c6818288a35137b72155f5' | '92fb72daf8c6818288a35137b72155f5' | ||||
'07e5de8d892712ab96277aaed8cf8a36'), | '07e5de8d892712ab96277aaed8cf8a36'), | ||||
'blake2s256': hash_to_bytes('76d0346f44e5a27f6bafdd9c2befd304af' | |||||
'f83780f93121d801ab6a1d4769db11'), | |||||
'status': 'visible', | 'status': 'visible', | ||||
} | } | ||||
self.missing_cont = { | self.missing_cont = { | ||||
'data': b'missing\n', | 'data': b'missing\n', | ||||
'length': 8, | 'length': 8, | ||||
'sha1': hash_to_bytes( | 'sha1': hash_to_bytes( | ||||
'f9c24e2abb82063a3ba2c44efd2d3c797f28ac90'), | 'f9c24e2abb82063a3ba2c44efd2d3c797f28ac90'), | ||||
'sha1_git': hash_to_bytes( | 'sha1_git': hash_to_bytes( | ||||
'33e45d56f88993aae6a0198013efa80716fd8919'), | '33e45d56f88993aae6a0198013efa80716fd8919'), | ||||
'sha256': hash_to_bytes( | 'sha256': hash_to_bytes( | ||||
'6bbd052ab054ef222c1c87be60cd191a' | '6bbd052ab054ef222c1c87be60cd191a' | ||||
'ddedd24cc882d1f5f7f7be61dc61bb3a'), | 'ddedd24cc882d1f5f7f7be61dc61bb3a'), | ||||
'blake2s256': hash_to_bytes('306856b8fd879edb7b6f1aeaaf8db9bbecc9' | |||||
'93cd7f776c333ac3a782fa5c6eba'), | |||||
'status': 'absent', | 'status': 'absent', | ||||
} | } | ||||
self.skipped_cont = { | self.skipped_cont = { | ||||
'length': 1024 * 1024 * 200, | 'length': 1024 * 1024 * 200, | ||||
'sha1_git': hash_to_bytes( | 'sha1_git': hash_to_bytes( | ||||
'33e45d56f88993aae6a0198013efa80716fd8920'), | '33e45d56f88993aae6a0198013efa80716fd8920'), | ||||
'reason': 'Content too long', | 'reason': 'Content too long', | ||||
▲ Show 20 Lines • Show All 507 Lines • ▼ Show 20 Lines | class CommonTestStorage(BaseTestStorage): | ||||
@istest | @istest | ||||
def skipped_content_add(self): | def skipped_content_add(self): | ||||
cont = self.skipped_cont | cont = self.skipped_cont | ||||
cont2 = self.skipped_cont2 | cont2 = self.skipped_cont2 | ||||
self.storage.content_add([cont]) | self.storage.content_add([cont]) | ||||
self.storage.content_add([cont2]) | self.storage.content_add([cont2]) | ||||
self.cursor.execute('SELECT sha1, sha1_git, sha256, length, status,' | self.cursor.execute('SELECT sha1, sha1_git, sha256, blake2s256, ' | ||||
'reason FROM skipped_content ORDER BY sha1_git') | 'length, status, reason ' | ||||
'FROM skipped_content ORDER BY sha1_git') | |||||
datum = self.cursor.fetchone() | datum = self.cursor.fetchone() | ||||
self.assertEqual( | self.assertEqual( | ||||
(datum[0], datum[1].tobytes(), datum[2], | (datum[0], datum[1].tobytes(), datum[2], | ||||
datum[3], datum[4], datum[5]), | datum[3], datum[4], datum[5], datum[6]), | ||||
(None, cont['sha1_git'], None, | (None, cont['sha1_git'], None, None, | ||||
cont['length'], 'absent', 'Content too long')) | cont['length'], 'absent', 'Content too long')) | ||||
datum2 = self.cursor.fetchone() | datum2 = self.cursor.fetchone() | ||||
self.assertEqual( | self.assertEqual( | ||||
(datum2[0], datum2[1].tobytes(), datum2[2], | (datum2[0], datum2[1].tobytes(), datum2[2], | ||||
datum2[3], datum2[4], datum2[5]), | datum2[3], datum2[4], datum2[5], datum2[6]), | ||||
(None, cont2['sha1_git'], None, | (None, cont2['sha1_git'], None, None, | ||||
cont2['length'], 'absent', 'Content too long')) | cont2['length'], 'absent', 'Content too long')) | ||||
@istest | @istest | ||||
def content_missing(self): | def content_missing(self): | ||||
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]) | ||||
gen = self.storage.content_missing([cont2, missing_cont]) | gen = self.storage.content_missing([cont2, missing_cont]) | ||||
▲ Show 20 Lines • Show All 1,240 Lines • ▼ Show 20 Lines | def content_find_with_present_content(self): | ||||
actually_present = self.storage.content_find({'sha1': cont['sha1']}) | actually_present = self.storage.content_find({'sha1': cont['sha1']}) | ||||
actually_present.pop('ctime') | actually_present.pop('ctime') | ||||
self.assertEqual(actually_present, { | self.assertEqual(actually_present, { | ||||
'sha1': cont['sha1'], | 'sha1': cont['sha1'], | ||||
'sha256': cont['sha256'], | 'sha256': cont['sha256'], | ||||
'sha1_git': cont['sha1_git'], | 'sha1_git': cont['sha1_git'], | ||||
'blake2s256': cont['blake2s256'], | |||||
'length': cont['length'], | 'length': cont['length'], | ||||
'status': 'visible' | 'status': 'visible' | ||||
}) | }) | ||||
# 2. with something to find | # 2. with something to find | ||||
actually_present = self.storage.content_find( | actually_present = self.storage.content_find( | ||||
{'sha1_git': cont['sha1_git']}) | {'sha1_git': cont['sha1_git']}) | ||||
actually_present.pop('ctime') | actually_present.pop('ctime') | ||||
self.assertEqual(actually_present, { | self.assertEqual(actually_present, { | ||||
'sha1': cont['sha1'], | 'sha1': cont['sha1'], | ||||
'sha256': cont['sha256'], | 'sha256': cont['sha256'], | ||||
'sha1_git': cont['sha1_git'], | 'sha1_git': cont['sha1_git'], | ||||
'blake2s256': cont['blake2s256'], | |||||
'length': cont['length'], | 'length': cont['length'], | ||||
'status': 'visible' | 'status': 'visible' | ||||
}) | }) | ||||
# 3. with something to find | # 3. with something to find | ||||
actually_present = self.storage.content_find( | actually_present = self.storage.content_find( | ||||
{'sha256': cont['sha256']}) | {'sha256': cont['sha256']}) | ||||
actually_present.pop('ctime') | actually_present.pop('ctime') | ||||
self.assertEqual(actually_present, { | self.assertEqual(actually_present, { | ||||
'sha1': cont['sha1'], | 'sha1': cont['sha1'], | ||||
'sha256': cont['sha256'], | 'sha256': cont['sha256'], | ||||
'sha1_git': cont['sha1_git'], | 'sha1_git': cont['sha1_git'], | ||||
'blake2s256': cont['blake2s256'], | |||||
'length': cont['length'], | 'length': cont['length'], | ||||
'status': 'visible' | 'status': 'visible' | ||||
}) | }) | ||||
# 4. with something to find | # 4. with something to find | ||||
actually_present = self.storage.content_find( | actually_present = self.storage.content_find({ | ||||
{'sha1': cont['sha1'], | 'sha1': cont['sha1'], | ||||
'sha1_git': cont['sha1_git'], | 'sha1_git': cont['sha1_git'], | ||||
'sha256': cont['sha256']}) | 'sha256': cont['sha256'], | ||||
'blake2s256': cont['blake2s256'], | |||||
}) | |||||
actually_present.pop('ctime') | actually_present.pop('ctime') | ||||
self.assertEqual(actually_present, { | self.assertEqual(actually_present, { | ||||
'sha1': cont['sha1'], | 'sha1': cont['sha1'], | ||||
'sha256': cont['sha256'], | 'sha256': cont['sha256'], | ||||
'sha1_git': cont['sha1_git'], | 'sha1_git': cont['sha1_git'], | ||||
'blake2s256': cont['blake2s256'], | |||||
'length': cont['length'], | 'length': cont['length'], | ||||
'status': 'visible' | 'status': 'visible' | ||||
}) | }) | ||||
@istest | @istest | ||||
def content_find_with_non_present_content(self): | def content_find_with_non_present_content(self): | ||||
# 1. with something that does not exist | # 1. with something that does not exist | ||||
missing_cont = self.missing_cont | missing_cont = self.missing_cont | ||||
▲ Show 20 Lines • Show All 1,158 Lines • Show Last 20 Lines |