Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/conftest.py
Show First 20 Lines • Show All 170 Lines • ▼ Show 20 Lines | def content_find(self, content: Dict[str, Any]) -> Dict[str, Any]: | ||||
cnt_ids_bytes = { | cnt_ids_bytes = { | ||||
algo_hash: hash_to_bytes(content[algo_hash]) | algo_hash: hash_to_bytes(content[algo_hash]) | ||||
for algo_hash in ALGORITHMS | for algo_hash in ALGORITHMS | ||||
if content.get(algo_hash) | if content.get(algo_hash) | ||||
} | } | ||||
cnt = self.storage.content_find(cnt_ids_bytes) | cnt = self.storage.content_find(cnt_ids_bytes) | ||||
return converters.from_content(cnt[0].to_dict()) if cnt else cnt | return converters.from_content(cnt[0].to_dict()) if cnt else cnt | ||||
def content_get_metadata(self, cnt_id): | def content_get(self, cnt_id: str) -> Dict[str, Any]: | ||||
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]) | content = self.storage.content_get([cnt_id_bytes])[0] | ||||
contents = metadata[cnt_id_bytes] | if content: | ||||
content = None if not contents else contents[0] | content_d = content.to_dict() | ||||
ardumont: Should not be needed when D3736 lands and gets released. | |||||
Not Done Inline ActionsI think we should keep it, because we'll probably want to make content_get return the ctime at some point vlorentz: I think we should keep it, because we'll probably want to make `content_get` return the ctime… | |||||
Done Inline Actionsack ardumont: ack | |||||
content_d.pop("ctime", None) | |||||
else: | |||||
content_d = None | |||||
return converters.from_swh( | return converters.from_swh( | ||||
content, hashess={"sha1", "sha1_git", "sha256", "blake2s256"} | content_d, hashess={"sha1", "sha1_git", "sha256", "blake2s256"} | ||||
) | ) | ||||
def content_get_data(self, cnt_id: str) -> Optional[Dict[str, Any]]: | 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_data = self.storage.content_get_data(cnt_id_bytes) | cnt_data = self.storage.content_get_data(cnt_id_bytes) | ||||
if cnt_data is None: | if cnt_data is None: | ||||
return None | return None | ||||
return converters.from_content({"data": cnt_data, "sha1": cnt_id_bytes}) | return converters.from_content({"data": cnt_data, "sha1": cnt_id_bytes}) | ||||
▲ Show 20 Lines • Show All 166 Lines • Show Last 20 Lines |
Should not be needed when D3736 lands and gets released.