Changeset View
Changeset View
Standalone View
Standalone View
swh/fuse/tests/test_revision.py
import json | import json | ||||
import os | import os | ||||
from swh.fuse.tests.common import get_data_from_archive | from swh.fuse.tests.common import check_dir_name_entries, get_data_from_archive | ||||
from swh.fuse.tests.data.config import ROOT_DIR, ROOT_REV | from swh.fuse.tests.data.config import ROOT_DIR, ROOT_REV | ||||
def test_access_meta(fuse_mntdir): | def test_access_meta(fuse_mntdir): | ||||
file_path = fuse_mntdir / "archive" / ROOT_REV / "meta.json" | file_path = fuse_mntdir / "archive" / ROOT_REV / "meta.json" | ||||
expected = json.dumps(get_data_from_archive(ROOT_REV)) | expected = json.dumps(get_data_from_archive(ROOT_REV)) | ||||
assert file_path.read_text() == expected | assert file_path.read_text() == expected | ||||
def test_list_root(fuse_mntdir): | def test_list_root(fuse_mntdir): | ||||
dir_path = fuse_mntdir / "archive" / ROOT_REV / "root" | dir_path = fuse_mntdir / "archive" / ROOT_REV / "root" | ||||
dir_meta = get_data_from_archive(ROOT_DIR) | check_dir_name_entries(dir_path, ROOT_DIR) | ||||
expected = [x["name"] for x in dir_meta] | |||||
actual = os.listdir(dir_path) | |||||
assert set(actual) == set(expected) | |||||
def test_list_parents(fuse_mntdir): | def test_list_parents(fuse_mntdir): | ||||
rev_meta = get_data_from_archive(ROOT_REV) | rev_meta = get_data_from_archive(ROOT_REV) | ||||
dir_path = fuse_mntdir / "archive" / ROOT_REV / "parents" | dir_path = fuse_mntdir / "archive" / ROOT_REV / "parents" | ||||
for i, parent in enumerate(rev_meta["parents"]): | for i, parent in enumerate(rev_meta["parents"]): | ||||
parent_path = dir_path / str(i + 1) | parent_path = dir_path / str(i + 1) | ||||
parent_swhid = f"swh:1:rev:{parent['id']}" | parent_swhid = f"swh:1:rev:{parent['id']}" | ||||
assert parent_path.is_symlink() | assert parent_path.is_symlink() | ||||
assert os.readlink(parent_path) == f"../../../archive/{parent_swhid}" | assert os.readlink(parent_path) == f"../../../archive/{parent_swhid}" | ||||
def test_list_parent(fuse_mntdir): | def test_list_parent(fuse_mntdir): | ||||
file_path = fuse_mntdir / "archive" / ROOT_REV / "parent" | file_path = fuse_mntdir / "archive" / ROOT_REV / "parent" | ||||
assert file_path.is_symlink() | assert file_path.is_symlink() | ||||
assert os.readlink(file_path) == "parents/1/" | assert os.readlink(file_path) == "parents/1/" |