Ticket #7611: test_template_loader_r7967.diff
File test_template_loader_r7967.diff, 3.3 KB (added by , 16 years ago) |
---|
-
django/test/testcases.py
58 58 named fixtures. 59 59 * If the Test Case class has a 'urls' member, replace the 60 60 ROOT_URLCONF with it. 61 * If the Test Case class has a 'templates` member, replace the 62 TEMPLATE_DIRS with it, and include the test template loader. 61 63 * Clearing the mail test outbox. 62 64 """ 63 65 call_command('flush', verbosity=0, interactive=False) … … 69 71 self._old_root_urlconf = settings.ROOT_URLCONF 70 72 settings.ROOT_URLCONF = self.urls 71 73 clear_url_caches() 74 if hasattr(self, 'templates'): 75 self._old_template_loaders = settings.TEMPLATE_LOADERS 76 self._old_template_dirs = settings.TEMPLATE_DIRS 77 settings.TEMPLATE_LOADERS = ('django.test.template_loader.load_template_source',) + settings.TEMPLATE_LOADERS 78 settings.TEMPLATE_DIRS = self.templates 72 79 mail.outbox = [] 73 80 74 81 def __call__(self, result=None): … … 104 111 if hasattr(self, '_old_root_urlconf'): 105 112 settings.ROOT_URLCONF = self._old_root_urlconf 106 113 clear_url_caches() 114 if hasattr(self, '_old_template_loaders'): 115 settings.TEMPLATE_LOADERS = self._old_template_loaders 116 settings.TEMPLATE_DIRS = self._old_template_dirs 107 117 108 118 def assertRedirects(self, response, expected_url, status_code=302, 109 119 target_status_code=200, host=None): -
django/test/template_loader.py
1 from django.conf import settings 2 from django.template import TemplateDoesNotExist 3 4 def get_template_sources(template_name, template_dirs=None): 5 # We don't use template_dirs as a list of directories. Instead, 6 # template_dirs is a dictionary with the template_name as the key and 7 # the contents of the template as the value. 8 if not template_dirs: 9 template_dirs = settings.TEMPLATE_DIRS 10 return template_dirs 11 12 def load_template_source(template_name, template_dirs=None): 13 template_dirs = get_template_sources(template_name, template_dirs) 14 if template_name in template_dirs: 15 return (template_dirs[template_name], template_name) 16 else: 17 raise TemplateDoesNotExist, template_name 18 load_template_source.is_usable = True -
django/contrib/auth/tests/basic.py
61 61 class PasswordResetTest(TestCase): 62 62 fixtures = ['authtestdata.json'] 63 63 urls = 'django.contrib.auth.urls' 64 64 templates = { 65 'registration/password_reset_form.html': '{% if form.email.errors %}{{ form.email.html_error_list }}{% endif %}', 66 'registration/password_reset_email.html': '', 67 } 68 65 69 def test_email_not_found(self): 66 70 "Error is raised if the provided email address isn't currently registered" 67 71 response = self.client.get('/password_reset/')