Changeset View
Changeset View
Standalone View
Standalone View
swh/scanner/tests/conftest.py
Show All 9 Lines | |||||
import aiohttp | import aiohttp | ||||
from aioresponses import aioresponses # type: ignore | from aioresponses import aioresponses # type: ignore | ||||
import pytest | import pytest | ||||
from swh.model.cli import swhid_of_dir, swhid_of_file | from swh.model.cli import swhid_of_dir, swhid_of_file | ||||
from swh.scanner.model import Tree | from swh.scanner.model import Tree | ||||
from .data import present_swhids | |||||
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 105 Lines • ▼ Show 20 Lines | def test_sample_folder(datadir, tmp_path): | ||||
archive_path = Path(os.path.join(datadir, "sample-folder.tgz")) | archive_path = Path(os.path.join(datadir, "sample-folder.tgz")) | ||||
assert archive_path.exists() | assert archive_path.exists() | ||||
shutil.unpack_archive(archive_path, extract_dir=tmp_path) | shutil.unpack_archive(archive_path, extract_dir=tmp_path) | ||||
test_sample_folder = Path(os.path.join(tmp_path, "sample-folder")) | test_sample_folder = Path(os.path.join(tmp_path, "sample-folder")) | ||||
assert test_sample_folder.exists() | assert test_sample_folder.exists() | ||||
return test_sample_folder | return test_sample_folder | ||||
@pytest.fixture | |||||
def test_swhids_sample(tmp_path): | |||||
"""Create and return the opened "swhids_sample" file, | |||||
filled with present swhids present in data.py | |||||
""" | |||||
test_swhids_sample = Path(os.path.join(tmp_path, "swhids_sample.txt")) | |||||
not_present_swhid = "swh:1:cnt:fa8eacf43d8646129ae8adfa1648f9307d999999" | |||||
swhids = present_swhids + [not_present_swhid] | |||||
with open(test_swhids_sample, "w") as f: | |||||
f.write("\n".join(swhid for swhid in swhids)) | |||||
assert test_swhids_sample.exists() | |||||
return open(test_swhids_sample, "r") | |||||
@pytest.fixture(scope="session") | @pytest.fixture(scope="session") | ||||
def app(): | def app(): | ||||
"""Flask backend API (used by live_server).""" | """Flask backend API (used by live_server).""" | ||||
app = create_app() | app = create_app() | ||||
return app | return app |