Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/tests/project_template/test_settings.py
blob: ac115f7dc284e76ee85a34971d491f708112a0fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import unittest

from django.test import TestCase
from django.utils import six


@unittest.skipIf(six.PY2,
    'Python 2 cannot import the project template because '
    'django/conf/project_template doesn\'t have an __init__.py file.')
class TestStartProjectSettings(TestCase):

    def test_middleware_classes_headers(self):
        """
        Ensure headers sent by the default MIDDLEWARE_CLASSES do not
        inadvertently 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_CLASSES

        with self.settings(
            MIDDLEWARE_CLASSES=MIDDLEWARE_CLASSES,
            ROOT_URLCONF='project_template.urls',
        ):
            response = self.client.get('/empty/')
            headers = sorted(response.serialize_headers().split(b'\r\n'))
            self.assertEqual(headers, [
                b'Content-Type: text/html; charset=utf-8',
                b'X-Frame-Options: SAMEORIGIN',
            ])