Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
venv
env
__pycache__
.venv
.cache
2 changes: 1 addition & 1 deletion web/docker_django/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
SECRET_KEY = os.environ['SECRET_KEY']

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True if os.getenv('DEBUG') == 'true' else False
DEBUG = os.getenv('DEBUG', 'NO').lower() in ('on', 'true', 'y', 'yes')

ALLOWED_HOSTS = ['*']

Expand Down
Empty file added web/tests/__init__.py
Empty file.
38 changes: 38 additions & 0 deletions web/tests/test_env_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Test Environmental settings are handled properly."""


import os
import importlib
from unittest.mock import patch
# from django.test import TestCase
# from unittest import skip
# we have to use tools outside of django, because when it's initialized
# it's too late to change environment variables
from unittest import TestCase, main


class DebugSettingTest(TestCase):
"""Test if setting DEBUG is handled properly."""

_variants = {
True: ('Yes', 'YES', 'Y', 'TRUE', 'tRUE', 'true', 'On'),

False: ('No', 'nO', 'N', 'n', 'false', 'False', 'off', 'oFF'),
}
env_var_debug = 'DEBUG'

def test_debug_setting(self):
"""Check if config accepts environment variable DEBUG and sets it."""
from docker_django import settings
for result, words in self._variants.items():
for word in words:
# print(word, result)
with patch.dict('os.environ', {self.env_var_debug: word}):
importlib.reload(settings)
assert self.env_var_debug in os.environ
self.assertEqual(settings.DEBUG, result)
assert self.env_var_debug not in os.environ # should be True


if __name__ == '__main__':
main()