Commit c844d022 by Camilo Nova

Added tests to make sure when a response is compressed the 'Content-Length'…

Added tests to make sure when a response is compressed the 'Content-Length' header is included in the response, otherwise the client (curl for example) will be confused about the content length
parent 85600af7
......@@ -13,6 +13,7 @@ SITE_ID = 1
INSTALLED_APPS = [
'django.contrib.contenttypes',
'django.contrib.sites',
'django.contrib.sessions',
'django.contrib.staticfiles',
'django.contrib.auth',
'django.contrib.admin',
......@@ -20,6 +21,8 @@ INSTALLED_APPS = [
'tests',
]
ROOT_URLCONF = 'tests.urls'
MEDIA_URL = '/media/'
MEDIA_ROOT = local_path('media')
......
......@@ -3,6 +3,7 @@ from .test_compiler import *
from .test_compressor import *
from .test_extension import *
from .test_glob import *
from .test_middleware import *
from .test_packager import *
from .test_storage import *
from .test_utils import *
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase
from django.conf import settings
from django.core.urlresolvers import reverse
class MiddlewareTest(TestCase):
def test_middleware_off(self):
response = self.client.get(reverse('admin:index'))
self.assertIn('text/html', response['Content-Type'])
# Should not come if not compressed
self.assertNotIn('Content-Length', response)
def test_middleware_on(self):
CUSTOM_MIDDLEWARE = (
'django.middleware.gzip.GZipMiddleware',
'pipeline.middleware.MinifyHTMLMiddleware',
) + settings.MIDDLEWARE_CLASSES
with self.settings(MIDDLEWARE_CLASSES=CUSTOM_MIDDLEWARE):
response = self.client.get(reverse('admin:index'))
self.assertIn('text/html', response['Content-Type'])
length = str(len(response.content))
self.assertEqual(length, response['Content-Length'])
from django.conf.urls import patterns, include
from django.contrib import admin
urlpatterns = patterns(
'',
(r'^admin/', include(admin.site.urls)),
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment