Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/conftest.py
Show All 21 Lines | |||||
from rest_framework.test import APIClient, APIRequestFactory | from rest_framework.test import APIClient, APIRequestFactory | ||||
from swh.model.hashutil import ( | from swh.model.hashutil import ( | ||||
ALGORITHMS, | ALGORITHMS, | ||||
DEFAULT_ALGORITHMS, | DEFAULT_ALGORITHMS, | ||||
hash_to_bytes, | hash_to_bytes, | ||||
hash_to_hex, | hash_to_hex, | ||||
) | ) | ||||
from swh.model.model import Content | from swh.model.model import Content, Directory | ||||
from swh.model.swhids import ObjectType | from swh.model.swhids import ObjectType | ||||
from swh.scheduler.tests.common import TASK_TYPES | from swh.scheduler.tests.common import TASK_TYPES | ||||
from swh.storage.algos.origin import origin_get_latest_visit_status | from swh.storage.algos.origin import origin_get_latest_visit_status | ||||
from swh.storage.algos.snapshot import snapshot_get_all_branches, snapshot_get_latest | from swh.storage.algos.snapshot import snapshot_get_all_branches, snapshot_get_latest | ||||
from swh.web.auth.utils import OIDC_SWH_WEB_CLIENT_ID | from swh.web.auth.utils import OIDC_SWH_WEB_CLIENT_ID | ||||
from swh.web.common import converters | from swh.web.common import converters | ||||
from swh.web.common.origin_save import get_scheduler_load_task_types | from swh.web.common.origin_save import get_scheduler_load_task_types | ||||
from swh.web.common.typing import OriginVisitInfo | from swh.web.common.typing import OriginVisitInfo | ||||
▲ Show 20 Lines • Show All 296 Lines • ▼ Show 20 Lines | return { | ||||
"e8c0654fe2d75ecd7e0b01bee8a8fc60a130097e", | "e8c0654fe2d75ecd7e0b01bee8a8fc60a130097e", | ||||
"eb6595e559a1d34a2b41e8d4835e0e4f98a5d2b5", | "eb6595e559a1d34a2b41e8d4835e0e4f98a5d2b5", | ||||
], | ], | ||||
"symbol_name": "ABS", | "symbol_name": "ABS", | ||||
} | } | ||||
@pytest.fixture(scope="function") | @pytest.fixture(scope="function") | ||||
def content_swhid(tests_data): | def directory(tests_data): | ||||
"""Fixture returning a random directory ingested into the test archive. | |||||
""" | """ | ||||
Fixture returning a qualified SWHID for a random content object | return random.choice(_known_swh_objects(tests_data, "directories")) | ||||
ingested into the test archive. | |||||
def _directory_with_entry_type(tests_data, type_): | |||||
return random.choice( | |||||
list( | |||||
filter( | |||||
lambda d: any( | |||||
[ | |||||
e["type"] == type_ | |||||
for e in list( | |||||
tests_data["storage"].directory_ls(hash_to_bytes(d)) | |||||
) | |||||
] | |||||
), | |||||
_known_swh_objects(tests_data, "directories"), | |||||
) | |||||
) | |||||
) | |||||
@pytest.fixture(scope="function") | |||||
def directory_with_subdirs(tests_data): | |||||
"""Fixture returning a random directory containing sub directories ingested | |||||
into the test archive. | |||||
""" | """ | ||||
return _directory_with_entry_type(tests_data, "dir") | |||||
@pytest.fixture(scope="function") | |||||
def directory_with_files(tests_data): | |||||
"""Fixture returning a random directory containing at least one regular file. | |||||
""" | |||||
return _directory_with_entry_type(tests_data, "file") | |||||
@pytest.fixture(scope="function") | |||||
def empty_directory(): | |||||
"""Fixture returning the empty directory ingested into the test archive. | |||||
""" | |||||
return Directory(entries=()).id.hex() | |||||
def _object_type_swhid(tests_data, object_type): | |||||
return random.choice( | return random.choice( | ||||
list( | list( | ||||
filter( | filter( | ||||
lambda swhid: swhid.object_type == ObjectType.CONTENT, | lambda swhid: swhid.object_type == object_type, | ||||
_known_swh_objects(tests_data, "swhids"), | _known_swh_objects(tests_data, "swhids"), | ||||
) | ) | ||||
) | ) | ||||
) | ) | ||||
@pytest.fixture(scope="function") | |||||
def content_swhid(tests_data): | |||||
"""Fixture returning a qualified SWHID for a random content object | |||||
ingested into the test archive. | |||||
""" | |||||
return _object_type_swhid(tests_data, ObjectType.CONTENT) | |||||
@pytest.fixture(scope="function") | |||||
def directory_swhid(tests_data): | |||||
"""Fixture returning a qualified SWHID for a random directory object | |||||
ingested into the test archive. | |||||
""" | |||||
return _object_type_swhid(tests_data, ObjectType.DIRECTORY) | |||||
# Fixture to manipulate data from a sample archive used in the tests | # Fixture to manipulate data from a sample archive used in the tests | ||||
@pytest.fixture(scope="function") | @pytest.fixture(scope="function") | ||||
def archive_data(tests_data): | def archive_data(tests_data): | ||||
return _ArchiveData(tests_data) | return _ArchiveData(tests_data) | ||||
# Fixture to manipulate indexer data from a sample archive used in the tests | # Fixture to manipulate indexer data from a sample archive used in the tests | ||||
@pytest.fixture(scope="function") | @pytest.fixture(scope="function") | ||||
▲ Show 20 Lines • Show All 368 Lines • Show Last 20 Lines |