Loading tests/template_tests/filter_tests/__init__.py 0 → 100644 +0 −0 Empty file added. tests/template_tests/filter_tests/test_add.py 0 → 100644 +46 −0 Original line number Diff line number Diff line from datetime import date, timedelta from django.test import SimpleTestCase from ..utils import render, setup class AddTests(SimpleTestCase): """ Tests for #11687 and #16676 """ @setup({'add01': '{{ i|add:"5" }}'}) def test_add01(self): output = render('add01', {'i': 2000}) self.assertEqual(output, '2005') @setup({'add02': '{{ i|add:"napis" }}'}) def test_add02(self): output = render('add02', {'i': 2000}) self.assertEqual(output, '') @setup({'add03': '{{ i|add:16 }}'}) def test_add03(self): output = render('add03', {'i': 'not_an_int'}) self.assertEqual(output, '') @setup({'add04': '{{ i|add:"16" }}'}) def test_add04(self): output = render('add04', {'i': 'not_an_int'}) self.assertEqual(output, 'not_an_int16') @setup({'add05': '{{ l1|add:l2 }}'}) def test_add05(self): output = render('add05', {'l1': [1, 2], 'l2': [3, 4]}) self.assertEqual(output, '[1, 2, 3, 4]') @setup({'add06': '{{ t1|add:t2 }}'}) def test_add06(self): output = render('add06', {'t1': (3, 4), 't2': (1, 2)}) self.assertEqual(output, '(3, 4, 1, 2)') @setup({'add07': '{{ d|add:t }}'}) def test_add07(self): output = render('add07', {'d': date(2000, 1, 1), 't': timedelta(10)}) self.assertEqual(output, 'Jan. 11, 2000') tests/template_tests/filter_tests/test_addslashes.py 0 → 100644 +17 −0 Original line number Diff line number Diff line from django.test import SimpleTestCase from django.utils.safestring import mark_safe from ..utils import render, setup class AddslashesTests(SimpleTestCase): @setup({'addslashes01': '{% autoescape off %}{{ a|addslashes }} {{ b|addslashes }}{% endautoescape %}'}) def test_addslashes01(self): output = render('addslashes01', {"a": "<a>'", "b": mark_safe("<a>'")}) self.assertEqual(output, r"<a>\' <a>\'") @setup({'addslashes02': '{{ a|addslashes }} {{ b|addslashes }}'}) def test_addslashes02(self): output = render('addslashes02', {"a": "<a>'", "b": mark_safe("<a>'")}) self.assertEqual(output, r"<a>\' <a>\'") tests/template_tests/filter_tests/test_autoescape.py 0 → 100644 +29 −0 Original line number Diff line number Diff line from django.test import SimpleTestCase from ..utils import render, setup, SafeClass, UnsafeClass class AutoescapeStringfilterTests(SimpleTestCase): """ Filters decorated with stringfilter still respect is_safe. """ @setup({'autoescape-stringfilter01': '{{ unsafe|capfirst }}'}) def test_autoescape_stringfilter01(self): output = render('autoescape-stringfilter01', {'unsafe': UnsafeClass()}) self.assertEqual(output, 'You & me') @setup({'autoescape-stringfilter02': '{% autoescape off %}{{ unsafe|capfirst }}{% endautoescape %}'}) def test_autoescape_stringfilter02(self): output = render('autoescape-stringfilter02', {'unsafe': UnsafeClass()}) self.assertEqual(output, 'You & me') @setup({'autoescape-stringfilter03': '{{ safe|capfirst }}'}) def test_autoescape_stringfilter03(self): output = render('autoescape-stringfilter03', {'safe': SafeClass()}) self.assertEqual(output, 'You > me') @setup({'autoescape-stringfilter04': '{% autoescape off %}{{ safe|capfirst }}{% endautoescape %}'}) def test_autoescape_stringfilter04(self): output = render('autoescape-stringfilter04', {'safe': SafeClass()}) self.assertEqual(output, 'You > me') tests/template_tests/filter_tests/test_capfirst.py 0 → 100644 +17 −0 Original line number Diff line number Diff line from django.test import SimpleTestCase from django.utils.safestring import mark_safe from ..utils import render, setup class CapfirstTests(SimpleTestCase): @setup({'capfirst01': '{% autoescape off %}{{ a|capfirst }} {{ b|capfirst }}{% endautoescape %}'}) def test_capfirst01(self): output = render('capfirst01', {'a': 'fred>', 'b': mark_safe('fred>')}) self.assertEqual(output, 'Fred> Fred>') @setup({'capfirst02': '{{ a|capfirst }} {{ b|capfirst }}'}) def test_capfirst02(self): output = render('capfirst02', {'a': 'fred>', 'b': mark_safe('fred>')}) self.assertEqual(output, 'Fred> Fred>') Loading
tests/template_tests/filter_tests/test_add.py 0 → 100644 +46 −0 Original line number Diff line number Diff line from datetime import date, timedelta from django.test import SimpleTestCase from ..utils import render, setup class AddTests(SimpleTestCase): """ Tests for #11687 and #16676 """ @setup({'add01': '{{ i|add:"5" }}'}) def test_add01(self): output = render('add01', {'i': 2000}) self.assertEqual(output, '2005') @setup({'add02': '{{ i|add:"napis" }}'}) def test_add02(self): output = render('add02', {'i': 2000}) self.assertEqual(output, '') @setup({'add03': '{{ i|add:16 }}'}) def test_add03(self): output = render('add03', {'i': 'not_an_int'}) self.assertEqual(output, '') @setup({'add04': '{{ i|add:"16" }}'}) def test_add04(self): output = render('add04', {'i': 'not_an_int'}) self.assertEqual(output, 'not_an_int16') @setup({'add05': '{{ l1|add:l2 }}'}) def test_add05(self): output = render('add05', {'l1': [1, 2], 'l2': [3, 4]}) self.assertEqual(output, '[1, 2, 3, 4]') @setup({'add06': '{{ t1|add:t2 }}'}) def test_add06(self): output = render('add06', {'t1': (3, 4), 't2': (1, 2)}) self.assertEqual(output, '(3, 4, 1, 2)') @setup({'add07': '{{ d|add:t }}'}) def test_add07(self): output = render('add07', {'d': date(2000, 1, 1), 't': timedelta(10)}) self.assertEqual(output, 'Jan. 11, 2000')
tests/template_tests/filter_tests/test_addslashes.py 0 → 100644 +17 −0 Original line number Diff line number Diff line from django.test import SimpleTestCase from django.utils.safestring import mark_safe from ..utils import render, setup class AddslashesTests(SimpleTestCase): @setup({'addslashes01': '{% autoescape off %}{{ a|addslashes }} {{ b|addslashes }}{% endautoescape %}'}) def test_addslashes01(self): output = render('addslashes01', {"a": "<a>'", "b": mark_safe("<a>'")}) self.assertEqual(output, r"<a>\' <a>\'") @setup({'addslashes02': '{{ a|addslashes }} {{ b|addslashes }}'}) def test_addslashes02(self): output = render('addslashes02', {"a": "<a>'", "b": mark_safe("<a>'")}) self.assertEqual(output, r"<a>\' <a>\'")
tests/template_tests/filter_tests/test_autoescape.py 0 → 100644 +29 −0 Original line number Diff line number Diff line from django.test import SimpleTestCase from ..utils import render, setup, SafeClass, UnsafeClass class AutoescapeStringfilterTests(SimpleTestCase): """ Filters decorated with stringfilter still respect is_safe. """ @setup({'autoescape-stringfilter01': '{{ unsafe|capfirst }}'}) def test_autoescape_stringfilter01(self): output = render('autoescape-stringfilter01', {'unsafe': UnsafeClass()}) self.assertEqual(output, 'You & me') @setup({'autoescape-stringfilter02': '{% autoescape off %}{{ unsafe|capfirst }}{% endautoescape %}'}) def test_autoescape_stringfilter02(self): output = render('autoescape-stringfilter02', {'unsafe': UnsafeClass()}) self.assertEqual(output, 'You & me') @setup({'autoescape-stringfilter03': '{{ safe|capfirst }}'}) def test_autoescape_stringfilter03(self): output = render('autoescape-stringfilter03', {'safe': SafeClass()}) self.assertEqual(output, 'You > me') @setup({'autoescape-stringfilter04': '{% autoescape off %}{{ safe|capfirst }}{% endautoescape %}'}) def test_autoescape_stringfilter04(self): output = render('autoescape-stringfilter04', {'safe': SafeClass()}) self.assertEqual(output, 'You > me')
tests/template_tests/filter_tests/test_capfirst.py 0 → 100644 +17 −0 Original line number Diff line number Diff line from django.test import SimpleTestCase from django.utils.safestring import mark_safe from ..utils import render, setup class CapfirstTests(SimpleTestCase): @setup({'capfirst01': '{% autoescape off %}{{ a|capfirst }} {{ b|capfirst }}{% endautoescape %}'}) def test_capfirst01(self): output = render('capfirst01', {'a': 'fred>', 'b': mark_safe('fred>')}) self.assertEqual(output, 'Fred> Fred>') @setup({'capfirst02': '{{ a|capfirst }} {{ b|capfirst }}'}) def test_capfirst02(self): output = render('capfirst02', {'a': 'fred>', 'b': mark_safe('fred>')}) self.assertEqual(output, 'Fred> Fred>')