From c0c1bb9e64d7e1cea50dc4818ffcf229b568578b Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Fri, 31 Oct 2014 11:38:53 +0100 Subject: [PATCH] Avoided using private API get_template_from_string. --- django/contrib/webdesign/tests.py | 4 ++-- tests/staticfiles_tests/tests.py | 4 ++-- tests/template_tests/test_nodelist.py | 17 ++++++----------- tests/test_utils/views.py | 4 ++-- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/django/contrib/webdesign/tests.py b/django/contrib/webdesign/tests.py index 239af194b7..fea378807f 100644 --- a/django/contrib/webdesign/tests.py +++ b/django/contrib/webdesign/tests.py @@ -3,12 +3,12 @@ from __future__ import unicode_literals import unittest -from django.template import loader, Context +from django.template import Context, Template class WebdesignTest(unittest.TestCase): 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({})), 'lorem ipsum dolor') diff --git a/tests/staticfiles_tests/tests.py b/tests/staticfiles_tests/tests.py index 67afd25351..5dc630f004 100644 --- a/tests/staticfiles_tests/tests.py +++ b/tests/staticfiles_tests/tests.py @@ -8,7 +8,7 @@ import shutil import sys import unittest -from django.template import loader, Context +from django.template import Context, Template from django.conf import settings from django.core.cache.backends.base import BaseCache from django.core.exceptions import ImproperlyConfigured @@ -97,7 +97,7 @@ class BaseStaticFilesTestCase(object): def render_template(self, template, **kwargs): if isinstance(template, six.string_types): - template = loader.get_template_from_string(template) + template = Template(template) return template.render(Context(kwargs)).strip() def static_template_snippet(self, path, asvar=False): diff --git a/tests/template_tests/test_nodelist.py b/tests/template_tests/test_nodelist.py index 1c48d3f7ce..bce75aeecb 100644 --- a/tests/template_tests/test_nodelist.py +++ b/tests/template_tests/test_nodelist.py @@ -1,33 +1,28 @@ from unittest import TestCase -from django.template import VariableNode, Context -from django.template.loader import get_template_from_string +from django.template import Context, Template, VariableNode from django.test import override_settings class NodelistTest(TestCase): def test_for(self): - source = '{% for i in 1 %}{{ a }}{% endfor %}' - template = get_template_from_string(source) + template = Template('{% for i in 1 %}{{ a }}{% endfor %}') vars = template.nodelist.get_nodes_by_type(VariableNode) self.assertEqual(len(vars), 1) def test_if(self): - source = '{% if x %}{{ a }}{% endif %}' - template = get_template_from_string(source) + template = Template('{% if x %}{{ a }}{% endif %}') vars = template.nodelist.get_nodes_by_type(VariableNode) self.assertEqual(len(vars), 1) def test_ifequal(self): - source = '{% ifequal x y %}{{ a }}{% endifequal %}' - template = get_template_from_string(source) + template = Template('{% ifequal x y %}{{ a }}{% endifequal %}') vars = template.nodelist.get_nodes_by_type(VariableNode) self.assertEqual(len(vars), 1) def test_ifchanged(self): - source = '{% ifchanged x %}{{ a }}{% endifchanged %}' - template = get_template_from_string(source) + template = Template('{% ifchanged x %}{{ a }}{% endifchanged %}') vars = template.nodelist.get_nodes_by_type(VariableNode) self.assertEqual(len(vars), 1) @@ -51,7 +46,7 @@ class ErrorIndexTest(TestCase): 'five': 5, }) for source, expected_error_source_index in tests: - template = get_template_from_string(source) + template = Template(source) try: template.render(context) except (RuntimeError, TypeError) as e: diff --git a/tests/test_utils/views.py b/tests/test_utils/views.py index 48fddba283..6c30d07199 100644 --- a/tests/test_utils/views.py +++ b/tests/test_utils/views.py @@ -1,6 +1,6 @@ from django.http import HttpResponse from django.shortcuts import get_object_or_404 -from django.template import loader, Context +from django.template import Context, Template from .models import Person @@ -11,7 +11,7 @@ def get_person(request, pk): 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({})))