diff options
| author | Preston Timmons <prestontimmons@gmail.com> | 2014-11-11 19:32:44 -0600 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-12-02 19:18:35 -0500 |
| commit | b872134bfc14f6322bd1e4b0a08bf5bfd2c43a52 (patch) | |
| tree | f82fc6be418adeb1e7ff36728f82008770066999 /tests/template_tests/syntax_tests/test_ssi.py | |
| parent | 4a4ad27712b44cebada1bdaebd082cf82df74610 (diff) | |
Fixed #23768 -- Rewrote template tests as unit tests.
Diffstat (limited to 'tests/template_tests/syntax_tests/test_ssi.py')
| -rw-r--r-- | tests/template_tests/syntax_tests/test_ssi.py | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/tests/template_tests/syntax_tests/test_ssi.py b/tests/template_tests/syntax_tests/test_ssi.py new file mode 100644 index 0000000000..33db059c92 --- /dev/null +++ b/tests/template_tests/syntax_tests/test_ssi.py @@ -0,0 +1,88 @@ +import os +import warnings + +from django.test import override_settings, TestCase +from django.utils._os import upath +from django.utils.deprecation import RemovedInDjango19Warning + +from .utils import render, 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(TestCase): + + # Test normal behavior + @setup({'ssi01': '{%% ssi "%s" %%}' % os.path.join( + root, 'templates', 'ssi_include.html', + )}) + def test_ssi01(self): + output = render('ssi01') + self.assertEqual(output, 'This is for testing an ssi include. {{ test }}\n') + + @setup({'ssi02': '{%% ssi "%s" %%}' % os.path.join( + root, 'not_here', + )}) + def test_ssi02(self): + output = render('ssi02') + self.assertEqual(output, ''), + + @setup({'ssi03': "{%% ssi '%s' %%}" % os.path.join( + root, 'not_here', + )}) + def test_ssi03(self): + output = render('ssi03') + self.assertEqual(output, ''), + + # Test passing as a variable + @setup({'ssi04': '{% load ssi from future %}{% ssi ssi_file %}'}) + 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') + }) + self.assertEqual(output, 'This is for testing an ssi include. {{ test }}\n') + + @setup({'ssi05': '{% load ssi from future %}{% ssi ssi_file %}'}) + def test_ssi05(self): + with warnings.catch_warnings(): + warnings.simplefilter("ignore", RemovedInDjango19Warning) + output = render('ssi05', {'ssi_file': 'no_file'}) + self.assertEqual(output, '') + + # Test parsed output + @setup({'ssi06': '{%% ssi "%s" parsed %%}' % os.path.join( + root, 'templates', 'ssi_include.html', + )}) + def test_ssi06(self): + output = render('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', + )}) + def test_ssi07(self): + output = render('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', + )}) + def test_ssi08(self): + output = render('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', + )}) + def test_ssi09(self): + output = render('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') |
