diff --git a/tests/regressiontests/templates/loaders.py b/tests/regressiontests/templates/loaders.py index 64a0dc6505..caa3faa6bc 100644 --- a/tests/regressiontests/templates/loaders.py +++ b/tests/regressiontests/templates/loaders.py @@ -15,9 +15,11 @@ import pkg_resources import imp import StringIO import os.path +import warnings from django.template import TemplateDoesNotExist, Context from django.template.loaders.eggs import load_template_source as lts_egg +from django.template.loaders.eggs import Loader as EggLoader from django.template import loader # Mock classes and objects for pkg_resources functions. @@ -53,7 +55,33 @@ def create_egg(name, resources): egg._resources = resources sys.modules[name] = egg -class EggLoader(unittest.TestCase): +class DeprecatedEggLoaderTest(unittest.TestCase): + "Test the deprecated load_template_source interface to the egg loader" + def setUp(self): + pkg_resources._provider_factories[MockLoader] = MockProvider + + self.empty_egg = create_egg("egg_empty", {}) + self.egg_1 = create_egg("egg_1", { + os.path.normcase('templates/y.html') : StringIO.StringIO("y"), + os.path.normcase('templates/x.txt') : StringIO.StringIO("x"), + }) + self._old_installed_apps = settings.INSTALLED_APPS + settings.INSTALLED_APPS = [] + warnings.simplefilter("ignore", PendingDeprecationWarning) + + def tearDown(self): + settings.INSTALLED_APPS = self._old_installed_apps + warnings.resetwarnings() + + def test_existing(self): + "A template can be loaded from an egg" + settings.INSTALLED_APPS = ['egg_1'] + contents, template_name = lts_egg("y.html") + self.assertEqual(contents, "y") + self.assertEqual(template_name, "egg:egg_1:templates/y.html") + + +class EggLoaderTest(unittest.TestCase): def setUp(self): pkg_resources._provider_factories[MockLoader] = MockProvider @@ -71,24 +99,28 @@ class EggLoader(unittest.TestCase): def test_empty(self): "Loading any template on an empty egg should fail" settings.INSTALLED_APPS = ['egg_empty'] - self.assertRaises(TemplateDoesNotExist, lts_egg, "not-existing.html") + egg_loader = EggLoader() + self.assertRaises(TemplateDoesNotExist, egg_loader.load_template_source, "not-existing.html") def test_non_existing(self): "Template loading fails if the template is not in the egg" settings.INSTALLED_APPS = ['egg_1'] - self.assertRaises(TemplateDoesNotExist, lts_egg, "not-existing.html") + egg_loader = EggLoader() + self.assertRaises(TemplateDoesNotExist, egg_loader.load_template_source, "not-existing.html") def test_existing(self): "A template can be loaded from an egg" settings.INSTALLED_APPS = ['egg_1'] - contents, template_name = lts_egg("y.html") + egg_loader = EggLoader() + contents, template_name = egg_loader.load_template_source("y.html") self.assertEqual(contents, "y") self.assertEqual(template_name, "egg:egg_1:templates/y.html") def test_not_installed(self): "Loading an existent template from an egg not included in INSTALLED_APPS should fail" settings.INSTALLED_APPS = [] - self.assertRaises(TemplateDoesNotExist, lts_egg, "y.html") + egg_loader = EggLoader() + self.assertRaises(TemplateDoesNotExist, egg_loader.load_template_source, "y.html") class CachedLoader(unittest.TestCase): def setUp(self):