from django.template.defaultfilters import unordered_list from django.test import SimpleTestCase from django.utils.encoding import python_2_unicode_compatible from django.utils.safestring import mark_safe from ..utils import setup class UnorderedListTests(SimpleTestCase): @setup({'unordered_list01': '{{ a|unordered_list }}'}) def test_unordered_list01(self): output = self.engine.render_to_string('unordered_list01', {'a': ['x>', ['x>\n\t\n\t') @setup({'unordered_list02': '{% autoescape off %}{{ a|unordered_list }}{% endautoescape %}'}) def test_unordered_list02(self): output = self.engine.render_to_string('unordered_list02', {'a': ['x>', ['x>\n\t\n\t') @setup({'unordered_list03': '{{ a|unordered_list }}'}) def test_unordered_list03(self): output = self.engine.render_to_string('unordered_list03', {'a': ['x>', [mark_safe('x>\n\t
    \n\t\t
  • \n\t
\n\t') @setup({'unordered_list04': '{% autoescape off %}{{ a|unordered_list }}{% endautoescape %}'}) def test_unordered_list04(self): output = self.engine.render_to_string('unordered_list04', {'a': ['x>', [mark_safe('x>\n\t
    \n\t\t
  • \n\t
\n\t') @setup({'unordered_list05': '{% autoescape off %}{{ a|unordered_list }}{% endautoescape %}'}) def test_unordered_list05(self): output = self.engine.render_to_string('unordered_list05', {'a': ['x>', ['x>\n\t
    \n\t\t
  • \n\t
\n\t') class FunctionTests(SimpleTestCase): def test_list(self): self.assertEqual(unordered_list(['item 1', 'item 2']), '\t
  • item 1
  • \n\t
  • item 2
  • ') def test_nested(self): self.assertEqual( unordered_list(['item 1', ['item 1.1']]), '\t
  • item 1\n\t
      \n\t\t
    • item 1.1
    • \n\t
    \n\t
  • ', ) def test_nested2(self): self.assertEqual( unordered_list(['item 1', ['item 1.1', 'item1.2'], 'item 2']), '\t
  • item 1\n\t
      \n\t\t
    • item 1.1
    • \n\t\t
    • item1.2' '
    • \n\t
    \n\t
  • \n\t
  • item 2
  • ', ) def test_nested3(self): self.assertEqual( unordered_list(['item 1', 'item 2', ['item 2.1']]), '\t
  • item 1
  • \n\t
  • item 2\n\t
      \n\t\t
    • item 2.1' '
    • \n\t
    \n\t
  • ', ) def test_nested_multiple(self): self.assertEqual( unordered_list(['item 1', ['item 1.1', ['item 1.1.1', ['item 1.1.1.1']]]]), '\t
  • item 1\n\t
      \n\t\t
    • item 1.1\n\t\t
        \n\t\t\t
      • ' 'item 1.1.1\n\t\t\t
          \n\t\t\t\t
        • item 1.1.1.1
        • \n\t\t\t' '
        \n\t\t\t
      • \n\t\t
      \n\t\t
    • \n\t
    \n\t
  • ', ) def test_nested_multiple2(self): self.assertEqual( unordered_list(['States', ['Kansas', ['Lawrence', 'Topeka'], 'Illinois']]), '\t
  • States\n\t
      \n\t\t
    • Kansas\n\t\t
        \n\t\t\t
      • ' 'Lawrence
      • \n\t\t\t
      • Topeka
      • \n\t\t
      \n\t\t
    • ' '\n\t\t
    • Illinois
    • \n\t
    \n\t
  • ', ) def test_autoescape(self): self.assertEqual( unordered_list(['item 1', 'item 2']), '\t
  • <a>item 1</a>
  • \n\t
  • item 2
  • ', ) def test_autoescape_off(self): self.assertEqual( unordered_list(['item 1', 'item 2'], autoescape=False), '\t
  • item 1
  • \n\t
  • item 2
  • ', ) def test_ulitem(self): @python_2_unicode_compatible class ULItem(object): def __init__(self, title): self.title = title def __str__(self): return 'ulitem-%s' % str(self.title) a = ULItem('a') b = ULItem('b') c = ULItem('c') self.assertEqual( unordered_list([a, b, c]), '\t
  • ulitem-a
  • \n\t
  • ulitem-b
  • \n\t
  • ulitem-<a>c</a>
  • ', ) def item_generator(): yield a yield b yield c self.assertEqual( unordered_list(item_generator()), '\t
  • ulitem-a
  • \n\t
  • ulitem-b
  • \n\t
  • ulitem-<a>c</a>
  • ', ) def test_ulitem_autoescape_off(self): @python_2_unicode_compatible class ULItem(object): def __init__(self, title): self.title = title def __str__(self): return 'ulitem-%s' % str(self.title) a = ULItem('a') b = ULItem('b') c = ULItem('c') self.assertEqual( unordered_list([a, b, c], autoescape=False), '\t
  • ulitem-a
  • \n\t
  • ulitem-b
  • \n\t
  • ulitem-c
  • ', ) def item_generator(): yield a yield b yield c self.assertEqual( unordered_list(item_generator(), autoescape=False), '\t
  • ulitem-a
  • \n\t
  • ulitem-b
  • \n\t
  • ulitem-c
  • ', )