mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Removed vary_delim_re
in django/utils/cache.py
in favor of existing cc_delim_re
since the latter is more correct in parsing the header (allows whitespace before and after comma separators instead of just after). As a bonus, tests added for patch_vary_headers()
.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6696 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
7d8ac66026
commit
34cc21983c
2 changed files with 31 additions and 5 deletions
30
tests/regressiontests/cache/tests.py
vendored
30
tests/regressiontests/cache/tests.py
vendored
|
@ -3,9 +3,12 @@
|
|||
# Unit tests for cache framework
|
||||
# Uses whatever cache backend is set in the test settings file.
|
||||
|
||||
from django.core.cache import cache
|
||||
import time, unittest
|
||||
|
||||
from django.core.cache import cache
|
||||
from django.utils.cache import patch_vary_headers
|
||||
from django.http import HttpResponse
|
||||
|
||||
# functions/classes for complex data type tests
|
||||
def f():
|
||||
return 42
|
||||
|
@ -87,5 +90,30 @@ class Cache(unittest.TestCase):
|
|||
cache.set(key, value)
|
||||
self.assertEqual(cache.get(key), value)
|
||||
|
||||
|
||||
class CacheUtils(unittest.TestCase):
|
||||
"""TestCase for django.utils.cache functions."""
|
||||
|
||||
def test_patch_vary_headers(self):
|
||||
headers = (
|
||||
# Initial vary, new headers, resulting vary.
|
||||
(None, ('Accept-Encoding',), 'Accept-Encoding'),
|
||||
('Accept-Encoding', ('accept-encoding',), 'Accept-Encoding'),
|
||||
('Accept-Encoding', ('ACCEPT-ENCODING',), 'Accept-Encoding'),
|
||||
('Cookie', ('Accept-Encoding',), 'Cookie, Accept-Encoding'),
|
||||
('Cookie, Accept-Encoding', ('Accept-Encoding',), 'Cookie, Accept-Encoding'),
|
||||
('Cookie, Accept-Encoding', ('Accept-Encoding', 'cookie'), 'Cookie, Accept-Encoding'),
|
||||
(None, ('Accept-Encoding', 'COOKIE'), 'Accept-Encoding, COOKIE'),
|
||||
('Cookie, Accept-Encoding', ('Accept-Encoding', 'cookie'), 'Cookie, Accept-Encoding'),
|
||||
('Cookie , Accept-Encoding', ('Accept-Encoding', 'cookie'), 'Cookie, Accept-Encoding'),
|
||||
)
|
||||
for initial_vary, newheaders, resulting_vary in headers:
|
||||
response = HttpResponse()
|
||||
if initial_vary is not None:
|
||||
response['Vary'] = initial_vary
|
||||
patch_vary_headers(response, newheaders)
|
||||
self.assertEqual(response['Vary'], resulting_vary)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue