diff options
| author | Chris Lamb <chris@chris-lamb.co.uk> | 2017-05-31 15:25:09 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-06-02 10:29:39 -0400 |
| commit | fa63fc91ccc08b20ed4ca45e73f7aad2b38d9171 (patch) | |
| tree | 85b9f606a0c3f62e39c68e38ce508efbc9961cf6 /tests | |
| parent | 1940e3daef8192d289f82fe97a9535fbca6a2c8c (diff) | |
[1.11.x] Fixed #26755 -- Fixed test_middleware_classes_headers if Django source isn't writable.
Backport of 2ec56bb78237ebf58494d7a7f3262482399f0be6 from master
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/project_template/test_settings.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/tests/project_template/test_settings.py b/tests/project_template/test_settings.py index a0047dd836..791c42e03a 100644 --- a/tests/project_template/test_settings.py +++ b/tests/project_template/test_settings.py @@ -1,11 +1,12 @@ import os import shutil +import tempfile import unittest from django import conf from django.test import TestCase +from django.test.utils import extend_sys_path from django.utils import six -from django.utils._os import upath @unittest.skipIf( @@ -15,16 +16,16 @@ from django.utils._os import upath ) class TestStartProjectSettings(TestCase): def setUp(self): - # Ensure settings.py exists - project_dir = os.path.join( - os.path.dirname(upath(conf.__file__)), + self.temp_dir = tempfile.TemporaryDirectory() + self.addCleanup(self.temp_dir.cleanup) + template_settings_py = os.path.join( + os.path.dirname(conf.__file__), 'project_template', 'project_name', + 'settings.py-tpl', ) - template_settings_py = os.path.join(project_dir, 'settings.py-tpl') - test_settings_py = os.path.join(project_dir, 'settings.py') + test_settings_py = os.path.join(self.temp_dir.name, 'test_settings.py') shutil.copyfile(template_settings_py, test_settings_py) - self.addCleanup(os.remove, test_settings_py) 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 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( MIDDLEWARE=MIDDLEWARE, |
