mirror of
				https://github.com/django/django.git
				synced 2025-10-30 17:16:10 +00:00 
			
		
		
		
	[1.11.x] Fixed #26755 -- Fixed test_middleware_classes_headers if Django source isn't writable.
Backport of 2ec56bb782 from master
			
			
This commit is contained in:
		| @@ -1,11 +1,12 @@ | |||||||
| import os | import os | ||||||
| import shutil | import shutil | ||||||
|  | import tempfile | ||||||
| import unittest | import unittest | ||||||
|  |  | ||||||
| from django import conf | from django import conf | ||||||
| from django.test import TestCase | from django.test import TestCase | ||||||
|  | from django.test.utils import extend_sys_path | ||||||
| from django.utils import six | from django.utils import six | ||||||
| from django.utils._os import upath |  | ||||||
|  |  | ||||||
|  |  | ||||||
| @unittest.skipIf( | @unittest.skipIf( | ||||||
| @@ -15,16 +16,16 @@ from django.utils._os import upath | |||||||
| ) | ) | ||||||
| class TestStartProjectSettings(TestCase): | class TestStartProjectSettings(TestCase): | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         # Ensure settings.py exists |         self.temp_dir = tempfile.TemporaryDirectory() | ||||||
|         project_dir = os.path.join( |         self.addCleanup(self.temp_dir.cleanup) | ||||||
|             os.path.dirname(upath(conf.__file__)), |         template_settings_py = os.path.join( | ||||||
|  |             os.path.dirname(conf.__file__), | ||||||
|             'project_template', |             'project_template', | ||||||
|             'project_name', |             'project_name', | ||||||
|  |             'settings.py-tpl', | ||||||
|         ) |         ) | ||||||
|         template_settings_py = os.path.join(project_dir, 'settings.py-tpl') |         test_settings_py = os.path.join(self.temp_dir.name, 'test_settings.py') | ||||||
|         test_settings_py = os.path.join(project_dir, 'settings.py') |  | ||||||
|         shutil.copyfile(template_settings_py, test_settings_py) |         shutil.copyfile(template_settings_py, test_settings_py) | ||||||
|         self.addCleanup(os.remove, test_settings_py) |  | ||||||
|  |  | ||||||
|     def test_middleware_headers(self): |     def test_middleware_headers(self): | ||||||
|         """ |         """ | ||||||
| @@ -32,7 +33,8 @@ class TestStartProjectSettings(TestCase): | |||||||
|         change. For example, we never want "Vary: Cookie" to appear in the list |         change. For example, we never want "Vary: Cookie" to appear in the list | ||||||
|         since it prevents the caching of responses. |         since it prevents the caching of responses. | ||||||
|         """ |         """ | ||||||
|         from django.conf.project_template.project_name.settings import MIDDLEWARE |         with extend_sys_path(self.temp_dir.name): | ||||||
|  |             from test_settings import MIDDLEWARE | ||||||
|  |  | ||||||
|         with self.settings( |         with self.settings( | ||||||
|             MIDDLEWARE=MIDDLEWARE, |             MIDDLEWARE=MIDDLEWARE, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user