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