Skip to content

Commit

Permalink
A better way to manage test settings
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Dec 5, 2015
1 parent fbb8af8 commit c74a007
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 39 deletions.
75 changes: 40 additions & 35 deletions tests/plugin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,51 @@
# Make Django templates outside of Django.
# Originally taken from: http://stackoverflow.com/a/98178/14343
from django.conf import settings
test_settings = {
'CACHES': {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',

def test_settings():
"""Create a dict full of default Django settings for the tests."""
the_settings = {
'CACHES': {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
},
},
'DATABASES': {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
},
},
'DATABASES': {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
},
'ROOT_URLCONF': 'tests',
}

if django.VERSION >= (1, 8):
test_settings.update({
'TEMPLATES': [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates'], # where the tests put things.
'OPTIONS': {
'debug': True,
'ROOT_URLCONF': 'tests',
}

if django.VERSION >= (1, 8):
the_settings.update({
'TEMPLATES': [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates'], # where the tests put things.
'OPTIONS': {
'debug': True,
},
},
},
],
})
],
})

if django.VERSION < (1, 10):
# for {% ssi %}
the_settings['TEMPLATES'][0]['OPTIONS']['allowed_include_roots'] = ['/']

if django.VERSION < (1, 10):
# for {% ssi %}
test_settings['TEMPLATES'][0]['OPTIONS']['allowed_include_roots'] = ['/']
else:
the_settings.update({
'ALLOWED_INCLUDE_ROOTS': ['/'], # for {% ssi %}
'TEMPLATE_DEBUG': True,
'TEMPLATE_DIRS': ['templates'], # where the tests put things.
})

else:
test_settings.update({
'ALLOWED_INCLUDE_ROOTS': ['/'], # for {% ssi %}
'TEMPLATE_DEBUG': True,
'TEMPLATE_DIRS': ['templates'], # where the tests put things.
})
return the_settings

settings.configure(**test_settings)
settings.configure(**test_settings())

if hasattr(django, "setup"):
django.setup()
Expand Down
6 changes: 2 additions & 4 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
"""Settings tests for django_coverage_plugin."""

import copy

import django
from django.test.utils import override_settings

from django_coverage_plugin import DjangoTemplatePluginException

from .plugin_test import DjangoPluginTestCase, test_settings
from .plugin_test import DjangoPluginTestCase, test_settings, django_start_at


if django.VERSION >= (1, 8):
DEBUG_FALSE_OVERRIDES = {
'TEMPLATES': [copy.deepcopy(test_settings['TEMPLATES'][0])]
'TEMPLATES': [test_settings()['TEMPLATES'][0]]
}
DEBUG_FALSE_OVERRIDES['TEMPLATES'][0]['OPTIONS']['debug'] = False
else:
Expand Down

0 comments on commit c74a007

Please # to comment.