Changeset View
Changeset View
Standalone View
Standalone View
swh/scanner/tests/conftest.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 pytest | import pytest | ||||
import asyncio | import asyncio | ||||
import aiohttp | import aiohttp | ||||
import os | import os | ||||
from pathlib import PosixPath | from pathlib import PosixPath | ||||
from aioresponses import aioresponses # type: ignore | from aioresponses import aioresponses # type: ignore | ||||
from swh.model.cli import pid_of_file, pid_of_dir | from swh.model.cli import swhid_of_file, swhid_of_dir | ||||
from swh.scanner.model import Tree | from swh.scanner.model import Tree | ||||
from .flask_api import create_app | from .flask_api import create_app | ||||
@pytest.fixture | @pytest.fixture | ||||
def mock_aioresponse(): | def mock_aioresponse(): | ||||
with aioresponses() as m: | with aioresponses() as m: | ||||
yield m | yield m | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | def temp_folder(tmp_path_factory): | ||||
subfile = root / "subfile.txt" | subfile = root / "subfile.txt" | ||||
subfile.touch() | subfile.touch() | ||||
filesample = subdir / "filesample.txt" | filesample = subdir / "filesample.txt" | ||||
filesample.touch() | filesample.touch() | ||||
filesample2 = subdir / "filesample2.txt" | filesample2 = subdir / "filesample2.txt" | ||||
filesample2.touch() | filesample2.touch() | ||||
avail_path = { | avail_path = { | ||||
subdir: pid_of_dir(bytes(subdir)), | subdir: swhid_of_dir(bytes(subdir)), | ||||
subsubdir: pid_of_dir(bytes(subsubdir)), | subsubdir: swhid_of_dir(bytes(subsubdir)), | ||||
subdir2: pid_of_dir(bytes(subdir2)), | subdir2: swhid_of_dir(bytes(subdir2)), | ||||
subfile: pid_of_file(bytes(subfile)), | subfile: swhid_of_file(bytes(subfile)), | ||||
filesample: pid_of_file(bytes(filesample)), | filesample: swhid_of_file(bytes(filesample)), | ||||
filesample2: pid_of_file(bytes(filesample2)), | filesample2: swhid_of_file(bytes(filesample2)), | ||||
} | } | ||||
return { | return { | ||||
"root": root, | "root": root, | ||||
"paths": avail_path, | "paths": avail_path, | ||||
"filesample": filesample, | "filesample": filesample, | ||||
"filesample2": filesample2, | "filesample2": filesample2, | ||||
"subsubdir": subsubdir, | "subsubdir": subsubdir, | ||||
Show All 21 Lines | def example_dirs(example_tree, temp_folder): | ||||
""" | """ | ||||
root = temp_folder["root"] | root = temp_folder["root"] | ||||
filesample_path = temp_folder["filesample"] | filesample_path = temp_folder["filesample"] | ||||
filesample2_path = temp_folder["filesample2"] | filesample2_path = temp_folder["filesample2"] | ||||
subsubdir_path = temp_folder["subsubdir"] | subsubdir_path = temp_folder["subsubdir"] | ||||
known_paths = [filesample_path, filesample2_path, subsubdir_path] | known_paths = [filesample_path, filesample2_path, subsubdir_path] | ||||
for path, pid in temp_folder["paths"].items(): | for path, swhid in temp_folder["paths"].items(): | ||||
if path in known_paths: | if path in known_paths: | ||||
example_tree.addNode(path, pid, True) | example_tree.addNode(path, swhid, True) | ||||
else: | else: | ||||
example_tree.addNode(path, pid, False) | example_tree.addNode(path, swhid, False) | ||||
return example_tree.getDirectoriesInfo(root) | return example_tree.getDirectoriesInfo(root) | ||||
@pytest.fixture | @pytest.fixture | ||||
def test_folder(): | def test_folder(): | ||||
"""Location of the "data" folder """ | """Location of the "data" folder """ | ||||
tests_path = PosixPath(os.path.abspath(__file__)).parent | tests_path = PosixPath(os.path.abspath(__file__)).parent | ||||
Show All 10 Lines |