mirror of https://github.com/django/django.git
Fixed #17086 -- Removed pollution of global template-builtins from markup and humanize tests.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17031 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
d89be53d95
commit
6df91d9539
|
@ -1,14 +1,12 @@
|
|||
from __future__ import with_statement
|
||||
from datetime import timedelta, date, datetime
|
||||
|
||||
from django.template import Template, Context, add_to_builtins, defaultfilters
|
||||
from django.template import Template, Context, defaultfilters
|
||||
from django.test import TestCase
|
||||
from django.utils import translation, tzinfo
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.utils.html import escape
|
||||
|
||||
add_to_builtins('django.contrib.humanize.templatetags.humanize')
|
||||
|
||||
|
||||
class HumanizeTests(TestCase):
|
||||
|
||||
|
@ -16,7 +14,7 @@ class HumanizeTests(TestCase):
|
|||
# Using max below ensures we go through both lists
|
||||
# However, if the lists are not equal length, this raises an exception
|
||||
for test_content, result in zip(test_list, result_list):
|
||||
t = Template('{{ test_content|%s }}' % method)
|
||||
t = Template('{%% load humanize %%}{{ test_content|%s }}' % method)
|
||||
rendered = t.render(Context(locals())).strip()
|
||||
self.assertEqual(rendered, escape(result),
|
||||
msg="%s test failed, produced '%s', should've produced '%s'" % (method, rendered, result))
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
# Quick tests for the markup templatetags (django.contrib.markup)
|
||||
import re
|
||||
|
||||
from django.template import Template, Context, add_to_builtins
|
||||
from django.template import Template, Context
|
||||
from django.utils import unittest
|
||||
from django.utils.html import escape
|
||||
|
||||
add_to_builtins('django.contrib.markup.templatetags.markup')
|
||||
|
||||
try:
|
||||
import textile
|
||||
except ImportError:
|
||||
|
@ -41,7 +39,7 @@ Paragraph 2 with a link_
|
|||
|
||||
@unittest.skipUnless(textile, 'texttile not installed')
|
||||
def test_textile(self):
|
||||
t = Template("{{ textile_content|textile }}")
|
||||
t = Template("{% load markup %}{{ textile_content|textile }}")
|
||||
rendered = t.render(Context({'textile_content':self.textile_content})).strip()
|
||||
self.assertEqual(rendered.replace('\t', ''), """<p>Paragraph 1</p>
|
||||
|
||||
|
@ -49,26 +47,26 @@ Paragraph 2 with a link_
|
|||
|
||||
@unittest.skipIf(textile, 'texttile is installed')
|
||||
def test_no_textile(self):
|
||||
t = Template("{{ textile_content|textile }}")
|
||||
t = Template("{% load markup %}{{ textile_content|textile }}")
|
||||
rendered = t.render(Context({'textile_content':self.textile_content})).strip()
|
||||
self.assertEqual(rendered, escape(self.textile_content))
|
||||
|
||||
@unittest.skipUnless(markdown, 'markdown not installed')
|
||||
def test_markdown(self):
|
||||
t = Template("{{ markdown_content|markdown }}")
|
||||
t = Template("{% load markup %}{{ markdown_content|markdown }}")
|
||||
rendered = t.render(Context({'markdown_content':self.markdown_content})).strip()
|
||||
pattern = re.compile("""<p>Paragraph 1\s*</p>\s*<h2>\s*An h2</h2>""")
|
||||
self.assertTrue(pattern.match(rendered))
|
||||
|
||||
@unittest.skipIf(markdown, 'markdown is installed')
|
||||
def test_no_markdown(self):
|
||||
t = Template("{{ markdown_content|markdown }}")
|
||||
t = Template("{% load markup %}{{ markdown_content|markdown }}")
|
||||
rendered = t.render(Context({'markdown_content':self.markdown_content})).strip()
|
||||
self.assertEqual(rendered, self.markdown_content)
|
||||
|
||||
@unittest.skipUnless(docutils, 'docutils not installed')
|
||||
def test_docutils(self):
|
||||
t = Template("{{ rest_content|restructuredtext }}")
|
||||
t = Template("{% load markup %}{{ rest_content|restructuredtext }}")
|
||||
rendered = t.render(Context({'rest_content':self.rest_content})).strip()
|
||||
# Different versions of docutils return slightly different HTML
|
||||
try:
|
||||
|
@ -82,7 +80,7 @@ Paragraph 2 with a link_
|
|||
|
||||
@unittest.skipIf(docutils, 'docutils is installed')
|
||||
def test_no_docutils(self):
|
||||
t = Template("{{ rest_content|restructuredtext }}")
|
||||
t = Template("{% load markup %}{{ rest_content|restructuredtext }}")
|
||||
rendered = t.render(Context({'rest_content':self.rest_content})).strip()
|
||||
self.assertEqual(rendered, self.rest_content)
|
||||
|
||||
|
|
Loading…
Reference in New Issue