create a deployment check to ensure USE_TZ is enabled

Fixes #1086
This commit is contained in:
Andrew Fyfe
2018-01-12 18:36:11 +00:00
parent 68b3158d08
commit 21a3164b77
4 changed files with 58 additions and 0 deletions
+2
View File
@@ -29,6 +29,8 @@ class CoreConfig(AppConfig):
def ready(self):
load_core_settings()
# Import these to force registration of checks and signals
from . import checks # noqa:F401
from . import handlers
signals.post_migrate.connect(handlers.create_local_config, sender=self)
+4
View File
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Import these to force registration of checks
from . import settings_checks # noqa:F401
+29
View File
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.conf import settings
from django.core.checks import Warning, register
from django.utils.translation import ugettext as _
W001 = Warning(
_("You have USE_TZ set to False, this may result in issues during "
"transitions between summer/winter time (ie the same local time occuring "
"twice due to clock change)."),
hint=_("Set `USE_TZ = True` in settings.py"),
id="modoboa.W001",
)
@register(deploy=True)
def check_use_tz_enabled(app_configs, **kwargs):
"""Ensure USE_TZ is enabled in settings.py
When USE_TZ is enabled all date/times are stored in UTC.
Fixes #1086 - https://github.com/modoboa/modoboa/issues/1086
"""
errors = []
if not settings.USE_TZ:
errors.append(W001)
return errors
+23
View File
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import SimpleTestCase
from django.test.utils import override_settings
from ..checks import settings_checks
class CheckSessionCookieSecureTest(SimpleTestCase):
@override_settings(USE_TZ=False)
def test_use_tz_false(self):
"""If USE_TZ is off provide one warning."""
self.assertEqual(
settings_checks.check_use_tz_enabled(None),
[settings_checks.W001]
)
@override_settings(USE_TZ=True)
def test_use_tz_true(self):
"""If USE_TZ is on, there's no warning about it."""
self.assertEqual(settings_checks.check_use_tz_enabled(None), [])