From 0ece2664acca078e8934eb9853c53adf248fc0b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Tue, 6 Nov 2018 10:48:59 +0200 Subject: [PATCH] Show a warning when running with DEBUG=True. Fixes #189 --- CHANGELOG.md | 1 + hc/front/templatetags/hc_extras.py | 12 ++++++++++++ hc/front/tests/test_basics.py | 8 ++++++-- static/css/base.css | 7 +++++++ templates/base.html | 1 + 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bd8907b..5e2f6e9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. - Add search box in the "My Checks" page - Add read-only API key support - Remove Profile.bill_to field (obsolete) +- Show a warning when running with DEBUG=True ### Bug Fixes - During DST transition, handle ambiguous dates as pre-transition diff --git a/hc/front/templatetags/hc_extras.py b/hc/front/templatetags/hc_extras.py index 62f3952b..2ebed6e7 100644 --- a/hc/front/templatetags/hc_extras.py +++ b/hc/front/templatetags/hc_extras.py @@ -35,6 +35,18 @@ def site_root(): return settings.SITE_ROOT +@register.simple_tag +def debug_warning(): + if settings.DEBUG: + return mark_safe(""" +
+ Running in debug mode, do not use in production. +
+ """) + + return "" + + def naturalize_int_match(match): return '%08d' % (int(match.group(0)),) diff --git a/hc/front/tests/test_basics.py b/hc/front/tests/test_basics.py index 43f9ad14..95098968 100644 --- a/hc/front/tests/test_basics.py +++ b/hc/front/tests/test_basics.py @@ -1,14 +1,18 @@ from django.test import TestCase from django.test.utils import override_settings -from hc.api.models import Check - class BasicsTestCase(TestCase): def test_it_shows_welcome(self): r = self.client.get("/") self.assertContains(r, "Get Notified", status_code=200) + self.assertNotContains(r, "do not use in production") + + @override_settings(DEBUG=True) + def test_it_shows_debug_warning(self): + r = self.client.get("/") + self.assertContains(r, "do not use in production") @override_settings(REGISTRATION_OPEN=False) def test_it_obeys_registration_open(self): diff --git a/static/css/base.css b/static/css/base.css index 4084357e..932c5899 100644 --- a/static/css/base.css +++ b/static/css/base.css @@ -93,3 +93,10 @@ pre { .jumbotron p { font-weight: 300; } + +#debug-warning { + background: #eeeeee; + text-align: center; + font-size: small; + padding: 2px 0; +} \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 114474cf..a8a9804c 100644 --- a/templates/base.html +++ b/templates/base.html @@ -46,6 +46,7 @@ {% endcompress %} + {% debug_warning %}