test_settings.py 1.1 KB

1234567891011121314151617181920212223242526272829
  1. import unittest
  2. from django.test import TestCase
  3. from django.utils import six
  4. @unittest.skipIf(six.PY2,
  5. 'Python 2 cannot import the project template because '
  6. 'django/conf/project_template doesn\'t have an __init__.py file.')
  7. class TestStartProjectSettings(TestCase):
  8. def test_middleware_classes_headers(self):
  9. """
  10. Ensure headers sent by the default MIDDLEWARE_CLASSES do not
  11. inadvertently change. For example, we never want "Vary: Cookie" to
  12. appear in the list since it prevents the caching of responses.
  13. """
  14. from django.conf.project_template.project_name.settings import MIDDLEWARE_CLASSES
  15. with self.settings(
  16. MIDDLEWARE_CLASSES=MIDDLEWARE_CLASSES,
  17. ROOT_URLCONF='project_template.urls',
  18. ):
  19. response = self.client.get('/empty/')
  20. headers = sorted(response.serialize_headers().split(b'\r\n'))
  21. self.assertEqual(headers, [
  22. b'Content-Type: text/html; charset=utf-8',
  23. b'X-Frame-Options: SAMEORIGIN',
  24. ])