diff --git a/.github/workflows/ci-django-tests.yml b/.github/workflows/ci-django-tests.yml index 9b547c5..40fb65e 100644 --- a/.github/workflows/ci-django-tests.yml +++ b/.github/workflows/ci-django-tests.yml @@ -25,6 +25,5 @@ jobs: - name: Run Tests run: | cd agate - mv core/local_settings.test.py core/local_settings.py - coverage run manage.py test + coverage run manage.py test --settings="core.local_settings_test" coverage report diff --git a/agate/core/settings.py b/agate/core/base_settings.py similarity index 84% rename from agate/core/settings.py rename to agate/core/base_settings.py index f1d4764..c37c493 100644 --- a/agate/core/settings.py +++ b/agate/core/base_settings.py @@ -1,13 +1,10 @@ import os -import sys # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) TEMPLATE_DIR = os.path.join(BASE_DIR, 'core/templates') - # Application definition - INSTALLED_APPS = [ # Django default apps 'django.contrib.admin', @@ -110,18 +107,6 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' -# Import local_settings.py -SECRET_KEY = None -try: - from .local_settings import * # NOQA -except ImportError: - sys.exit('Unable to import local_settings.py (refer to local_settings.example.py for help)') - -# Ensure the SECRET_KEY is supplied in local_settings.py - and trust that the other settings are there too. -if not SECRET_KEY: # NOQA - sys.exit('Missing SECRET_KEY in local_settings.py') - - # Storages # Default STORAGES from Django documentation @@ -131,13 +116,7 @@ "staticfiles": {"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage"}, } -# Use ManifestStaticFilesStorage when not in debug mode -if not DEBUG: # NOQA - STORAGES['staticfiles'] = {"BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"} - - # Logging - LOGGING = { 'version': 1, 'disable_existing_loggers': False, @@ -160,9 +139,16 @@ }, }, 'handlers': { - 'stream': { + 'stream_debug': { + 'class': 'logging.StreamHandler', + 'filters': ['require_debug_true'], + 'level': 'DEBUG', # NOQA + 'formatter': 'verbose', + }, + 'stream_prod': { 'class': 'logging.StreamHandler', - 'level': 'DEBUG' if DEBUG else 'INFO', # NOQA + 'filters': ['require_debug_false'], + 'level': os.getenv("DJANGO_LOG_LEVEL", "INFO"), # NOQA 'formatter': 'verbose', }, 'file': { @@ -181,8 +167,8 @@ }, 'loggers': { 'django': { - 'handlers': ['stream', 'file', 'mail_admins'], - 'level': 'DEBUG' if DEBUG else 'INFO', # NOQA + 'handlers': ['stream_debug', 'stream_prod', 'file', 'mail_admins'], + 'level': 'DEBUG', # NOQA 'propagate': 'True', }, }, diff --git a/agate/core/local_settings.test.py b/agate/core/local_settings_test.py similarity index 71% rename from agate/core/local_settings.test.py rename to agate/core/local_settings_test.py index a34de82..1c7cf8d 100644 --- a/agate/core/local_settings.test.py +++ b/agate/core/local_settings_test.py @@ -8,7 +8,8 @@ import os from empty_message_retrieval import EmptyMessageRetrieval -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +from .base_settings import * # noqa: F403 +from .base_settings import BASE_DIR, STORAGES SECRET_KEY = 'u6n(9&8g-3=6d1#jyp^#))you-h&y^-5y7*&hu)cpxzeu_7#j+' @@ -16,7 +17,7 @@ ALLOWED_HOSTS = ['*'] -ADMIN_EMAIL = 'bear-rsg@contacts.bham.ac.uk' +# ADMIN_EMAIL = 'bear-rsg@contacts.bham.ac.uk' DATABASES = { 'default': { @@ -33,3 +34,7 @@ MESSAGE_RETRIEVAL = EmptyMessageRetrieval() LIMITED_PROJECT_LIST = ["synthscape"] + +# Use ManifestStaticFilesStorage when not in debug mode +if not DEBUG: # NOQA + STORAGES['staticfiles'] = {"BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"} diff --git a/agate/manage.py b/agate/manage.py index 52c2189..a0d0781 100644 --- a/agate/manage.py +++ b/agate/manage.py @@ -3,7 +3,7 @@ import sys if __name__ == '__main__': - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.local_settings') try: from django.core.management import execute_from_command_line except ImportError as exc: