Moved TemplateTagLoading cases into test_custom.

This commit is contained in:
Preston Timmons 2015-02-21 13:13:26 -06:00 committed by Aymeric Augustin
parent 06ffc764a9
commit ff67ce5076
2 changed files with 40 additions and 38 deletions

View File

@ -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)

View File

@ -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):