2
0

test_load.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. from django.template.base import TemplateSyntaxError
  2. from django.template.loader import get_template
  3. from django.test import SimpleTestCase
  4. from .utils import render, setup
  5. class LoadTagTests(SimpleTestCase):
  6. @setup({'load01': '{% load testtags subpackage.echo %}{% echo test %} {% echo2 "test" %}'})
  7. def test_load01(self):
  8. output = render('load01')
  9. self.assertEqual(output, 'test test')
  10. @setup({'load02': '{% load subpackage.echo %}{% echo2 "test" %}'})
  11. def test_load02(self):
  12. output = render('load02')
  13. self.assertEqual(output, 'test')
  14. # {% load %} tag, importing individual tags
  15. @setup({'load03': '{% load echo from testtags %}{% echo this that theother %}'})
  16. def test_load03(self):
  17. output = render('load03')
  18. self.assertEqual(output, 'this that theother')
  19. @setup({'load04': '{% load echo other_echo from testtags %}'
  20. '{% echo this that theother %} {% other_echo and another thing %}'})
  21. def test_load04(self):
  22. output = render('load04')
  23. self.assertEqual(output, 'this that theother and another thing')
  24. @setup({'load05': '{% load echo upper from testtags %}'
  25. '{% echo this that theother %} {{ statement|upper }}'})
  26. def test_load05(self):
  27. output = render('load05', {'statement': 'not shouting'})
  28. self.assertEqual(output, 'this that theother NOT SHOUTING')
  29. @setup({'load06': '{% load echo2 from subpackage.echo %}{% echo2 "test" %}'})
  30. def test_load06(self):
  31. output = render('load06')
  32. self.assertEqual(output, 'test')
  33. # {% load %} tag errors
  34. @setup({'load07': '{% load echo other_echo bad_tag from testtags %}'})
  35. def test_load07(self):
  36. with self.assertRaises(TemplateSyntaxError):
  37. get_template('load07')
  38. @setup({'load08': '{% load echo other_echo bad_tag from %}'})
  39. def test_load08(self):
  40. with self.assertRaises(TemplateSyntaxError):
  41. get_template('load08')
  42. @setup({'load09': '{% load from testtags %}'})
  43. def test_load09(self):
  44. with self.assertRaises(TemplateSyntaxError):
  45. get_template('load09')
  46. @setup({'load10': '{% load echo from bad_library %}'})
  47. def test_load10(self):
  48. with self.assertRaises(TemplateSyntaxError):
  49. get_template('load10')
  50. @setup({'load11': '{% load subpackage.echo_invalid %}'})
  51. def test_load11(self):
  52. with self.assertRaises(TemplateSyntaxError):
  53. get_template('load11')
  54. @setup({'load12': '{% load subpackage.missing %}'})
  55. def test_load12(self):
  56. with self.assertRaises(TemplateSyntaxError):
  57. get_template('load12')