From 50c1d8f24b0d04c813b3dd34720df86446091afa Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Wed, 3 Dec 2014 09:44:09 -0500 Subject: [PATCH] Added a test to verify headers set by default middleware; refs #23939. --- tests/project_template/__init__.py | 0 tests/project_template/test_settings.py | 29 +++++++++++++++++++++++++ tests/project_template/urls.py | 7 ++++++ tests/project_template/views.py | 5 +++++ 4 files changed, 41 insertions(+) create mode 100644 tests/project_template/__init__.py create mode 100644 tests/project_template/test_settings.py create mode 100644 tests/project_template/urls.py create mode 100644 tests/project_template/views.py diff --git a/tests/project_template/__init__.py b/tests/project_template/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/project_template/test_settings.py b/tests/project_template/test_settings.py new file mode 100644 index 00000000000..8998a844c76 --- /dev/null +++ b/tests/project_template/test_settings.py @@ -0,0 +1,29 @@ +import sys +import unittest + +from django.test import TestCase + + +@unittest.skipIf(sys.version_info < (3, 3), + 'Python < 3.3 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', + ]) diff --git a/tests/project_template/urls.py b/tests/project_template/urls.py new file mode 100644 index 00000000000..db0e9bb42e9 --- /dev/null +++ b/tests/project_template/urls.py @@ -0,0 +1,7 @@ +from django.conf.urls import url + +from . import views + +urlpatterns = [ + url(r'^empty/$', views.empty_view), +] diff --git a/tests/project_template/views.py b/tests/project_template/views.py new file mode 100644 index 00000000000..50e23d1782a --- /dev/null +++ b/tests/project_template/views.py @@ -0,0 +1,5 @@ +from django.http import HttpResponse + + +def empty_view(request, *args, **kwargs): + return HttpResponse('')