test_settings.py 1.36 KB
Newer Older
1 2
import os
import shutil
3

4
from django import conf
5 6 7 8
from django.test import TestCase


class TestStartProjectSettings(TestCase):
9 10 11
    def setUp(self):
        # Ensure settings.py exists
        project_dir = os.path.join(
12
            os.path.dirname(conf.__file__),
13 14 15 16 17 18 19
            'project_template',
            'project_name',
        )
        template_settings_py = os.path.join(project_dir, 'settings.py-tpl')
        test_settings_py = os.path.join(project_dir, 'settings.py')
        shutil.copyfile(template_settings_py, test_settings_py)
        self.addCleanup(os.remove, test_settings_py)
20

21
    def test_middleware_headers(self):
22
        """
23 24 25
        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.
26
        """
27
        from django.conf.project_template.project_name.settings import MIDDLEWARE
28 29

        with self.settings(
30
            MIDDLEWARE=MIDDLEWARE,
31 32 33 34 35
            ROOT_URLCONF='project_template.urls',
        ):
            response = self.client.get('/empty/')
            headers = sorted(response.serialize_headers().split(b'\r\n'))
            self.assertEqual(headers, [
36
                b'Content-Length: 0',
37 38 39
                b'Content-Type: text/html; charset=utf-8',
                b'X-Frame-Options: SAMEORIGIN',
            ])