Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/conftest.py
Show All 12 Lines | |||||
from hypothesis import HealthCheck | from hypothesis import HealthCheck | ||||
from hypothesis import __version_info__ as hypothesis_version | from hypothesis import __version_info__ as hypothesis_version | ||||
from hypothesis import settings | from hypothesis import settings | ||||
import pytest | import pytest | ||||
from django.core.cache import cache | from django.core.cache import cache | ||||
from rest_framework.test import APIClient, APIRequestFactory | from rest_framework.test import APIClient, APIRequestFactory | ||||
from swh.auth.pytest_plugin import keycloak_mock_factory | |||||
from swh.model.hashutil import ALGORITHMS, hash_to_bytes | from swh.model.hashutil import ALGORITHMS, hash_to_bytes | ||||
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.typing import OriginVisitInfo | from swh.web.common.typing import OriginVisitInfo | ||||
from swh.web.config import get_config | from swh.web.config import get_config | ||||
from swh.web.tests.data import get_tests_data, override_storages | from swh.web.tests.data import get_tests_data, override_storages | ||||
ardumont: don't you have a warning about this?
I remembered that at some point, they removed the… | |||||
Done Inline ActionsNope, because test*/conftest.py file can contain pytest_plugins variable (see doc) anlambert: Nope, because `test*/conftest.py` file can contain `pytest_plugins` variable (see [[ https… | |||||
pytest_plugins = ["swh.auth.pytest_plugin"] | |||||
# Used to skip some tests | # Used to skip some tests | ||||
ctags_json_missing = ( | ctags_json_missing = ( | ||||
shutil.which("ctags") is None | shutil.which("ctags") is None | ||||
or b"+json" not in run(["ctags", "--version"], stdout=PIPE).stdout | or b"+json" not in run(["ctags", "--version"], stdout=PIPE).stdout | ||||
) | ) | ||||
fossology_missing = shutil.which("nomossa") is None | fossology_missing = shutil.which("nomossa") is None | ||||
▲ Show 20 Lines • Show All 317 Lines • ▼ Show 20 Lines | class _IndexerData: | ||||
def content_get_ctags(self, cnt_id): | def content_get_ctags(self, cnt_id): | ||||
cnt_id_bytes = hash_to_bytes(cnt_id) | cnt_id_bytes = hash_to_bytes(cnt_id) | ||||
ctags = self.idx_storage.content_ctags_get([cnt_id_bytes]) | ctags = self.idx_storage.content_ctags_get([cnt_id_bytes]) | ||||
for ctag in ctags: | for ctag in ctags: | ||||
yield converters.from_swh(ctag, hashess={"id"}) | yield converters.from_swh(ctag, hashess={"id"}) | ||||
_keycloak_config = get_config()["keycloak"] | @pytest.fixture | ||||
def keycloak_oidc(keycloak_oidc, mocker): | |||||
_keycloak_mock = keycloak_mock_factory( | keycloak_config = get_config()["keycloak"] | ||||
server_url=_keycloak_config["server_url"], | |||||
realm_name=_keycloak_config["realm_name"], | |||||
client_id=OIDC_SWH_WEB_CLIENT_ID, | |||||
) | |||||
keycloak_oidc.server_url = keycloak_config["server_url"] | |||||
keycloak_oidc.realm_name = keycloak_config["realm_name"] | |||||
keycloak_oidc.client_id = OIDC_SWH_WEB_CLIENT_ID | |||||
@pytest.fixture | keycloak_oidc_client = mocker.patch("swh.web.auth.views.keycloak_oidc_client") | ||||
def keycloak_mock(_keycloak_mock, mocker): | keycloak_oidc_client.return_value = keycloak_oidc | ||||
for oidc_client_factory in ( | |||||
"swh.web.auth.views.get_oidc_client", | |||||
"swh.web.auth.backends.get_oidc_client", | |||||
): | |||||
mock_get_oidc_client = mocker.patch(oidc_client_factory) | |||||
mock_get_oidc_client.return_value = _keycloak_mock | |||||
return _keycloak_mock | return keycloak_oidc |
don't you have a warning about this?
I remembered that at some point, they removed the possibility of defining this here...