Changeset View
Changeset View
Standalone View
Standalone View
swh/web/conftest.py
- This file was moved from swh/web/tests/conftest.py.
# Copyright (C) 2018-2022 The Software Heritage developers | # Copyright (C) 2018-2022 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 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 | ||||
from importlib import import_module, reload | from importlib import import_module, reload | ||||
import json | import json | ||||
import os | import os | ||||
import random | import random | ||||
import shutil | |||||
import sys | import sys | ||||
import time | import time | ||||
from typing import Any, Dict, List, Optional | from typing import Any, Dict, List, Optional | ||||
from _pytest.python import Function | from _pytest.python import Function | ||||
from hypothesis import HealthCheck | from hypothesis import HealthCheck | ||||
from hypothesis import settings as hypothesis_settings | from hypothesis import settings as hypothesis_settings | ||||
import pytest | import pytest | ||||
Show All 34 Lines | from swh.web.tests.data import ( | ||||
random_sha256, | random_sha256, | ||||
) | ) | ||||
from swh.web.tests.helpers import create_django_permission | from swh.web.tests.helpers import create_django_permission | ||||
from swh.web.utils import browsers_supported_image_mimes, converters | from swh.web.utils import browsers_supported_image_mimes, converters | ||||
from swh.web.utils.typing import OriginVisitInfo | from swh.web.utils.typing import OriginVisitInfo | ||||
os.environ["LC_ALL"] = "C.UTF-8" | os.environ["LC_ALL"] = "C.UTF-8" | ||||
fossology_missing = shutil.which("nomossa") is None | |||||
# Register some hypothesis profiles | # Register some hypothesis profiles | ||||
hypothesis_settings.register_profile("default", hypothesis_settings()) | hypothesis_settings.register_profile("default", hypothesis_settings()) | ||||
# we use getattr here to keep mypy happy regardless hypothesis version | # we use getattr here to keep mypy happy regardless hypothesis version | ||||
function_scoped_fixture_check = ( | function_scoped_fixture_check = ( | ||||
[getattr(HealthCheck, "function_scoped_fixture")] | [getattr(HealthCheck, "function_scoped_fixture")] | ||||
if hasattr(HealthCheck, "function_scoped_fixture") | if hasattr(HealthCheck, "function_scoped_fixture") | ||||
else [] | else [] | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | def pytest_configure(config): | ||||
# that issue. | # that issue. | ||||
test_dir = os.path.dirname(__file__) | test_dir = os.path.dirname(__file__) | ||||
# location of the static folder when running tests through tox | # location of the static folder when running tests through tox | ||||
data_dir = os.path.join(sys.prefix, "share/swh/web") | data_dir = os.path.join(sys.prefix, "share/swh/web") | ||||
static_dir = os.path.join(data_dir, "static") | static_dir = os.path.join(data_dir, "static") | ||||
if not os.path.exists(static_dir): | if not os.path.exists(static_dir): | ||||
# location of the static folder when running tests locally with pytest | # location of the static folder when running tests locally with pytest | ||||
static_dir = os.path.join(test_dir, "../../../static") | static_dir = os.path.join(test_dir, "../../static") | ||||
webpack_stats = os.path.join(static_dir, "webpack-stats.json") | webpack_stats = os.path.join(static_dir, "webpack-stats.json") | ||||
if os.path.exists(webpack_stats): | if os.path.exists(webpack_stats): | ||||
return | return | ||||
django_apps_dir = os.path.join(test_dir, "../../../swh/web") | django_apps_dir = os.path.join(test_dir, "../../swh/web") | ||||
if not os.path.exists(django_apps_dir): | if not os.path.exists(django_apps_dir): | ||||
# location of the applications folder when running tests with tox | # location of the applications folder when running tests with tox | ||||
django_apps_dir = os.path.join(data_dir, "swh/web") | django_apps_dir = os.path.join(data_dir, "swh/web") | ||||
bundles = [] | bundles = [] | ||||
_, apps, _ = next(os.walk(django_apps_dir)) | _, apps, _ = next(os.walk(django_apps_dir)) | ||||
for app in apps: | for app in apps: | ||||
app_assets_dir = os.path.join(django_apps_dir, app, "assets") | app_assets_dir = os.path.join(django_apps_dir, app, "assets") | ||||
if os.path.exists(app_assets_dir): | if os.path.exists(app_assets_dir): | ||||
if os.path.exists(os.path.join(app_assets_dir, "index.js")): | if os.path.exists(os.path.join(app_assets_dir, "index.js")): | ||||
bundles.append(app) | bundles.append(app) | ||||
else: | else: | ||||
_, app_bundles, _ = next(os.walk(app_assets_dir)) | _, app_bundles, _ = next(os.walk(app_assets_dir)) | ||||
for app_bundle in app_bundles: | for app_bundle in app_bundles: | ||||
if os.path.exists( | if os.path.exists( | ||||
os.path.join(app_assets_dir, app_bundle, "index.js") | os.path.join(app_assets_dir, app_bundle, "index.js") | ||||
): | ): | ||||
bundles.append(app_bundle) | bundles.append(app_bundle) | ||||
print(bundles) | |||||
mock_webpack_stats = { | mock_webpack_stats = { | ||||
"status": "done", | "status": "done", | ||||
"publicPath": "/static", | "publicPath": "/static", | ||||
"chunks": {}, | "chunks": {}, | ||||
"assets": {}, | "assets": {}, | ||||
} | } | ||||
for bundle in bundles: | for bundle in bundles: | ||||
asset = f"js/{bundle}.js" | asset = f"js/{bundle}.js" | ||||
▲ Show 20 Lines • Show All 1,099 Lines • Show Last 20 Lines |