Files
edx-platform/common/djangoapps/clean_headers/tests/test_middleware.py
Toby Lawrence 01a9ad2369 Add support to enhance the cacheability of course assets.
This introduces a mechanism to control the time-to-live for an unlocked
course asset, which will allow browsers and intermediate proxies/caches
to cache these course assets, determinstically.

Locked assets, with their nature of requiring authorization, are not
eligible for caching.
2016-01-26 21:09:18 -05:00

35 lines
1.3 KiB
Python

"""Tests for clean_headers middleware."""
from django.http import HttpResponse, HttpRequest
from django.test import TestCase
from clean_headers.middleware import CleanHeadersMiddleware
class TestCleanHeadersMiddlewareProcessResponse(TestCase):
"""Test the `clean_headers` middleware. """
def setUp(self):
super(TestCleanHeadersMiddlewareProcessResponse, self).setUp()
self.middleware = CleanHeadersMiddleware()
def test_cleans_intended_headers(self):
fake_request = HttpRequest()
fake_response = HttpResponse()
fake_response['Vary'] = 'Cookie'
fake_response['Accept-Encoding'] = 'gzip'
fake_response.clean_headers = ['Vary']
result = self.middleware.process_response(fake_request, fake_response)
self.assertNotIn('Vary', result)
self.assertEquals('gzip', result['Accept-Encoding'])
def test_does_not_mangle_undecorated_response(self):
fake_request = HttpRequest()
fake_response = HttpResponse()
fake_response['Vary'] = 'Cookie'
fake_response['Accept-Encoding'] = 'gzip'
result = self.middleware.process_response(fake_request, fake_response)
self.assertEquals('Cookie', result['Vary'])
self.assertEquals('gzip', result['Accept-Encoding'])