diff --git a/debian/rules b/debian/rules index e0dd13c8..ca3fac06 100755 --- a/debian/rules +++ b/debian/rules @@ -1,12 +1,12 @@ #!/usr/bin/make -f export PYBUILD_NAME=swh.web -export PYBUILD_TEST_ARGS=--with-doctest -sv -a !db,!fs +export PYBUILD_TEST_ARGS=--with-doctest -sv ./swh/web/tests export DJANGO_SETTINGS_MODULE=swh.web.settings.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/swh/web/settings/development.py b/swh/web/settings/development.py index feabdae2..d1f9563b 100644 --- a/swh/web/settings/development.py +++ b/swh/web/settings/development.py @@ -1,23 +1,19 @@ # 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 development settings for swh-web. """ import os -# guard to avoid side effects on the django settings when building the -# Debian package for swh-web -if os.environ['DJANGO_SETTINGS_MODULE'] == 'swh.web.settings.development': +from .common import * - from .common import * +MIDDLEWARE += ['swh.web.common.middlewares.HtmlPrettifyMiddleware'] - MIDDLEWARE += ['swh.web.common.middlewares.HtmlPrettifyMiddleware'] - - from django.core.cache import cache - cache.clear() +from django.core.cache import cache +cache.clear() diff --git a/swh/web/settings/production.py b/swh/web/settings/production.py index a03afc6a..0fc1af2d 100644 --- a/swh/web/settings/production.py +++ b/swh/web/settings/production.py @@ -1,50 +1,46 @@ # 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 production settings for swh-web. """ import os -# guard to avoid side effects on the django settings when building the -# Debian package for swh-web -if os.environ['DJANGO_SETTINGS_MODULE'] == 'swh.web.settings.production': - - from .common import * - from .common import swh_web_config - from .common import REST_FRAMEWORK - - # activate per-site caching - if 'GZip' in MIDDLEWARE[0]: - MIDDLEWARE.insert(1, 'django.middleware.cache.UpdateCacheMiddleware') - else: - MIDDLEWARE.insert(0, 'django.middleware.cache.UpdateCacheMiddleware') - - MIDDLEWARE += ['swh.web.common.middlewares.HtmlMinifyMiddleware', - 'django.middleware.cache.FetchFromCacheMiddleware'] - - CACHES = { - 'default': { - 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', - 'LOCATION': swh_web_config['throttling']['cache_uri'], - } +from .common import * +from .common import swh_web_config +from .common import REST_FRAMEWORK + +# activate per-site caching +if 'GZip' in MIDDLEWARE[0]: + MIDDLEWARE.insert(1, 'django.middleware.cache.UpdateCacheMiddleware') +else: + MIDDLEWARE.insert(0, 'django.middleware.cache.UpdateCacheMiddleware') + +MIDDLEWARE += ['swh.web.common.middlewares.HtmlMinifyMiddleware', + 'django.middleware.cache.FetchFromCacheMiddleware'] + +CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', + 'LOCATION': swh_web_config['throttling']['cache_uri'], } +} - # Setup support for proxy headers - USE_X_FORWARDED_HOST = True - SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') +# Setup support for proxy headers +USE_X_FORWARDED_HOST = True +SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') - # We're going through seven (or, in that case, 2) proxies thanks to Varnish - REST_FRAMEWORK['NUM_PROXIES'] = 2 +# We're going through seven (or, in that case, 2) proxies thanks to Varnish +REST_FRAMEWORK['NUM_PROXIES'] = 2 - ALLOWED_HOSTS += [ - 'archive.softwareheritage.org', - 'base.softwareheritage.org', - 'archive.internal.softwareheritage.org', - ] +ALLOWED_HOSTS += [ + 'archive.softwareheritage.org', + 'base.softwareheritage.org', + 'archive.internal.softwareheritage.org', +] diff --git a/swh/web/settings/tests.py b/swh/web/settings/tests.py index 9edac6cd..ad81700e 100644 --- a/swh/web/settings/tests.py +++ b/swh/web/settings/tests.py @@ -1,73 +1,69 @@ # 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 -# guard to avoid side effects on the django settings when building the -# Debian package for swh-web -if os.environ['DJANGO_SETTINGS_MODULE'] == 'swh.web.settings.tests': +from swh.web.config import get_config - 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 - 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 = 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'] - }, - 'scope1': { - 'limiter_rate': { - 'default': '%s/min' % scope1_limiter_rate, - 'POST': '%s/min' % scope1_limiter_rate_post, - } +swh_web_config.update({ + 'debug': True, + 'secret_key': 'test', + 'throttling': { + 'cache_uri': None, + 'scopes': { + 'swh_api': { + 'limiter_rate': { + 'default': '60/min' }, - 'scope2': { - 'limiter_rate': { - 'default': '%s/min' % scope2_limiter_rate, - 'POST': '%s/min' % scope2_limiter_rate_post - } + 'exempted_networks': ['127.0.0.0/8'] + }, + 'swh_vault_cooking': { + 'limiter_rate': { + 'default': '120/h', + 'GET': '60/m' }, - 'scope3': { - 'limiter_rate': { - 'default': '%s/min' % scope3_limiter_rate, - 'POST': '%s/min' % scope3_limiter_rate_post - }, - 'exempted_networks': ['127.0.0.0/8'] + '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 * +from .common import * - ALLOWED_HOSTS += ['testserver'] \ No newline at end of file +ALLOWED_HOSTS += ['testserver'] \ No newline at end of file