-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtests.py
51 lines (42 loc) · 1.29 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import django
import pytest # noqa
from copy import deepcopy
from django.conf import settings
from django.template.base import Context, Template
try:
from django.test import override_settings
except ImportError: # Django < 1.7
from django.test.utils import override_settings
cached_template_settings = {}
if django.VERSION < (1, 8):
cached_template_settings['TEMPLATE_LOADERS'] = [
('django.template.loaders.cached.Loader', settings.TEMPLATE_LOADERS)
]
else:
TEMPLATES = deepcopy(settings.TEMPLATES)
opt = TEMPLATES[0]['OPTIONS']
opt['loaders'] = [
('django.template.loaders.cached.Loader', opt['loaders'])
]
cached_template_settings['TEMPLATES'] = TEMPLATES
def test_import():
"""
Importing this module should not fail.
"""
import apptemplates
assert apptemplates.__name__ == 'apptemplates'
def test_render():
"""
Test-drive the apptemplate code base by rendering a template.
"""
c = Context()
t = Template('{% extends "admin:admin/base.html" %}')
t.render(c)
@override_settings(**cached_template_settings)
def test_cached():
"""
Test that the template still works when the cached loader is being used.
"""
c = Context()
t = Template('{% extends "admin:admin/base.html" %}')
t.render(c)