|
13 | 13 | # Make Django templates outside of Django.
|
14 | 14 | # Originally taken from: http://stackoverflow.com/a/98178/14343
|
15 | 15 | from django.conf import settings
|
16 |
| -test_settings = { |
17 |
| - 'CACHES': { |
18 |
| - 'default': { |
19 |
| - 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', |
| 16 | + |
| 17 | +def test_settings(): |
| 18 | + """Create a dict full of default Django settings for the tests.""" |
| 19 | + the_settings = { |
| 20 | + 'CACHES': { |
| 21 | + 'default': { |
| 22 | + 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', |
| 23 | + }, |
| 24 | + }, |
| 25 | + 'DATABASES': { |
| 26 | + 'default': { |
| 27 | + 'ENGINE': 'django.db.backends.sqlite3', |
| 28 | + 'NAME': ':memory:', |
| 29 | + } |
20 | 30 | },
|
21 |
| - }, |
22 |
| - 'DATABASES': { |
23 |
| - 'default': { |
24 |
| - 'ENGINE': 'django.db.backends.sqlite3', |
25 |
| - 'NAME': ':memory:', |
26 |
| - } |
27 |
| - }, |
28 |
| - 'ROOT_URLCONF': 'tests', |
29 |
| -} |
30 |
| - |
31 |
| -if django.VERSION >= (1, 8): |
32 |
| - test_settings.update({ |
33 |
| - 'TEMPLATES': [ |
34 |
| - { |
35 |
| - 'BACKEND': 'django.template.backends.django.DjangoTemplates', |
36 |
| - 'DIRS': ['templates'], # where the tests put things. |
37 |
| - 'OPTIONS': { |
38 |
| - 'debug': True, |
| 31 | + 'ROOT_URLCONF': 'tests', |
| 32 | + } |
| 33 | + |
| 34 | + if django.VERSION >= (1, 8): |
| 35 | + the_settings.update({ |
| 36 | + 'TEMPLATES': [ |
| 37 | + { |
| 38 | + 'BACKEND': 'django.template.backends.django.DjangoTemplates', |
| 39 | + 'DIRS': ['templates'], # where the tests put things. |
| 40 | + 'OPTIONS': { |
| 41 | + 'debug': True, |
| 42 | + }, |
39 | 43 | },
|
40 |
| - }, |
41 |
| - ], |
42 |
| - }) |
| 44 | + ], |
| 45 | + }) |
| 46 | + |
| 47 | + if django.VERSION < (1, 10): |
| 48 | + # for {% ssi %} |
| 49 | + the_settings['TEMPLATES'][0]['OPTIONS']['allowed_include_roots'] = ['/'] |
43 | 50 |
|
44 |
| - if django.VERSION < (1, 10): |
45 |
| - # for {% ssi %} |
46 |
| - test_settings['TEMPLATES'][0]['OPTIONS']['allowed_include_roots'] = ['/'] |
| 51 | + else: |
| 52 | + the_settings.update({ |
| 53 | + 'ALLOWED_INCLUDE_ROOTS': ['/'], # for {% ssi %} |
| 54 | + 'TEMPLATE_DEBUG': True, |
| 55 | + 'TEMPLATE_DIRS': ['templates'], # where the tests put things. |
| 56 | + }) |
47 | 57 |
|
48 |
| -else: |
49 |
| - test_settings.update({ |
50 |
| - 'ALLOWED_INCLUDE_ROOTS': ['/'], # for {% ssi %} |
51 |
| - 'TEMPLATE_DEBUG': True, |
52 |
| - 'TEMPLATE_DIRS': ['templates'], # where the tests put things. |
53 |
| - }) |
| 58 | + return the_settings |
54 | 59 |
|
55 |
| -settings.configure(**test_settings) |
| 60 | +settings.configure(**test_settings()) |
56 | 61 |
|
57 | 62 | if hasattr(django, "setup"):
|
58 | 63 | django.setup()
|
|
0 commit comments