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
|
2018-11-26 19:05:02 +00:00
|
|
|
from django.test import SimpleTestCase
|
2017-05-31 14:25:09 +00:00
|
|
|
from django.test.utils import extend_sys_path
|
2014-12-03 14:44:09 +00:00
|
|
|
|
|
|
|
|
2018-11-26 19:05:02 +00:00
|
|
|
class TestStartProjectSettings(SimpleTestCase):
|
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__),
|
2022-02-03 19:24:19 +00:00
|
|
|
"project_template",
|
|
|
|
"project_name",
|
|
|
|
"settings.py-tpl",
|
2016-01-24 09:06:01 +00:00
|
|
|
)
|
2022-02-03 19:24:19 +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,
|
2022-02-03 19:24:19 +00:00
|
|
|
ROOT_URLCONF="project_template.urls",
|
2014-12-03 14:44:09 +00:00
|
|
|
):
|
2022-02-03 19:24:19 +00:00
|
|
|
response = self.client.get("/empty/")
|
|
|
|
headers = sorted(response.serialize_headers().split(b"\r\n"))
|
|
|
|
self.assertEqual(
|
|
|
|
headers,
|
|
|
|
[
|
|
|
|
b"Content-Length: 0",
|
|
|
|
b"Content-Type: text/html; charset=utf-8",
|
|
|
|
b"Cross-Origin-Opener-Policy: same-origin",
|
|
|
|
b"Referrer-Policy: same-origin",
|
|
|
|
b"X-Content-Type-Options: nosniff",
|
|
|
|
b"X-Frame-Options: DENY",
|
|
|
|
],
|
|
|
|
)
|