|
| 1 | +from django.contrib.auth.models import Group |
| 2 | +from django.test import SimpleTestCase, override_settings |
| 3 | + |
| 4 | +from ..utils import setup |
| 5 | + |
| 6 | + |
| 7 | +@override_settings(DEBUG=True) |
| 8 | +class DebugTests(SimpleTestCase): |
| 9 | + |
| 10 | + @override_settings(DEBUG=False) |
| 11 | + @setup({'non_debug': '{% debug %}'}) |
| 12 | + def test_non_debug(self): |
| 13 | + output = self.engine.render_to_string('non_debug', {}) |
| 14 | + self.assertEqual(output, '') |
| 15 | + |
| 16 | + @setup({'modules': '{% debug %}'}) |
| 17 | + def test_modules(self): |
| 18 | + output = self.engine.render_to_string('modules', {}) |
| 19 | + self.assertIn( |
| 20 | + ''django': <module 'django' ', |
| 21 | + output, |
| 22 | + ) |
| 23 | + |
| 24 | + @setup({'plain': '{% debug %}'}) |
| 25 | + def test_plain(self): |
| 26 | + output = self.engine.render_to_string('plain', {'a': 1}) |
| 27 | + self.assertTrue(output.startswith( |
| 28 | + '{'a': 1}' |
| 29 | + '{'False': False, 'None': None, ' |
| 30 | + ''True': True}\n\n{' |
| 31 | + )) |
| 32 | + |
| 33 | + @setup({'non_ascii': '{% debug %}'}) |
| 34 | + def test_non_ascii(self): |
| 35 | + group = Group(name="清風") |
| 36 | + output = self.engine.render_to_string('non_ascii', {'group': group}) |
| 37 | + self.assertTrue(output.startswith( |
| 38 | + '{'group': <Group: 清風>}' |
| 39 | + )) |
| 40 | + |
| 41 | + @setup({'script': '{% debug %}'}) |
| 42 | + def test_script(self): |
| 43 | + output = self.engine.render_to_string('script', {'frag': '<script>'}) |
| 44 | + self.assertTrue(output.startswith( |
| 45 | + '{'frag': '<script>'}' |
| 46 | + )) |
0 commit comments