diff --git a/django_coverage_plugin/plugin.py b/django_coverage_plugin/plugin.py index 19b472c..e1c25da 100644 --- a/django_coverage_plugin/plugin.py +++ b/django_coverage_plugin/plugin.py @@ -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 diff --git a/tests/plugin_test.py b/tests/plugin_test.py index aec7302..a8546d8 100644 --- a/tests/plugin_test.py +++ b/tests/plugin_test.py @@ -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 = { diff --git a/tests/test_settings.py b/tests/test_settings.py index de606f5..2591035 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -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): @@ -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()