Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_storage.py
Show First 20 Lines • Show All 869 Lines • ▼ Show 20 Lines | def _transform_entries(dir_, *, prefix=b''): | ||||
'type': ent['type'], | 'type': ent['type'], | ||||
'target': ent['target'], | 'target': ent['target'], | ||||
'name': prefix + ent['name'], | 'name': prefix + ent['name'], | ||||
'perms': ent['perms'], | 'perms': ent['perms'], | ||||
'status': None, | 'status': None, | ||||
'sha1': None, | 'sha1': None, | ||||
'sha1_git': None, | 'sha1_git': None, | ||||
'sha256': None, | 'sha256': None, | ||||
'blake2s256': None, | |||||
'length': None, | 'length': None, | ||||
} | } | ||||
def test_directory_add(self): | def test_directory_add(self): | ||||
init_missing = list(self.storage.directory_missing([self.dir['id']])) | init_missing = list(self.storage.directory_missing([self.dir['id']])) | ||||
self.assertEqual([self.dir['id']], init_missing) | self.assertEqual([self.dir['id']], init_missing) | ||||
actual_result = self.storage.directory_add([self.dir]) | actual_result = self.storage.directory_add([self.dir]) | ||||
Show All 34 Lines | def test_directory_get_recursive(self): | ||||
actual_data = list(self.storage.directory_ls( | actual_data = list(self.storage.directory_ls( | ||||
self.dir3['id'], recursive=True)) | self.dir3['id'], recursive=True)) | ||||
expected_data = list(itertools.chain( | expected_data = list(itertools.chain( | ||||
self._transform_entries(self.dir3), | self._transform_entries(self.dir3), | ||||
self._transform_entries(self.dir, prefix=b'subdir/'))) | self._transform_entries(self.dir, prefix=b'subdir/'))) | ||||
self.assertCountEqual(expected_data, actual_data) | self.assertCountEqual(expected_data, actual_data) | ||||
def test_directory_get_known_content(self): | |||||
init_missing = list(self.storage.directory_missing([self.dir['id']])) | |||||
self.assertEqual([self.dir['id']], init_missing) | |||||
self.storage.content_add([self.cont]) | |||||
self.storage.directory_add([self.dir]) | |||||
actual_data = list(self.storage.directory_ls(self.dir['id'])) | |||||
expected_data = list(self._transform_entries(self.dir)) | |||||
assert any(entry['type'] == 'file' for entry in expected_data) | |||||
for entry in expected_data: | |||||
if entry['type'] == 'file': | |||||
entry.update(self.cont) | |||||
del entry['data'] | |||||
self.assertCountEqual(expected_data, actual_data) | |||||
def test_directory_entry_get_by_path(self): | def test_directory_entry_get_by_path(self): | ||||
# given | # given | ||||
init_missing = list(self.storage.directory_missing([self.dir3['id']])) | init_missing = list(self.storage.directory_missing([self.dir3['id']])) | ||||
self.assertEqual([self.dir3['id']], init_missing) | self.assertEqual([self.dir3['id']], init_missing) | ||||
actual_result = self.storage.directory_add([self.dir3]) | actual_result = self.storage.directory_add([self.dir3]) | ||||
self.assertEqual(actual_result, {'directory:add': 1}) | self.assertEqual(actual_result, {'directory:add': 1}) | ||||
expected_entries = [ | expected_entries = [ | ||||
{ | { | ||||
'dir_id': self.dir3['id'], | 'dir_id': self.dir3['id'], | ||||
'name': b'foo', | 'name': b'foo', | ||||
'type': 'file', | 'type': 'file', | ||||
'target': self.cont['sha1_git'], | 'target': self.cont['sha1_git'], | ||||
'sha1': None, | 'sha1': None, | ||||
'sha1_git': None, | 'sha1_git': None, | ||||
'sha256': None, | 'sha256': None, | ||||
'blake2s256': None, | |||||
'status': None, | 'status': None, | ||||
'perms': from_disk.DentryPerms.content, | 'perms': from_disk.DentryPerms.content, | ||||
'length': None, | 'length': None, | ||||
}, | }, | ||||
{ | { | ||||
'dir_id': self.dir3['id'], | 'dir_id': self.dir3['id'], | ||||
'name': b'subdir', | 'name': b'subdir', | ||||
'type': 'dir', | 'type': 'dir', | ||||
'target': self.dir['id'], | 'target': self.dir['id'], | ||||
'sha1': None, | 'sha1': None, | ||||
'sha1_git': None, | 'sha1_git': None, | ||||
'sha256': None, | 'sha256': None, | ||||
'blake2s256': None, | |||||
'status': None, | 'status': None, | ||||
'perms': from_disk.DentryPerms.directory, | 'perms': from_disk.DentryPerms.directory, | ||||
'length': None, | 'length': None, | ||||
}, | }, | ||||
{ | { | ||||
'dir_id': self.dir3['id'], | 'dir_id': self.dir3['id'], | ||||
'name': b'hello', | 'name': b'hello', | ||||
'type': 'file', | 'type': 'file', | ||||
'target': b'12345678901234567890', | 'target': b'12345678901234567890', | ||||
'sha1': None, | 'sha1': None, | ||||
'sha1_git': None, | 'sha1_git': None, | ||||
'sha256': None, | 'sha256': None, | ||||
'blake2s256': None, | |||||
'status': None, | 'status': None, | ||||
'perms': from_disk.DentryPerms.content, | 'perms': from_disk.DentryPerms.content, | ||||
'length': None, | 'length': None, | ||||
}, | }, | ||||
] | ] | ||||
# when (all must be found here) | # when (all must be found here) | ||||
for entry, expected_entry in zip(self.dir3['entries'], | for entry, expected_entry in zip(self.dir3['entries'], | ||||
▲ Show 20 Lines • Show All 2,384 Lines • Show Last 20 Lines |