Changeset View
Changeset View
Standalone View
Standalone View
swh/fuse/tests/common.py
# Copyright (C) 2020 The Software Heritage developers | # Copyright (C) 2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import os | import os | ||||
from pathlib import Path | from pathlib import Path | ||||
from typing import Any, List | from typing import Any, List | ||||
from swh.fuse.tests.data.api_data import MOCK_ARCHIVE, SWHID2URL | from swh.fuse.tests.data.api_data import MOCK_ARCHIVE, SWHID2URL | ||||
def get_data_from_archive(swhid: str, raw: bool = False) -> Any: | def get_data_from_archive(swhid: str, raw: bool = False) -> Any: | ||||
url = SWHID2URL[swhid] | url = SWHID2URL[swhid] | ||||
if raw: | if raw: | ||||
url += "raw/" | url += "raw/" | ||||
# Special case: snapshots Web API and Web Client API differ a bit in format | |||||
if url.startswith("snapshot"): | |||||
return MOCK_ARCHIVE[url]["branches"] | |||||
else: | |||||
return MOCK_ARCHIVE[url] | return MOCK_ARCHIVE[url] | ||||
def get_dir_name_entries(swhid: str) -> List[str]: | def get_dir_name_entries(swhid: str) -> List[str]: | ||||
dir_meta = get_data_from_archive(swhid) | dir_meta = get_data_from_archive(swhid) | ||||
return [x["name"] for x in dir_meta] | return [x["name"] for x in dir_meta] | ||||
def check_dir_name_entries(dir_path: Path, dir_swhid: str) -> None: | def check_dir_name_entries(dir_path: Path, dir_swhid: str) -> None: | ||||
expected = get_dir_name_entries(dir_swhid) | expected = get_dir_name_entries(dir_swhid) | ||||
actual = os.listdir(dir_path) | actual = os.listdir(dir_path) | ||||
assert set(actual) == set(expected) | assert set(actual) == set(expected) |