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_firstof.py | |
| parent | 4a4ad27712b44cebada1bdaebd082cf82df74610 (diff) | |
Fixed #23768 -- Rewrote template tests as unit tests.
Diffstat (limited to 'tests/template_tests/syntax_tests/test_firstof.py')
| -rw-r--r-- | tests/template_tests/syntax_tests/test_firstof.py | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/tests/template_tests/syntax_tests/test_firstof.py b/tests/template_tests/syntax_tests/test_firstof.py new file mode 100644 index 0000000000..23216416ac --- /dev/null +++ b/tests/template_tests/syntax_tests/test_firstof.py @@ -0,0 +1,90 @@ +import warnings + +from django.template.base import TemplateSyntaxError +from django.template.loader import get_template +from django.test import TestCase +from django.utils.deprecation import RemovedInDjango20Warning + +from .utils import render, setup + + +class FirstOfTagTests(TestCase): + + @setup({'firstof01': '{% firstof a b c %}'}) + def test_firstof01(self): + output = render('firstof01', {'a': 0, 'c': 0, 'b': 0}) + self.assertEqual(output, '') + + @setup({'firstof02': '{% firstof a b c %}'}) + def test_firstof02(self): + output = render('firstof02', {'a': 1, 'c': 0, 'b': 0}) + self.assertEqual(output, '1') + + @setup({'firstof03': '{% firstof a b c %}'}) + def test_firstof03(self): + output = render('firstof03', {'a': 0, 'c': 0, 'b': 2}) + self.assertEqual(output, '2') + + @setup({'firstof04': '{% firstof a b c %}'}) + def test_firstof04(self): + output = render('firstof04', {'a': 0, 'c': 3, 'b': 0}) + self.assertEqual(output, '3') + + @setup({'firstof05': '{% firstof a b c %}'}) + def test_firstof05(self): + output = render('firstof05', {'a': 1, 'c': 3, 'b': 2}) + self.assertEqual(output, '1') + + @setup({'firstof06': '{% firstof a b c %}'}) + def test_firstof06(self): + output = render('firstof06', {'c': 3, 'b': 0}) + self.assertEqual(output, '3') + + @setup({'firstof07': '{% firstof a b "c" %}'}) + def test_firstof07(self): + output = render('firstof07', {'a': 0}) + self.assertEqual(output, 'c') + + @setup({'firstof08': '{% firstof a b "c and d" %}'}) + def test_firstof08(self): + output = render('firstof08', {'a': 0, 'b': 0}) + self.assertEqual(output, 'c and d') + + @setup({'firstof09': '{% firstof %}'}) + def test_firstof09(self): + with self.assertRaises(TemplateSyntaxError): + get_template('firstof09') + + @setup({'firstof10': '{% firstof a %}'}) + def test_firstof10(self): + output = render('firstof10', {'a': '<'}) + self.assertEqual(output, '<') + + @setup({'firstof11': '{% load firstof from future %}{% firstof a b %}'}) + def test_firstof11(self): + with warnings.catch_warnings(): + warnings.simplefilter("ignore", RemovedInDjango20Warning) + output = render('firstof11', {'a': '<', 'b': '>'}) + self.assertEqual(output, '<') + + @setup({'firstof12': '{% load firstof from future %}{% firstof a b %}'}) + def test_firstof12(self): + with warnings.catch_warnings(): + warnings.simplefilter("ignore", RemovedInDjango20Warning) + output = render('firstof12', {'a': '', 'b': '>'}) + self.assertEqual(output, '>') + + @setup({'firstof13': '{% load firstof from future %}' + '{% autoescape off %}{% firstof a %}{% endautoescape %}'}) + def test_firstof13(self): + with warnings.catch_warnings(): + warnings.simplefilter("ignore", RemovedInDjango20Warning) + output = render('firstof13', {'a': '<'}) + self.assertEqual(output, '<') + + @setup({'firstof14': '{% load firstof from future %}{% firstof a|safe b %}'}) + def test_firstof14(self): + with warnings.catch_warnings(): + warnings.simplefilter("ignore", RemovedInDjango20Warning) + output = render('firstof14', {'a': '<'}) + self.assertEqual(output, '<') |
