| 165 | try: |
| 166 | loader.template_source_loaders = (filesystem.Loader(),) |
| 167 | |
| 168 | # We rely on the fact that runtests.py sets up TEMPLATE_DIRS to |
| 169 | # point to a directory containing a 404.html file. Also that |
| 170 | # the file system and app directories loaders both inherit the |
| 171 | # load_template method from the BaseLoader class, so we only need |
| 172 | # to test one of them. |
| 173 | load_name = '404.html' |
| 174 | template = loader.get_template(load_name) |
| 175 | template_name = template.nodelist[0].source[0].name |
| 176 | self.assertTrue(template_name.endswith(load_name), |
| 177 | 'Template loaded by filesystem loader has incorrect name for debug page: %s' % template_name) |
| 178 | |
| 179 | # Aso test the cached loader, since it overrides load_template |
| 180 | cache_loader = cached.Loader(('',)) |
| 181 | cache_loader._cached_loaders = loader.template_source_loaders |
| 182 | loader.template_source_loaders = (cache_loader,) |
| 183 | |
| 184 | template = loader.get_template(load_name) |
| 185 | template_name = template.nodelist[0].source[0].name |
| 186 | self.assertTrue(template_name.endswith(load_name), |
| 187 | 'Template loaded through cached loader has incorrect name for debug page: %s' % template_name) |
| 188 | |
| 189 | template = loader.get_template(load_name) |
| 190 | template_name = template.nodelist[0].source[0].name |
| 191 | self.assertTrue(template_name.endswith(load_name), |
| 192 | 'Cached template loaded through cached loader has incorrect name for debug page: %s' % template_name) |
| 193 | finally: |
| 194 | loader.template_source_loaders = old_loaders |
| 195 | settings.TEMPLATE_DEBUG = old_td |
| 196 | |
| 197 | def test_does_not_exist_name_app(self): |
| 198 | old_td, settings.TEMPLATE_DEBUG = settings.TEMPLATE_DEBUG, True |
167 | | # We rely on the fact that runtests.py sets up TEMPLATE_DIRS to |
168 | | # point to a directory containing a 404.html file. Also that |
169 | | # the file system and app directories loaders both inherit the |
170 | | # load_template method from the BaseLoader class, so we only need |
171 | | # to test one of them. |
172 | | load_name = '404.html' |
173 | | template = loader.get_template(load_name) |
174 | | template_name = template.nodelist[0].source[0].name |
175 | | self.assertTrue(template_name.endswith(load_name), |
176 | | 'Template loaded by filesystem loader has incorrect name for debug page: %s' % template_name) |
| 201 | try: |
| 202 | loader.template_source_loaders = (app_directories.Loader(),) |
178 | | # Aso test the cached loader, since it overrides load_template |
179 | | cache_loader = cached.Loader(('',)) |
180 | | cache_loader._cached_loaders = loader.template_source_loaders |
181 | | loader.template_source_loaders = (cache_loader,) |
| 204 | load_name = 'test_extends_error.html' |
| 205 | tmpl = loader.get_template(load_name) |
| 206 | r = None |
| 207 | try: |
| 208 | r = tmpl.render(template.Context({})) |
| 209 | except template.TemplateSyntaxError, e: |
| 210 | settings.TEMPLATE_DEBUG = old_td |
| 211 | self.assertEqual(e.args[0], 'Caught TemplateDoesNotExist while rendering: missing.html') |
| 212 | self.assertEqual(r, None, 'Template rendering unexpectedly succeeded, produced: ->%r<-' % r) |
| 213 | finally: |
| 214 | loader.template_source_loaders = old_loaders |
| 215 | settings.TEMPLATE_DEBUG = old_td |
183 | | template = loader.get_template(load_name) |
184 | | template_name = template.nodelist[0].source[0].name |
185 | | self.assertTrue(template_name.endswith(load_name), |
186 | | 'Template loaded through cached loader has incorrect name for debug page: %s' % template_name) |
| 217 | def test_does_not_exist_name_cache(self): |
| 218 | old_td, settings.TEMPLATE_DEBUG = settings.TEMPLATE_DEBUG, True |
| 219 | old_loaders = loader.template_source_loaders |
188 | | template = loader.get_template(load_name) |
189 | | template_name = template.nodelist[0].source[0].name |
190 | | self.assertTrue(template_name.endswith(load_name), |
191 | | 'Cached template loaded through cached loader has incorrect name for debug page: %s' % template_name) |
| 221 | try: |
| 222 | cache_loader = cached.Loader(('',)) |
| 223 | cache_loader._cached_loaders = (app_directories.Loader(),) |
| 224 | loader.template_source_loaders = (cache_loader,) |
193 | | loader.template_source_loaders = old_loaders |
194 | | settings.TEMPLATE_DEBUG = old_td |
| 226 | load_name = 'test_extends_error.html' |
| 227 | tmpl = loader.get_template(load_name) |
| 228 | r = None |
| 229 | try: |
| 230 | r = tmpl.render(template.Context({})) |
| 231 | except template.TemplateSyntaxError, e: |
| 232 | self.assertEqual(e.args[0], 'Caught TemplateDoesNotExist while rendering: missing.html') |
| 233 | self.assertEqual(r, None, 'Template rendering unexpectedly succeeded, produced: ->%r<-' % r) |
| 235 | # For the cached loader, repeat the test, to ensure the first attempt did not cache a |
| 236 | # result that behaves incorrectly on subsequent attempts. |
| 237 | tmpl = loader.get_template(load_name) |
| 238 | try: |
| 239 | tmpl.render(template.Context({})) |
| 240 | except template.TemplateSyntaxError, e: |
| 241 | self.assertEqual(e.args[0], 'Caught TemplateDoesNotExist while rendering: missing.html') |
| 242 | self.assertEqual(r, None, 'Template rendering unexpectedly succeeded, produced: ->%r<-' % r) |
| 243 | finally: |
| 244 | loader.template_source_loaders = old_loaders |
| 245 | settings.TEMPLATE_DEBUG = old_td |
| 246 | |