Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/conftest.py
# Copyright (C) 2018-2021 The Software Heritage developers | # Copyright (C) 2018-2022 The Software Heritage developers | ||||
vlorentz: and you should add 2022 here | |||||
# 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 Affero General Public License version 3, or any later version | # License: GNU Affero 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 | ||||
from collections import defaultdict | from collections import defaultdict | ||||
from datetime import timedelta | from datetime import timedelta | ||||
import functools | import functools | ||||
import json | import json | ||||
Show All 16 Lines | |||||
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, Directory | from swh.model.model import Content, Directory | ||||
from swh.model.swhids import ObjectType | from swh.model.swhids import CoreSWHID, 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.revisions_walker import get_revisions_walker | from swh.storage.algos.revisions_walker import get_revisions_walker | ||||
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 ( | from swh.web.auth.utils import ( | ||||
ADD_FORGE_MODERATOR_PERMISSION, | ADD_FORGE_MODERATOR_PERMISSION, | ||||
MAILMAP_ADMIN_PERMISSION, | MAILMAP_ADMIN_PERMISSION, | ||||
MAILMAP_PERMISSION, | MAILMAP_PERMISSION, | ||||
OIDC_SWH_WEB_CLIENT_ID, | 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 | ||||
from swh.web.common.utils import browsers_supported_image_mimes | from swh.web.common.utils import browsers_supported_image_mimes | ||||
from swh.web.config import get_config | from swh.web.config import get_config | ||||
from swh.web.tests.data import ( | from swh.web.tests.data import ( | ||||
get_tests_data, | get_tests_data, | ||||
override_storages, | override_storages, | ||||
random_content, | random_content, | ||||
random_sha1, | random_sha1, | ||||
random_sha1_bytes, | |||||
random_sha256, | random_sha256, | ||||
) | ) | ||||
from swh.web.tests.utils import create_django_permission | from swh.web.tests.utils import create_django_permission | ||||
os.environ["LC_ALL"] = "C.UTF-8" | os.environ["LC_ALL"] = "C.UTF-8" | ||||
# Used to skip some tests | # Used to skip some tests | ||||
ctags_json_missing = ( | ctags_json_missing = ( | ||||
▲ Show 20 Lines • Show All 747 Lines • ▼ Show 20 Lines | |||||
@pytest.fixture(scope="function") | @pytest.fixture(scope="function") | ||||
def snapshot_swhid(): | def snapshot_swhid(): | ||||
"""Fixture returning a qualified SWHID for a snapshot object | """Fixture returning a qualified SWHID for a snapshot object | ||||
ingested into the test archive. | ingested into the test archive. | ||||
""" | """ | ||||
return random.choice(_object_type_swhid(ObjectType.SNAPSHOT)) | return random.choice(_object_type_swhid(ObjectType.SNAPSHOT)) | ||||
@pytest.fixture(scope="function", params=list(ObjectType)) | |||||
def unknown_core_swhid(request) -> CoreSWHID: | |||||
"""Fixture returning an unknown core SWHID. | |||||
Tests using this will be called once per object type. | |||||
""" | |||||
return CoreSWHID( | |||||
object_type=request.param, | |||||
object_id=random_sha1_bytes(), | |||||
) | |||||
# 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 410 Lines • Show Last 20 Lines |
and you should add 2022 here