Skip to content

Commit

Permalink
More bad-settings cases to test.
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Dec 6, 2015
1 parent c74a007 commit 99ba553
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
14 changes: 4 additions & 10 deletions django_coverage_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,12 @@ def check_debug():
from django.conf import settings
templates = settings.TEMPLATES
if len(templates) > 1:
raise DjangoTemplatePluginException(
"Can't use multiple template engines, help me add support!"
)
raise DjangoTemplatePluginException("Can't use multiple template engines.")
template_settings = templates[0]
if template_settings['BACKEND'] != 'django.template.backends.django.DjangoTemplates':
raise DjangoTemplatePluginException(
"Can't use non-Django templates!"
)
if not template_settings['OPTIONS']['debug']:
raise DjangoTemplatePluginException(
"Template debugging must be enabled in settings."
)
raise DjangoTemplatePluginException("Can't use non-Django templates.")
if not template_settings.get('OPTIONS', {}).get('debug', False):
raise DjangoTemplatePluginException("Template debugging must be enabled in settings.")
else:
def check_debug():
from django.conf import settings
Expand Down
4 changes: 1 addition & 3 deletions tests/plugin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
from coverage.test_helpers import TempDirMixin

import django

# Make Django templates outside of Django.
# Originally taken from: http://stackoverflow.com/a/98178/14343
from django.conf import settings


def test_settings():
"""Create a dict full of default Django settings for the tests."""
the_settings = {
Expand Down
44 changes: 41 additions & 3 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,27 @@
from .plugin_test import DjangoPluginTestCase, test_settings, django_start_at


# Make settings overrides for tests below.
if django.VERSION >= (1, 8):
DEBUG_FALSE_OVERRIDES = {
'TEMPLATES': [test_settings()['TEMPLATES'][0]]
}
NON_DJANGO_BACKEND = 'django.template.backends.dummy.TemplateStrings'

DEBUG_FALSE_OVERRIDES = test_settings()
DEBUG_FALSE_OVERRIDES['TEMPLATES'][0]['OPTIONS']['debug'] = False

NO_OPTIONS_OVERRIDES = test_settings()
del NO_OPTIONS_OVERRIDES['TEMPLATES'][0]['OPTIONS']

MULTIPLE_ENGINE_OVERRIDES = test_settings()
MULTIPLE_ENGINE_OVERRIDES['TEMPLATES'].append({
'BACKEND': NON_DJANGO_BACKEND,
})

OTHER_ENGINE_OVERRIDES = test_settings()
OTHER_ENGINE_OVERRIDES['TEMPLATES'][0]['BACKEND'] = NON_DJANGO_BACKEND
OTHER_ENGINE_OVERRIDES['TEMPLATES'][0]['OPTIONS'] = {}
else:
DEBUG_FALSE_OVERRIDES = {'TEMPLATE_DEBUG': False}
NO_OPTIONS_OVERRIDES = MULTIPLE_ENGINE_OVERRIDES = OTHER_ENGINE_OVERRIDES = {}


class SettingsTest(DjangoPluginTestCase):
Expand All @@ -25,3 +39,27 @@ def test_debug_false(self):
msg = "Template debugging must be enabled in settings."
with self.assertRaisesRegexp(DjangoTemplatePluginException, msg):
self.run_django_coverage()

@django_start_at(1, 8)
@override_settings(**NO_OPTIONS_OVERRIDES)
def test_no_options(self):
self.make_template('Hello')
msg = "Template debugging must be enabled in settings."
with self.assertRaisesRegexp(DjangoTemplatePluginException, msg):
self.run_django_coverage()

@django_start_at(1, 8)
@override_settings(**MULTIPLE_ENGINE_OVERRIDES)
def test_multiple_engines(self):
self.make_template('Hello')
msg = "Can't use multiple template engines."
with self.assertRaisesRegexp(DjangoTemplatePluginException, msg):
self.run_django_coverage()

@django_start_at(1, 8)
@override_settings(**OTHER_ENGINE_OVERRIDES)
def test_other_engine(self):
self.make_template('Hello')
msg = "Can't use non-Django templates."
with self.assertRaisesRegexp(DjangoTemplatePluginException, msg):
self.run_django_coverage()

0 comments on commit 99ba553

Please # to comment.