2014-11-12 09:32:44 +08:00
|
|
|
import os
|
|
|
|
|
2015-01-28 20:35:27 +08:00
|
|
|
from django.test import SimpleTestCase, ignore_warnings
|
2015-01-18 02:29:52 +08:00
|
|
|
from django.utils.deprecation import RemovedInDjango20Warning
|
2014-11-12 09:32:44 +08:00
|
|
|
|
2014-12-07 16:43:10 +08:00
|
|
|
from ..utils import ROOT, setup
|
2014-11-12 09:32:44 +08:00
|
|
|
|
|
|
|
|
2015-01-06 04:43:15 +08:00
|
|
|
@ignore_warnings(category=RemovedInDjango20Warning)
|
2014-12-04 04:36:17 +08:00
|
|
|
class SsiTagTests(SimpleTestCase):
|
2014-11-12 09:32:44 +08:00
|
|
|
|
|
|
|
# Test normal behavior
|
|
|
|
@setup({'ssi01': '{%% ssi "%s" %%}' % os.path.join(
|
2014-12-07 16:43:10 +08:00
|
|
|
ROOT, 'templates', 'ssi_include.html',
|
2014-11-12 09:32:44 +08:00
|
|
|
)})
|
|
|
|
def test_ssi01(self):
|
2014-12-07 16:43:10 +08:00
|
|
|
output = self.engine.render_to_string('ssi01')
|
2014-11-12 09:32:44 +08:00
|
|
|
self.assertEqual(output, 'This is for testing an ssi include. {{ test }}\n')
|
|
|
|
|
|
|
|
@setup({'ssi02': '{%% ssi "%s" %%}' % os.path.join(
|
2014-12-07 16:43:10 +08:00
|
|
|
ROOT, 'not_here',
|
2014-11-12 09:32:44 +08:00
|
|
|
)})
|
|
|
|
def test_ssi02(self):
|
2014-12-07 16:43:10 +08:00
|
|
|
output = self.engine.render_to_string('ssi02')
|
2014-11-12 09:32:44 +08:00
|
|
|
self.assertEqual(output, ''),
|
|
|
|
|
|
|
|
@setup({'ssi03': "{%% ssi '%s' %%}" % os.path.join(
|
2014-12-07 16:43:10 +08:00
|
|
|
ROOT, 'not_here',
|
2014-11-12 09:32:44 +08:00
|
|
|
)})
|
|
|
|
def test_ssi03(self):
|
2014-12-07 16:43:10 +08:00
|
|
|
output = self.engine.render_to_string('ssi03')
|
2014-11-12 09:32:44 +08:00
|
|
|
self.assertEqual(output, ''),
|
|
|
|
|
|
|
|
# Test passing as a variable
|
2015-01-18 02:29:52 +08:00
|
|
|
@setup({'ssi04': '{% ssi ssi_file %}'})
|
2014-11-12 09:32:44 +08:00
|
|
|
def test_ssi04(self):
|
2014-12-22 04:19:05 +08:00
|
|
|
output = self.engine.render_to_string('ssi04', {
|
|
|
|
'ssi_file': os.path.join(ROOT, 'templates', 'ssi_include.html')
|
|
|
|
})
|
2014-11-12 09:32:44 +08:00
|
|
|
self.assertEqual(output, 'This is for testing an ssi include. {{ test }}\n')
|
|
|
|
|
2015-01-18 02:29:52 +08:00
|
|
|
@setup({'ssi05': '{% ssi ssi_file %}'})
|
2014-11-12 09:32:44 +08:00
|
|
|
def test_ssi05(self):
|
2014-12-22 04:19:05 +08:00
|
|
|
output = self.engine.render_to_string('ssi05', {'ssi_file': 'no_file'})
|
2014-11-12 09:32:44 +08:00
|
|
|
self.assertEqual(output, '')
|
|
|
|
|
|
|
|
# Test parsed output
|
|
|
|
@setup({'ssi06': '{%% ssi "%s" parsed %%}' % os.path.join(
|
2014-12-07 16:43:10 +08:00
|
|
|
ROOT, 'templates', 'ssi_include.html',
|
2014-11-12 09:32:44 +08:00
|
|
|
)})
|
|
|
|
def test_ssi06(self):
|
2014-12-07 16:43:10 +08:00
|
|
|
output = self.engine.render_to_string('ssi06', {'test': 'Look ma! It parsed!'})
|
2014-11-12 09:32:44 +08:00
|
|
|
self.assertEqual(output, 'This is for testing an ssi include. '
|
|
|
|
'Look ma! It parsed!\n')
|
|
|
|
|
|
|
|
@setup({'ssi07': '{%% ssi "%s" parsed %%}' % os.path.join(
|
2014-12-07 16:43:10 +08:00
|
|
|
ROOT, 'not_here',
|
2014-11-12 09:32:44 +08:00
|
|
|
)})
|
|
|
|
def test_ssi07(self):
|
2014-12-07 16:43:10 +08:00
|
|
|
output = self.engine.render_to_string('ssi07', {'test': 'Look ma! It parsed!'})
|
2014-11-12 09:32:44 +08:00
|
|
|
self.assertEqual(output, '')
|
|
|
|
|
|
|
|
# Test space in file name
|
|
|
|
@setup({'ssi08': '{%% ssi "%s" %%}' % os.path.join(
|
2014-12-07 16:43:10 +08:00
|
|
|
ROOT, 'templates', 'ssi include with spaces.html',
|
2014-11-12 09:32:44 +08:00
|
|
|
)})
|
|
|
|
def test_ssi08(self):
|
2014-12-07 16:43:10 +08:00
|
|
|
output = self.engine.render_to_string('ssi08')
|
2014-11-12 09:32:44 +08:00
|
|
|
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(
|
2014-12-07 16:43:10 +08:00
|
|
|
ROOT, 'templates', 'ssi include with spaces.html',
|
2014-11-12 09:32:44 +08:00
|
|
|
)})
|
|
|
|
def test_ssi09(self):
|
2014-12-07 16:43:10 +08:00
|
|
|
output = self.engine.render_to_string('ssi09', {'test': 'Look ma! It parsed!'})
|
2014-11-12 09:32:44 +08:00
|
|
|
self.assertEqual(output, 'This is for testing an ssi include '
|
|
|
|
'with spaces in its name. Look ma! It parsed!\n')
|