diff --git a/tests/template_tests/test_custom.py b/tests/template_tests/test_custom.py index 3e817254ee..2b70380825 100644 --- a/tests/template_tests/test_custom.py +++ b/tests/template_tests/test_custom.py @@ -1,10 +1,14 @@ from __future__ import unicode_literals +import os + from django.template import Context, Template, TemplateSyntaxError from django.test import SimpleTestCase, ignore_warnings +from django.test.utils import extend_sys_path from django.utils.deprecation import RemovedInDjango20Warning from .templatetags import custom, inclusion +from .utils import ROOT class CustomFilterTests(SimpleTestCase): @@ -276,3 +280,38 @@ class AssignmentTagTests(TagTestCase): ) with self.assertRaisesMessage(TemplateSyntaxError, msg): Template('{% load custom %}{% assignment_tag_without_context_parameter 123 as var %}') + + +class TemplateTagLoadingTests(SimpleTestCase): + + def setUp(self): + self.egg_dir = os.path.join(ROOT, 'eggs') + + def test_load_error(self): + ttext = "{% load broken_tag %}" + with self.assertRaises(TemplateSyntaxError) as e: + Template(ttext) + + self.assertIn('ImportError', e.exception.args[0]) + self.assertIn('Xtemplate', e.exception.args[0]) + + def test_load_error_egg(self): + ttext = "{% load broken_egg %}" + egg_name = '%s/tagsegg.egg' % self.egg_dir + with extend_sys_path(egg_name): + with self.assertRaises(TemplateSyntaxError): + with self.settings(INSTALLED_APPS=['tagsegg']): + Template(ttext) + try: + with self.settings(INSTALLED_APPS=['tagsegg']): + Template(ttext) + except TemplateSyntaxError as e: + self.assertIn('ImportError', e.args[0]) + self.assertIn('Xtemplate', e.args[0]) + + def test_load_working_egg(self): + ttext = "{% load working_egg %}" + egg_name = '%s/tagsegg.egg' % self.egg_dir + with extend_sys_path(egg_name): + with self.settings(INSTALLED_APPS=['tagsegg']): + Template(ttext) diff --git a/tests/template_tests/tests.py b/tests/template_tests/tests.py index a49efcad4f..62902773d3 100644 --- a/tests/template_tests/tests.py +++ b/tests/template_tests/tests.py @@ -12,8 +12,7 @@ from django.template import ( Context, RequestContext, Template, TemplateSyntaxError, base as template_base, engines, loader, ) -from django.test import RequestFactory, SimpleTestCase -from django.test.utils import extend_sys_path, override_settings +from django.test import RequestFactory, SimpleTestCase, override_settings from django.utils._os import upath TEMPLATES_DIR = os.path.join(os.path.dirname(upath(__file__)), 'templates') @@ -183,42 +182,6 @@ class TemplateRegressionTests(SimpleTestCase): self.assertEqual(child.render({'parent': parent}), 'child') -class TemplateTagLoading(SimpleTestCase): - - def setUp(self): - self.egg_dir = '%s/eggs' % os.path.dirname(upath(__file__)) - - def test_load_error(self): - ttext = "{% load broken_tag %}" - self.assertRaises(template.TemplateSyntaxError, template.Template, ttext) - try: - template.Template(ttext) - except template.TemplateSyntaxError as e: - self.assertIn('ImportError', e.args[0]) - self.assertIn('Xtemplate', e.args[0]) - - def test_load_error_egg(self): - ttext = "{% load broken_egg %}" - egg_name = '%s/tagsegg.egg' % self.egg_dir - with extend_sys_path(egg_name): - with self.assertRaises(template.TemplateSyntaxError): - with self.settings(INSTALLED_APPS=['tagsegg']): - template.Template(ttext) - try: - with self.settings(INSTALLED_APPS=['tagsegg']): - template.Template(ttext) - except template.TemplateSyntaxError as e: - self.assertIn('ImportError', e.args[0]) - self.assertIn('Xtemplate', e.args[0]) - - def test_load_working_egg(self): - ttext = "{% load working_egg %}" - egg_name = '%s/tagsegg.egg' % self.egg_dir - with extend_sys_path(egg_name): - with self.settings(INSTALLED_APPS=['tagsegg']): - template.Template(ttext) - - class RequestContextTests(unittest.TestCase): def setUp(self):