[1.7.x] Avoided using private API get_template_from_string.
Conflicts:
django/contrib/webdesign/tests.py
Backport of c0c1bb9e
from master.
This commit is contained in:
parent
31d1ccca3f
commit
12bace46c1
|
@ -4,7 +4,7 @@ from __future__ import unicode_literals
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from django.contrib.webdesign.lorem_ipsum import paragraphs, words
|
from django.contrib.webdesign.lorem_ipsum import paragraphs, words
|
||||||
from django.template import loader, Context
|
from django.template import Context, Template
|
||||||
|
|
||||||
|
|
||||||
class WebdesignTest(unittest.TestCase):
|
class WebdesignTest(unittest.TestCase):
|
||||||
|
@ -17,6 +17,6 @@ class WebdesignTest(unittest.TestCase):
|
||||||
['Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'])
|
['Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'])
|
||||||
|
|
||||||
def test_lorem_tag(self):
|
def test_lorem_tag(self):
|
||||||
t = loader.get_template_from_string("{% load webdesign %}{% lorem 3 w %}")
|
t = Template("{% load webdesign %}{% lorem 3 w %}")
|
||||||
self.assertEqual(t.render(Context({})),
|
self.assertEqual(t.render(Context({})),
|
||||||
'lorem ipsum dolor')
|
'lorem ipsum dolor')
|
||||||
|
|
|
@ -9,7 +9,7 @@ import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from django.template import loader, Context
|
from django.template import Context, Template
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.cache.backends.base import BaseCache
|
from django.core.cache.backends.base import BaseCache
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
|
@ -89,7 +89,7 @@ class BaseStaticFilesTestCase(object):
|
||||||
|
|
||||||
def render_template(self, template, **kwargs):
|
def render_template(self, template, **kwargs):
|
||||||
if isinstance(template, six.string_types):
|
if isinstance(template, six.string_types):
|
||||||
template = loader.get_template_from_string(template)
|
template = Template(template)
|
||||||
return template.render(Context(kwargs)).strip()
|
return template.render(Context(kwargs)).strip()
|
||||||
|
|
||||||
def static_template_snippet(self, path, asvar=False):
|
def static_template_snippet(self, path, asvar=False):
|
||||||
|
|
|
@ -1,33 +1,28 @@
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from django.template import VariableNode, Context
|
from django.template import Context, Template, VariableNode
|
||||||
from django.template.loader import get_template_from_string
|
|
||||||
from django.test import override_settings
|
from django.test import override_settings
|
||||||
|
|
||||||
|
|
||||||
class NodelistTest(TestCase):
|
class NodelistTest(TestCase):
|
||||||
|
|
||||||
def test_for(self):
|
def test_for(self):
|
||||||
source = '{% for i in 1 %}{{ a }}{% endfor %}'
|
template = Template('{% for i in 1 %}{{ a }}{% endfor %}')
|
||||||
template = get_template_from_string(source)
|
|
||||||
vars = template.nodelist.get_nodes_by_type(VariableNode)
|
vars = template.nodelist.get_nodes_by_type(VariableNode)
|
||||||
self.assertEqual(len(vars), 1)
|
self.assertEqual(len(vars), 1)
|
||||||
|
|
||||||
def test_if(self):
|
def test_if(self):
|
||||||
source = '{% if x %}{{ a }}{% endif %}'
|
template = Template('{% if x %}{{ a }}{% endif %}')
|
||||||
template = get_template_from_string(source)
|
|
||||||
vars = template.nodelist.get_nodes_by_type(VariableNode)
|
vars = template.nodelist.get_nodes_by_type(VariableNode)
|
||||||
self.assertEqual(len(vars), 1)
|
self.assertEqual(len(vars), 1)
|
||||||
|
|
||||||
def test_ifequal(self):
|
def test_ifequal(self):
|
||||||
source = '{% ifequal x y %}{{ a }}{% endifequal %}'
|
template = Template('{% ifequal x y %}{{ a }}{% endifequal %}')
|
||||||
template = get_template_from_string(source)
|
|
||||||
vars = template.nodelist.get_nodes_by_type(VariableNode)
|
vars = template.nodelist.get_nodes_by_type(VariableNode)
|
||||||
self.assertEqual(len(vars), 1)
|
self.assertEqual(len(vars), 1)
|
||||||
|
|
||||||
def test_ifchanged(self):
|
def test_ifchanged(self):
|
||||||
source = '{% ifchanged x %}{{ a }}{% endifchanged %}'
|
template = Template('{% ifchanged x %}{{ a }}{% endifchanged %}')
|
||||||
template = get_template_from_string(source)
|
|
||||||
vars = template.nodelist.get_nodes_by_type(VariableNode)
|
vars = template.nodelist.get_nodes_by_type(VariableNode)
|
||||||
self.assertEqual(len(vars), 1)
|
self.assertEqual(len(vars), 1)
|
||||||
|
|
||||||
|
@ -51,7 +46,7 @@ class ErrorIndexTest(TestCase):
|
||||||
'five': 5,
|
'five': 5,
|
||||||
})
|
})
|
||||||
for source, expected_error_source_index in tests:
|
for source, expected_error_source_index in tests:
|
||||||
template = get_template_from_string(source)
|
template = Template(source)
|
||||||
try:
|
try:
|
||||||
template.render(context)
|
template.render(context)
|
||||||
except (RuntimeError, TypeError) as e:
|
except (RuntimeError, TypeError) as e:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from django.template import loader, Context
|
from django.template import Context, Template
|
||||||
|
|
||||||
from .models import Person
|
from .models import Person
|
||||||
|
|
||||||
|
@ -11,5 +11,5 @@ def get_person(request, pk):
|
||||||
|
|
||||||
|
|
||||||
def no_template_used(request):
|
def no_template_used(request):
|
||||||
template = loader.get_template_from_string("This is a string-based template")
|
template = Template("This is a string-based template")
|
||||||
return HttpResponse(template.render(Context({})))
|
return HttpResponse(template.render(Context({})))
|
||||||
|
|
Loading…
Reference in New Issue