2016-01-24 09:06:01 +00:00
|
|
|
import os
|
|
|
|
import shutil
|
2017-05-31 14:25:09 +00:00
|
|
|
import tempfile
|
2014-12-03 14:44:09 +00:00
|
|
|
|
2016-01-24 09:06:01 +00:00
|
|
|
from django import conf
|
2014-12-03 14:44:09 +00:00
|
|
|
from django.test import TestCase
|
2017-05-31 14:25:09 +00:00
|
|
|
from django.test.utils import extend_sys_path
|
2014-12-03 14:44:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestStartProjectSettings(TestCase):
|
2016-01-24 09:06:01 +00:00
|
|
|
def setUp(self):
|
2017-05-31 14:25:09 +00:00
|
|
|
self.temp_dir = tempfile.TemporaryDirectory()
|
|
|
|
self.addCleanup(self.temp_dir.cleanup)
|
|
|
|
template_settings_py = os.path.join(
|
2017-01-20 13:01:02 +00:00
|
|
|
os.path.dirname(conf.__file__),
|
2016-01-24 09:06:01 +00:00
|
|
|
'project_template',
|
|
|
|
'project_name',
|
2017-05-31 14:25:09 +00:00
|
|
|
'settings.py-tpl',
|
2016-01-24 09:06:01 +00:00
|
|
|
)
|
2017-05-31 14:25:09 +00:00
|
|
|
test_settings_py = os.path.join(self.temp_dir.name, 'test_settings.py')
|
2016-01-24 09:06:01 +00:00
|
|
|
shutil.copyfile(template_settings_py, test_settings_py)
|
2014-12-03 14:44:09 +00:00
|
|
|
|
2015-11-07 15:12:37 +00:00
|
|
|
def test_middleware_headers(self):
|
2014-12-03 14:44:09 +00:00
|
|
|
"""
|
2015-11-07 15:12:37 +00:00
|
|
|
Ensure headers sent by the default MIDDLEWARE don't inadvertently
|
|
|
|
change. For example, we never want "Vary: Cookie" to appear in the list
|
|
|
|
since it prevents the caching of responses.
|
2014-12-03 14:44:09 +00:00
|
|
|
"""
|
2017-05-31 14:25:09 +00:00
|
|
|
with extend_sys_path(self.temp_dir.name):
|
|
|
|
from test_settings import MIDDLEWARE
|
2014-12-03 14:44:09 +00:00
|
|
|
|
|
|
|
with self.settings(
|
2015-11-07 15:12:37 +00:00
|
|
|
MIDDLEWARE=MIDDLEWARE,
|
2014-12-03 14:44:09 +00:00
|
|
|
ROOT_URLCONF='project_template.urls',
|
|
|
|
):
|
|
|
|
response = self.client.get('/empty/')
|
|
|
|
headers = sorted(response.serialize_headers().split(b'\r\n'))
|
|
|
|
self.assertEqual(headers, [
|
2016-06-18 08:51:38 +00:00
|
|
|
b'Content-Length: 0',
|
2014-12-03 14:44:09 +00:00
|
|
|
b'Content-Type: text/html; charset=utf-8',
|
|
|
|
b'X-Frame-Options: SAMEORIGIN',
|
|
|
|
])
|