2016-01-24 17:06:01 +08:00
|
|
|
import os
|
|
|
|
import shutil
|
2017-05-31 22:25:09 +08:00
|
|
|
import tempfile
|
2014-12-03 22:44:09 +08:00
|
|
|
|
2016-01-24 17:06:01 +08:00
|
|
|
from django import conf
|
2018-11-27 03:05:02 +08:00
|
|
|
from django.test import SimpleTestCase
|
2017-05-31 22:25:09 +08:00
|
|
|
from django.test.utils import extend_sys_path
|
2014-12-03 22:44:09 +08:00
|
|
|
|
|
|
|
|
2018-11-27 03:05:02 +08:00
|
|
|
class TestStartProjectSettings(SimpleTestCase):
|
2016-01-24 17:06:01 +08:00
|
|
|
def setUp(self):
|
2017-05-31 22:25:09 +08:00
|
|
|
self.temp_dir = tempfile.TemporaryDirectory()
|
|
|
|
self.addCleanup(self.temp_dir.cleanup)
|
|
|
|
template_settings_py = os.path.join(
|
2017-01-20 21:01:02 +08:00
|
|
|
os.path.dirname(conf.__file__),
|
2016-01-24 17:06:01 +08:00
|
|
|
'project_template',
|
|
|
|
'project_name',
|
2017-05-31 22:25:09 +08:00
|
|
|
'settings.py-tpl',
|
2016-01-24 17:06:01 +08:00
|
|
|
)
|
2017-05-31 22:25:09 +08:00
|
|
|
test_settings_py = os.path.join(self.temp_dir.name, 'test_settings.py')
|
2016-01-24 17:06:01 +08:00
|
|
|
shutil.copyfile(template_settings_py, test_settings_py)
|
2014-12-03 22:44:09 +08:00
|
|
|
|
2015-11-07 23:12:37 +08:00
|
|
|
def test_middleware_headers(self):
|
2014-12-03 22:44:09 +08:00
|
|
|
"""
|
2015-11-07 23:12:37 +08: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 22:44:09 +08:00
|
|
|
"""
|
2017-05-31 22:25:09 +08:00
|
|
|
with extend_sys_path(self.temp_dir.name):
|
|
|
|
from test_settings import MIDDLEWARE
|
2014-12-03 22:44:09 +08:00
|
|
|
|
|
|
|
with self.settings(
|
2015-11-07 23:12:37 +08:00
|
|
|
MIDDLEWARE=MIDDLEWARE,
|
2014-12-03 22:44:09 +08: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 16:51:38 +08:00
|
|
|
b'Content-Length: 0',
|
2014-12-03 22:44:09 +08:00
|
|
|
b'Content-Type: text/html; charset=utf-8',
|
2020-02-05 18:02:35 +08:00
|
|
|
b'Referrer-Policy: same-origin',
|
2019-08-02 23:16:01 +08:00
|
|
|
b'X-Content-Type-Options: nosniff',
|
2019-09-07 15:52:10 +08:00
|
|
|
b'X-Frame-Options: DENY',
|
2014-12-03 22:44:09 +08:00
|
|
|
])
|