Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.2.X] Modified the egg template loader tests; firstly to ensure tha…

…t we are testing the new, non-deprecated interface; secondly to ensure that the old deprecated interface is also tested, but deprecation warnings are silenced.

Backport of r13812 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@13813 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0c65a6f7daaffb99e8269c4884b341ee1266a102 1 parent 6752258
@freakboy3742 freakboy3742 authored
Showing with 37 additions and 5 deletions.
  1. +37 −5 tests/regressiontests/templates/loaders.py
View
42 tests/regressiontests/templates/loaders.py
@@ -15,9 +15,11 @@
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 @@ def tearDown(self):
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):
Please sign in to comment.
Something went wrong with that request. Please try again.