Modified the egg template loader tests; firstly to ensure that we are testing the new, non-deprecated interface; secondly to ensure that the old deprecated interface is also tested, but deprecation warnings are silenced.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13812 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
2d4da641a6
commit
720299053a
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue