diff --git a/MANIFEST.in b/MANIFEST.in index 21963a510..05a3d01d5 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,11 +1,12 @@ include Makefile include pytest.ini include requirements.txt include requirements-swh.txt include requirements-test.txt include tox.ini include version.txt +recursive-include swh/web/assets * recursive-include swh/web/static * recursive-include swh/web/templates * include swh/web/tests/browse/views/data/swh-logo.png include swh/web/tests/browse/views/data/iso-8859-1_encoded_content diff --git a/Makefile.local b/Makefile.local index 75eadbab7..a3e834c1e 100644 --- a/Makefile.local +++ b/Makefile.local @@ -1,38 +1,37 @@ TEST_DIRS := ./swh/web/tests .PHONY: build-webpack-dev build-webpack-dev: npm run build-dev .PHONY: build-webpack-dev-no-verbose build-webpack-dev-no-verbose: npm run build-dev >/dev/null .PHONY: build-webpack-prod build-webpack-prod: npm run build .PHONY: run-migrations run-migrations: python3 swh/web/manage.py migrate 2>/dev/null run-django-webpack-devserver: run-migrations bash -c "trap 'trap - SIGINT SIGTERM ERR; kill %1' SIGINT SIGTERM ERR; npm run start-dev & cd swh/web && python3 manage.py runserver --nostatic" run-django-webpack-dev: build-webpack-dev run-migrations python3 swh/web/manage.py runserver --nostatic run-django-webpack-prod: build-webpack-prod run-migrations python3 swh/web/manage.py runserver --nostatic --settings=swh.web.settings.production run-django-server-dev: run-migrations python3 swh/web/manage.py runserver --nostatic run-django-server-prod: run-migrations python3 swh/web/manage.py runserver --nostatic --settings=swh.web.settings.production run-gunicorn-server: run-migrations gunicorn3 -b 127.0.0.1:5004 swh.web.wsgi -test: build-webpack-dev-no-verbose diff --git a/swh/web/tests/conftest.py b/swh/web/tests/conftest.py new file mode 100644 index 000000000..e2c981433 --- /dev/null +++ b/swh/web/tests/conftest.py @@ -0,0 +1,40 @@ +# Copyright (C) 2018 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU Affero General Public License version 3, or any later version +# See top-level LICENSE file for more information + +import json +import os + + +def pytest_configure(config): + # Small hack in order to be able to run the unit tests + # without static assets generated by webpack. + # Those assets are not really needed for the Python tests + # but the django templates will fail to load due to missing + # generated file webpack-stats.json describing the js and css + # files to include. + # So generate a dummy webpack-stats.json file to overcome + # that issue. + test_dir = os.path.dirname(__file__) + static_dir = os.path.join(test_dir, '../static') + webpack_stats = os.path.join(static_dir, 'webpack-stats.json') + if os.path.exists(webpack_stats): + return + bundles_dir = os.path.join(test_dir, '../assets/src/bundles') + _, dirs, _ = next(os.walk(bundles_dir)) + mock_webpack_stats = { + 'status': 'done', + 'publicPath': '/static', + 'chunks': {} + } + for bundle in dirs: + asset = 'js/%s.js' % bundle + mock_webpack_stats['chunks'][bundle] = [{ + 'name': asset, + 'publicPath': '/static/%s' % asset, + 'path': os.path.join(static_dir, asset) + }] + + with open(webpack_stats, 'w') as outfile: + json.dump(mock_webpack_stats, outfile)