| 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 |
@override_settings(DEBUG=False) |
| 10 |
@setup({"non_debug": "{% debug %}"}) |
| 11 |
def test_non_debug(self): |
| 12 |
output = self.engine.render_to_string("non_debug", {}) |
| 13 |
self.assertEqual(output, "") |
| 14 |
|
| 15 |
@setup({"modules": "{% debug %}"}) |
| 16 |
def test_modules(self): |
| 17 |
output = self.engine.render_to_string("modules", {}) |
| 18 |
self.assertIn( |
| 19 |
"'django': <module 'django' ", |
| 20 |
output, |
| 21 |
) |
| 22 |
|
| 23 |
@setup({"plain": "{% debug %}"}) |
| 24 |
def test_plain(self): |
| 25 |
output = self.engine.render_to_string("plain", {"a": 1}) |
| 26 |
self.assertTrue( |
| 27 |
output.startswith( |
| 28 |
"{'a': 1}" |
| 29 |
"{'False': False, 'None': None, " |
| 30 |
"'True': True}\n\n{" |
| 31 |
) |
| 32 |
) |
| 33 |
|
| 34 |
@setup({"non_ascii": "{% debug %}"}) |
| 35 |
def test_non_ascii(self): |
| 36 |
group = Group(name="清風") |
| 37 |
output = self.engine.render_to_string("non_ascii", {"group": group}) |
| 38 |
self.assertTrue(output.startswith("{'group': <Group: 清風>}")) |
| 39 |
|
| 40 |
@setup({"script": "{% debug %}"}) |
| 41 |
def test_script(self): |
| 42 |
output = self.engine.render_to_string("script", {"frag": "<script>"}) |
| 43 |
self.assertTrue( |
| 44 |
output.startswith("{'frag': '<script>'}") |
| 45 |
) |