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.
This commit is contained in:
20
common/djangoapps/clean_headers/tests/test_decorators.py
Normal file
20
common/djangoapps/clean_headers/tests/test_decorators.py
Normal file
@@ -0,0 +1,20 @@
|
||||
"""Tests for clean_headers decorator. """
|
||||
from django.http import HttpResponse, HttpRequest
|
||||
from django.test import TestCase
|
||||
from clean_headers.decorators import clean_headers
|
||||
|
||||
|
||||
def fake_view(_request):
|
||||
"""Fake view that returns an empty response."""
|
||||
return HttpResponse()
|
||||
|
||||
|
||||
class TestCleanHeaders(TestCase):
|
||||
"""Test the `clean_headers` decorator."""
|
||||
|
||||
def test_clean_headers(self):
|
||||
request = HttpRequest()
|
||||
wrapper = clean_headers('Vary', 'Accept-Encoding')
|
||||
wrapped_view = wrapper(fake_view)
|
||||
response = wrapped_view(request)
|
||||
self.assertEqual(len(response.clean_headers), 2)
|
||||
34
common/djangoapps/clean_headers/tests/test_middleware.py
Normal file
34
common/djangoapps/clean_headers/tests/test_middleware.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""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'])
|
||||
Reference in New Issue
Block a user