Ticket #7611: 7611.diff
File 7611.diff, 5.6 KB (added by , 16 years ago) |
---|
-
django/test/testcases.py
1 1 import re 2 import os 3 import sys 2 4 import unittest 3 5 from urlparse import urlsplit, urlunsplit 4 6 … … 58 60 named fixtures. 59 61 * If the Test Case class has a 'urls' member, replace the 60 62 ROOT_URLCONF with it. 63 * If the Test Case class has a 'template_dirs` member, replace the 64 TEMPLATE_DIRS with the values in template_dirs interpreted as 65 path names relative to the directory where the test is defined. 66 * If the Test Case class has a 'template_loaders` member, replace the 67 TEMPLATE_LOADERS with it. 61 68 * Clearing the mail test outbox. 62 69 """ 63 70 call_command('flush', verbosity=0, interactive=False) … … 69 76 self._old_root_urlconf = settings.ROOT_URLCONF 70 77 settings.ROOT_URLCONF = self.urls 71 78 clear_url_caches() 79 if hasattr(self, 'template_loaders'): 80 self._old_template_loaders = settings.TEMPLATE_LOADERS 81 settings.TEMPLATE_LOADERS = self.template_loaders 82 if hasattr(self, 'template_dirs'): 83 self._old_template_dirs = settings.TEMPLATE_DIRS 84 test_dir = os.path.dirname(sys.modules[self.__module__].__file__) 85 settings.TEMPLATE_DIRS = [ os.path.join(test_dir, dirname) for dirname in self.template_dirs ] 86 72 87 mail.outbox = [] 73 88 74 89 def __call__(self, result=None): … … 104 119 if hasattr(self, '_old_root_urlconf'): 105 120 settings.ROOT_URLCONF = self._old_root_urlconf 106 121 clear_url_caches() 122 if hasattr(self, '_old_template_loaders'): 123 settings.TEMPLATE_LOADERS = self._old_template_loaders 124 if hasattr(self, '_old_template_dirs'): 125 settings.TEMPLATE_DIRS = self._old_template_dirs 107 126 108 127 def assertRedirects(self, response, expected_url, status_code=302, 109 128 target_status_code=200, host=None): -
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 template_dirs = ('templates',) 65 template_loaders = ('django.template.loaders.filesystem.load_template_source',) 66 65 67 def test_email_not_found(self): 66 68 "Error is raised if the provided email address isn't currently registered" 67 69 response = self.client.get('/password_reset/') -
django/contrib/auth/tests/templates/registration/password_reset_form.html
1 {% if form.email.errors %}{{ form.email.errors }}{% endif %} 2 No newline at end of file -
django/contrib/auth/tests/templates/registration/password_reset_email.html
1 <p>A valid email address was provided for password reset</p> 2 No newline at end of file -
docs/testing.txt
830 830 This test case will use the contents of ``myapp.test_urls`` as the 831 831 URLconf for the duration of the test case. 832 832 833 Test templates 834 ~~~~~~~~~~~~~~ 835 836 **New in Django development version** 837 838 If you are building a truly reusable application, you can't always rely 839 upon the fact that the project in which your application is deployed will 840 provide templates in the same way as templates being available. 841 842 In order to provide a reliable collection of templates for your tests, 843 ``django.test.TestCase`` provides the ability to customize the template 844 directories and loaders for the duration of a test suite. 845 846 If your ``TestCase`` instance defines the attributes ``template_dirs`` 847 or ``template_loaders``, the values provided will override the values for 848 ``settings.TEMPLATE_DIRS`` and ``settings.TEMPLATE_LOADERS`` respectively, 849 for the duration of the tests. 850 851 The value of ``template_loaders`` is interpreted the same way that 852 ``settings.TEMPLATE_LOADERS`` is interpreted in a normal settings file. 853 However, in order to avoid a dependency on a specific absolute project 854 directory, the directories named in ``template_dirs`` will be interpreted 855 as being relative to the directory containing the file in which the test 856 case is defined. 857 858 For example, consider the following test case:: 859 860 from django.test import TestCase 861 862 class TestMyViews(TestCase): 863 template_dirs = ('templates',) 864 template_loaders = ('django.template.loaders.filesystem.load_template_source',) 865 866 def testIndexPageView(self): 867 # Here you'd test your view using ``Client``. 868 869 If this test case was defined in ``/foo/bar/tests/mytest.py``, then templates 870 would be loaded from ``/for/bar/tests/templates/`` for the duration of the 871 test case. 872 833 873 Emptying the test outbox 834 874 ~~~~~~~~~~~~~~~~~~~~~~~~ 835 875