Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/conftest.py
Show First 20 Lines • Show All 179 Lines • ▼ Show 20 Lines | def content_get_metadata(self, cnt_id): | ||||
cnt_id_bytes = hash_to_bytes(cnt_id) | cnt_id_bytes = hash_to_bytes(cnt_id) | ||||
metadata = self.storage.content_get_metadata([cnt_id_bytes]) | metadata = self.storage.content_get_metadata([cnt_id_bytes]) | ||||
contents = metadata[cnt_id_bytes] | contents = metadata[cnt_id_bytes] | ||||
content = None if not contents else contents[0] | content = None if not contents else contents[0] | ||||
return converters.from_swh( | return converters.from_swh( | ||||
content, hashess={"sha1", "sha1_git", "sha256", "blake2s256"} | content, hashess={"sha1", "sha1_git", "sha256", "blake2s256"} | ||||
) | ) | ||||
def content_get(self, cnt_id): | def content_get_data(self, cnt_id: str) -> Optional[Dict[str, Any]]: | ||||
cnt_id_bytes = hash_to_bytes(cnt_id) | cnt_id_bytes = hash_to_bytes(cnt_id) | ||||
cnt = next(self.storage.content_get([cnt_id_bytes])) | cnt_data = self.storage.content_get_data(cnt_id_bytes) | ||||
return converters.from_content(cnt) | if cnt_data is None: | ||||
return None | |||||
return converters.from_content({"data": cnt_data, "sha1": cnt_id_bytes}) | |||||
def directory_get(self, dir_id): | def directory_get(self, dir_id): | ||||
return {"id": dir_id, "content": self.directory_ls(dir_id)} | return {"id": dir_id, "content": self.directory_ls(dir_id)} | ||||
def directory_ls(self, dir_id): | def directory_ls(self, dir_id): | ||||
cnt_id_bytes = hash_to_bytes(dir_id) | cnt_id_bytes = hash_to_bytes(dir_id) | ||||
dir_content = map( | dir_content = map( | ||||
converters.from_directory_entry, self.storage.directory_ls(cnt_id_bytes) | converters.from_directory_entry, self.storage.directory_ls(cnt_id_bytes) | ||||
▲ Show 20 Lines • Show All 158 Lines • Show Last 20 Lines |