Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/conftest.py
# Copyright (C) 2018-2019 The Software Heritage developers | # Copyright (C) 2018-2019 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 | ||||
import inspect | import inspect | ||||
import json | import json | ||||
import os | import os | ||||
import shutil | import shutil | ||||
import sys | |||||
from subprocess import run, PIPE | from subprocess import run, PIPE | ||||
import pytest | import pytest | ||||
from django.core.cache import cache | from django.core.cache import cache | ||||
from hypothesis import settings, HealthCheck | from hypothesis import settings, HealthCheck | ||||
from rest_framework.test import APIClient, APIRequestFactory | from rest_framework.test import APIClient, APIRequestFactory | ||||
Show All 31 Lines | def pytest_configure(config): | ||||
# without static assets generated by webpack. | # without static assets generated by webpack. | ||||
# Those assets are not really needed for the Python tests | # Those assets are not really needed for the Python tests | ||||
# but the django templates will fail to load due to missing | # but the django templates will fail to load due to missing | ||||
# generated file webpack-stats.json describing the js and css | # generated file webpack-stats.json describing the js and css | ||||
# files to include. | # files to include. | ||||
# So generate a dummy webpack-stats.json file to overcome | # So generate a dummy webpack-stats.json file to overcome | ||||
# that issue. | # that issue. | ||||
test_dir = os.path.dirname(__file__) | test_dir = os.path.dirname(__file__) | ||||
static_dir = os.path.join(test_dir, '../static') | # location of the static folder when running tests through tox | ||||
vlorentzUnsubmitted Not Done Inline Actionsvlorentz: ```
static_dir = os.path.join(sys.prefix, 'share/swh/web/static')
``` | |||||
Not Done Inline ActionsOr static_dir = pkg_resources.resource_string('swh.web', 'static') vlorentz: Or `static_dir = pkg_resources.resource_string('swh.web', 'static')` | |||||
Done Inline ActionsRight ! The pkg_resources approach does not seem to work after a quick test as it will try to locate resources inside the module folder but data files are located in a different one. So I will go for the classic os.path.join approach. anlambert: Right ! The `pkg_resources` approach does not seem to work after a quick test as it will try to… | |||||
Not Done Inline ActionsThere's an extra leading slash vlorentz: There's an extra leading slash | |||||
static_dir = os.path.join(sys.prefix, 'share/swh/web/static') | |||||
if not os.path.exists(static_dir): | |||||
# location of the static folder when running tests locally with pytest | |||||
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 | ||||
bundles_dir = os.path.join(test_dir, '../assets/src/bundles') | bundles_dir = os.path.join(test_dir, '../assets/src/bundles') | ||||
_, dirs, _ = next(os.walk(bundles_dir)) | _, dirs, _ = next(os.walk(bundles_dir)) | ||||
mock_webpack_stats = { | mock_webpack_stats = { | ||||
'status': 'done', | 'status': 'done', | ||||
'publicPath': '/static', | 'publicPath': '/static', | ||||
▲ Show 20 Lines • Show All 236 Lines • Show Last 20 Lines |