# Quick tests for the markup templatetags (django.contrib.markup) import re from django.template import Template, Context, add_to_builtins from django.utils import unittest from django.utils.html import escape add_to_builtins('django.contrib.markup.templatetags.markup') try: import textile except ImportError: textile = None try: import markdown except ImportError: markdown = None try: import docutils except ImportError: docutils = None class Templates(unittest.TestCase): textile_content = """Paragraph 1 Paragraph 2 with "quotes" and @code@""" markdown_content = """Paragraph 1 ## An h2""" rest_content = """Paragraph 1 Paragraph 2 with a link_ .. _link: http://www.example.com/""" @unittest.skipUnless(textile, 'texttile not installed') def test_textile(self): t = Template("{{ textile_content|textile }}") rendered = t.render(Context({'textile_content':self.textile_content})).strip() self.assertEqual(rendered.replace('\t', ''), """
Paragraph 1
Paragraph 2 with “quotes” and code
Paragraph 1\s*
\s*Paragraph 1
Paragraph 2 with a link
""") except AssertionError, e: # Docutils from SVN (which will become 0.5) self.assertEqual(rendered, """Paragraph 1
Paragraph 2 with a link
""") @unittest.skipIf(docutils, 'docutils is installed') def test_no_docutils(self): t = Template("{{ rest_content|restructuredtext }}") rendered = t.render(Context({'rest_content':self.rest_content})).strip() self.assertEqual(rendered, self.rest_content) if __name__ == '__main__': unittest.main()