Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[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
Russell Keith-Magee authored
42  tests/regressiontests/templates/loaders.py
@@ -15,9 +15,11 @@
15 15
 import imp
16 16
 import StringIO
17 17
 import os.path
  18
+import warnings
18 19
 
19 20
 from django.template import TemplateDoesNotExist, Context
20 21
 from django.template.loaders.eggs import load_template_source as lts_egg
  22
+from django.template.loaders.eggs import Loader as EggLoader
21 23
 from django.template import loader
22 24
 
23 25
 # Mock classes and objects for pkg_resources functions.
@@ -53,7 +55,33 @@ def create_egg(name, resources):
53 55
     egg._resources = resources
54 56
     sys.modules[name] = egg
55 57
 
56  
-class EggLoader(unittest.TestCase):
  58
+class DeprecatedEggLoaderTest(unittest.TestCase):
  59
+    "Test the deprecated load_template_source interface to the egg loader"
  60
+    def setUp(self):
  61
+        pkg_resources._provider_factories[MockLoader] = MockProvider
  62
+
  63
+        self.empty_egg = create_egg("egg_empty", {})
  64
+        self.egg_1 = create_egg("egg_1", {
  65
+            os.path.normcase('templates/y.html') : StringIO.StringIO("y"),
  66
+            os.path.normcase('templates/x.txt') : StringIO.StringIO("x"),
  67
+        })
  68
+        self._old_installed_apps = settings.INSTALLED_APPS
  69
+        settings.INSTALLED_APPS = []
  70
+        warnings.simplefilter("ignore", PendingDeprecationWarning)
  71
+
  72
+    def tearDown(self):
  73
+        settings.INSTALLED_APPS = self._old_installed_apps
  74
+        warnings.resetwarnings()
  75
+
  76
+    def test_existing(self):
  77
+        "A template can be loaded from an egg"
  78
+        settings.INSTALLED_APPS = ['egg_1']
  79
+        contents, template_name = lts_egg("y.html")
  80
+        self.assertEqual(contents, "y")
  81
+        self.assertEqual(template_name, "egg:egg_1:templates/y.html")
  82
+
  83
+
  84
+class EggLoaderTest(unittest.TestCase):
57 85
     def setUp(self):
58 86
         pkg_resources._provider_factories[MockLoader] = MockProvider
59 87
 
@@ -71,24 +99,28 @@ def tearDown(self):
71 99
     def test_empty(self):
72 100
         "Loading any template on an empty egg should fail"
73 101
         settings.INSTALLED_APPS = ['egg_empty']
74  
-        self.assertRaises(TemplateDoesNotExist, lts_egg, "not-existing.html")
  102
+        egg_loader = EggLoader()
  103
+        self.assertRaises(TemplateDoesNotExist, egg_loader.load_template_source, "not-existing.html")
75 104
 
76 105
     def test_non_existing(self):
77 106
         "Template loading fails if the template is not in the egg"
78 107
         settings.INSTALLED_APPS = ['egg_1']
79  
-        self.assertRaises(TemplateDoesNotExist, lts_egg, "not-existing.html")
  108
+        egg_loader = EggLoader()
  109
+        self.assertRaises(TemplateDoesNotExist, egg_loader.load_template_source, "not-existing.html")
80 110
 
81 111
     def test_existing(self):
82 112
         "A template can be loaded from an egg"
83 113
         settings.INSTALLED_APPS = ['egg_1']
84  
-        contents, template_name = lts_egg("y.html")
  114
+        egg_loader = EggLoader()
  115
+        contents, template_name = egg_loader.load_template_source("y.html")
85 116
         self.assertEqual(contents, "y")
86 117
         self.assertEqual(template_name, "egg:egg_1:templates/y.html")
87 118
 
88 119
     def test_not_installed(self):
89 120
         "Loading an existent template from an egg not included in INSTALLED_APPS should fail"
90 121
         settings.INSTALLED_APPS = []
91  
-        self.assertRaises(TemplateDoesNotExist, lts_egg, "y.html")
  122
+        egg_loader = EggLoader()
  123
+        self.assertRaises(TemplateDoesNotExist, egg_loader.load_template_source, "y.html")
92 124
 
93 125
 class CachedLoader(unittest.TestCase):
94 126
     def setUp(self):

0 notes on commit 0c65a6f

Please sign in to comment.
Something went wrong with that request. Please try again.