mirror of
https://github.com/django/django.git
synced 2025-10-28 16:16:12 +00:00
Isolated template tests from Django settings.
This commit is contained in:
@@ -1,40 +1,34 @@
|
||||
import os
|
||||
import warnings
|
||||
|
||||
from django.test import override_settings, SimpleTestCase
|
||||
from django.utils._os import upath
|
||||
from django.test import SimpleTestCase
|
||||
from django.utils.deprecation import RemovedInDjango19Warning
|
||||
|
||||
from ..utils import render, setup
|
||||
from ..utils import ROOT, setup
|
||||
|
||||
|
||||
cwd = os.path.dirname(os.path.abspath(upath(__file__)))
|
||||
root = os.path.abspath(os.path.join(cwd, ".."))
|
||||
|
||||
|
||||
@override_settings(ALLOWED_INCLUDE_ROOTS=(root))
|
||||
class SsiTagTests(SimpleTestCase):
|
||||
|
||||
# Test normal behavior
|
||||
@setup({'ssi01': '{%% ssi "%s" %%}' % os.path.join(
|
||||
root, 'templates', 'ssi_include.html',
|
||||
ROOT, 'templates', 'ssi_include.html',
|
||||
)})
|
||||
def test_ssi01(self):
|
||||
output = render('ssi01')
|
||||
output = self.engine.render_to_string('ssi01')
|
||||
self.assertEqual(output, 'This is for testing an ssi include. {{ test }}\n')
|
||||
|
||||
@setup({'ssi02': '{%% ssi "%s" %%}' % os.path.join(
|
||||
root, 'not_here',
|
||||
ROOT, 'not_here',
|
||||
)})
|
||||
def test_ssi02(self):
|
||||
output = render('ssi02')
|
||||
output = self.engine.render_to_string('ssi02')
|
||||
self.assertEqual(output, ''),
|
||||
|
||||
@setup({'ssi03': "{%% ssi '%s' %%}" % os.path.join(
|
||||
root, 'not_here',
|
||||
ROOT, 'not_here',
|
||||
)})
|
||||
def test_ssi03(self):
|
||||
output = render('ssi03')
|
||||
output = self.engine.render_to_string('ssi03')
|
||||
self.assertEqual(output, ''),
|
||||
|
||||
# Test passing as a variable
|
||||
@@ -42,8 +36,8 @@ class SsiTagTests(SimpleTestCase):
|
||||
def test_ssi04(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango19Warning)
|
||||
output = render('ssi04', {
|
||||
'ssi_file': os.path.join(root, 'templates', 'ssi_include.html')
|
||||
output = self.engine.render_to_string('ssi04', {
|
||||
'ssi_file': os.path.join(ROOT, 'templates', 'ssi_include.html')
|
||||
})
|
||||
self.assertEqual(output, 'This is for testing an ssi include. {{ test }}\n')
|
||||
|
||||
@@ -51,38 +45,38 @@ class SsiTagTests(SimpleTestCase):
|
||||
def test_ssi05(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango19Warning)
|
||||
output = render('ssi05', {'ssi_file': 'no_file'})
|
||||
output = self.engine.render_to_string('ssi05', {'ssi_file': 'no_file'})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
# Test parsed output
|
||||
@setup({'ssi06': '{%% ssi "%s" parsed %%}' % os.path.join(
|
||||
root, 'templates', 'ssi_include.html',
|
||||
ROOT, 'templates', 'ssi_include.html',
|
||||
)})
|
||||
def test_ssi06(self):
|
||||
output = render('ssi06', {'test': 'Look ma! It parsed!'})
|
||||
output = self.engine.render_to_string('ssi06', {'test': 'Look ma! It parsed!'})
|
||||
self.assertEqual(output, 'This is for testing an ssi include. '
|
||||
'Look ma! It parsed!\n')
|
||||
|
||||
@setup({'ssi07': '{%% ssi "%s" parsed %%}' % os.path.join(
|
||||
root, 'not_here',
|
||||
ROOT, 'not_here',
|
||||
)})
|
||||
def test_ssi07(self):
|
||||
output = render('ssi07', {'test': 'Look ma! It parsed!'})
|
||||
output = self.engine.render_to_string('ssi07', {'test': 'Look ma! It parsed!'})
|
||||
self.assertEqual(output, '')
|
||||
|
||||
# Test space in file name
|
||||
@setup({'ssi08': '{%% ssi "%s" %%}' % os.path.join(
|
||||
root, 'templates', 'ssi include with spaces.html',
|
||||
ROOT, 'templates', 'ssi include with spaces.html',
|
||||
)})
|
||||
def test_ssi08(self):
|
||||
output = render('ssi08')
|
||||
output = self.engine.render_to_string('ssi08')
|
||||
self.assertEqual(output, 'This is for testing an ssi include '
|
||||
'with spaces in its name. {{ test }}\n')
|
||||
|
||||
@setup({'ssi09': '{%% ssi "%s" parsed %%}' % os.path.join(
|
||||
root, 'templates', 'ssi include with spaces.html',
|
||||
ROOT, 'templates', 'ssi include with spaces.html',
|
||||
)})
|
||||
def test_ssi09(self):
|
||||
output = render('ssi09', {'test': 'Look ma! It parsed!'})
|
||||
output = self.engine.render_to_string('ssi09', {'test': 'Look ma! It parsed!'})
|
||||
self.assertEqual(output, 'This is for testing an ssi include '
|
||||
'with spaces in its name. Look ma! It parsed!\n')
|
||||
|
||||
Reference in New Issue
Block a user