diff --git a/.gitignore b/.gitignore index bf71dc9db..2eea526a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,27 +1,28 @@ *.pyc *.sw? *~ \#* .\#* .coverage .eggs/ resources/test/ __pycache__ version.txt swh.web.egg-info docs/build/ docs/uri-scheme.md docs/dev-info.md *.sqlite3 .vscode/ .directory node_modules/ swh/web/static/*.* swh/web/static/js/ swh/web/static/css/ swh/web/static/fonts/ .cache-loader/ build/ dist/ .hypothesis -.pytest_cache +.cache +.pytest_cache \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in index e4f2f7c39..30e7328d3 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,8 +1,10 @@ include Makefile +include pytest.ini include requirements.txt include requirements-swh.txt +include requirements-test.txt include version.txt 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 c031570c0..75eadbab7 100644 --- a/Makefile.local +++ b/Makefile.local @@ -1,43 +1,38 @@ 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 -.PHONY: run-tests-migrations -run-tests-migrations: - rm -f swh/web/settings/testdb.sqlite3 2>/dev/null - django-admin migrate --settings=swh.web.settings.tests 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 run-tests-migrations +test: build-webpack-dev-no-verbose diff --git a/debian/control b/debian/control index 7f538bb07..a66538887 100644 --- a/debian/control +++ b/debian/control @@ -1,45 +1,46 @@ Source: swh-web Maintainer: Software Heritage developers Section: python Priority: optional Build-Depends: curl, debhelper (>= 9), dh-python (>= 2), python3-all, python3-bs4, python3-django (>= 1.10.7~), python3-djangorestframework (>= 3.4.0~), python3-django-webpack-loader, python3-django-js-reverse, python3-docutils, python3-htmlmin, python3-magic (>= 0.3.0~), python3-lxml, - python3-nose, + python3-pytest, + python3-pytest-django, python3-pygments, python3-pypandoc, python3-requests, python3-setuptools, python3-sphinx, python3-sphinxcontrib.httpdomain, python3-yaml, python3-swh.core (>= 0.0.40~), python3-swh.model (>= 0.0.25~), python3-swh.storage (>= 0.0.107~), python3-swh.indexer.storage (>= 0.0.52~), python3-swh.vault (>= 0.0.20~), python3-swh.scheduler (>= 0.0.31~) Standards-Version: 3.9.6 Homepage: https://forge.softwareheritage.org/diffusion/DWUI/ Package: python3-swh.web Architecture: all Depends: python3-swh.core (>= 0.0.40~), python3-swh.model (>= 0.0.25~), python3-swh.storage (>= 0.0.107~), python3-swh.indexer.storage (>= 0.0.52~), python3-swh.vault (>= 0.0.20~), python3-swh.scheduler (>= 0.0.31~), ${misc:Depends}, ${python3:Depends} Description: Software Heritage Web Applications diff --git a/debian/rules b/debian/rules index a9ea3b16d..20f5d221a 100755 --- a/debian/rules +++ b/debian/rules @@ -1,14 +1,12 @@ #!/usr/bin/make -f export PYBUILD_NAME=swh.web -export PYBUILD_TEST_ARGS=--with-doctest -sv ./swh/web/tests -export PYBUILD_BEFORE_TEST=cd {build_dir}; python3 swh/web/manage.py migrate -export PYBUILD_AFTER_TEST=cd {build_dir}; rm -f swh/web/settings/testdb.sqlite3 -export DJANGO_SETTINGS_MODULE=swh.web.settings.tests +export PYBUILD_OPTION=--test-pytest +export PYBUILD_TEST_ARGS=./swh/web/tests %: dh $@ --with python3 --buildsystem=pybuild override_dh_install: dh_install rm -v $(CURDIR)/debian/python3-*/usr/lib/python*/dist-packages/swh/__init__.py diff --git a/pytest.ini b/pytest.ini index ae6297c6b..c204cb150 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,4 @@ [pytest] norecursedirs = docs node_modules +DJANGO_SETTINGS_MODULE = swh.web.settings.tests + diff --git a/requirements-test.txt b/requirements-test.txt index f3c7e8e6f..395001ad6 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1 +1,3 @@ -nose +pytest +pytest-django + diff --git a/swh/web/settings/tests.py b/swh/web/settings/tests.py index 15edebc48..2a67b4f49 100644 --- a/swh/web/settings/tests.py +++ b/swh/web/settings/tests.py @@ -1,85 +1,79 @@ # Copyright (C) 2017-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 # flake8: noqa """ Django tests settings for swh-web. """ import os from swh.web.config import get_config scope1_limiter_rate = 3 scope1_limiter_rate_post = 1 scope2_limiter_rate = 5 scope2_limiter_rate_post = 2 scope3_limiter_rate = 1 scope3_limiter_rate_post = 1 swh_web_config = get_config() swh_web_config.update({ 'debug': True, 'secret_key': 'test', 'throttling': { 'cache_uri': None, 'scopes': { 'swh_api': { 'limiter_rate': { 'default': '60/min' }, 'exempted_networks': ['127.0.0.0/8'] }, 'swh_vault_cooking': { 'limiter_rate': { 'default': '120/h', 'GET': '60/m' }, 'exempted_networks': ['127.0.0.0/8'] }, 'swh_save_origin': { 'limiter_rate': { 'default': '120/h', 'POST': '10/h' }, 'exempted_networks': ['127.0.0.0/8'] }, 'scope1': { 'limiter_rate': { 'default': '%s/min' % scope1_limiter_rate, 'POST': '%s/min' % scope1_limiter_rate_post, } }, 'scope2': { 'limiter_rate': { 'default': '%s/min' % scope2_limiter_rate, 'POST': '%s/min' % scope2_limiter_rate_post } }, 'scope3': { 'limiter_rate': { 'default': '%s/min' % scope3_limiter_rate, 'POST': '%s/min' % scope3_limiter_rate_post }, 'exempted_networks': ['127.0.0.0/8'] } } } }) from .common import * ALLOWED_HOSTS += ['testserver'] -# As nose is used as a test runner, we cannot benefit from the in-memory -# django test database used when running tests through '$ python3 manage.py test'. -# So instead use a different database file that will be created on the fly -# when running the tests. -DATABASES['default']['NAME'] = os.path.join(PROJECT_DIR, 'testdb.sqlite3') - # Silent DEBUG output when running unit tests LOGGING['handlers']['console']['level'] = 'INFO' diff --git a/swh/web/tests/__init__.py b/swh/web/tests/__init__.py index 40814eea0..e69de29bb 100644 --- a/swh/web/tests/__init__.py +++ b/swh/web/tests/__init__.py @@ -1,13 +0,0 @@ -# Copyright (C) 2017-2018 The Software Heritage developers -# See the AUTHORS file at the top-level directory of this distribution -# License: GNU General Public License version 3, or any later version -# See top-level LICENSE file for more information - -# this configuration is needed to successfully run the tests locally -# when calling 'make test' - -import django -import os - -os.environ["DJANGO_SETTINGS_MODULE"] = "swh.web.settings.tests" -django.setup()