summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2011-12-29 13:57:32 +0000
committerAymeric Augustin <aymeric.augustin@m4x.org>2011-12-29 13:57:32 +0000
commit3367913c3db97a15b64f03646ac2c4486a77376f (patch)
treec2d95b672186557a97e5981b859749f7069e1eb3 /tests
parentec07a30e821ada170904df8901787e05b7959594 (diff)
Fixed #17476 -- Ensure timezone-dependant cache keys only use ASCII characters, especially on Windows.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17286 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/cache/tests.py31
1 files changed, 29 insertions, 2 deletions
diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py
index 8faaa6fdc4..d31a5e0d87 100644
--- a/tests/regressiontests/cache/tests.py
+++ b/tests/regressiontests/cache/tests.py
@@ -28,6 +28,7 @@ from django.test.utils import (get_warnings_state, restore_warnings_state,
from django.utils import timezone, translation, unittest
from django.utils.cache import (patch_vary_headers, get_cache_key,
learn_cache_key, patch_cache_control, patch_response_headers)
+from django.utils.encoding import force_unicode
from django.views.decorators.cache import cache_page
from .models import Poll, expensive_calculation
@@ -1270,7 +1271,10 @@ class CacheI18nTest(TestCase):
@override_settings(USE_I18N=False, USE_L10N=False, USE_TZ=True)
def test_cache_key_i18n_timezone(self):
request = self._get_request()
- tz = timezone.get_current_timezone_name().replace(' ', '_')
+ # This is tightly coupled to the implementation,
+ # but it's the most straightforward way to test the key.
+ tz = force_unicode(timezone.get_current_timezone_name(), errors='ignore')
+ tz = tz.encode('ascii', 'ignore').replace(' ', '_')
response = HttpResponse()
key = learn_cache_key(request, response)
self.assertIn(tz, key, "Cache keys should include the time zone name when time zones are active")
@@ -1281,12 +1285,35 @@ class CacheI18nTest(TestCase):
def test_cache_key_no_i18n (self):
request = self._get_request()
lang = translation.get_language()
- tz = timezone.get_current_timezone_name().replace(' ', '_')
+ tz = force_unicode(timezone.get_current_timezone_name(), errors='ignore')
+ tz = tz.encode('ascii', 'ignore').replace(' ', '_')
response = HttpResponse()
key = learn_cache_key(request, response)
self.assertNotIn(lang, key, "Cache keys shouldn't include the language name when i18n isn't active")
self.assertNotIn(tz, key, "Cache keys shouldn't include the time zone name when i18n isn't active")
+ @override_settings(USE_I18N=False, USE_L10N=False, USE_TZ=True)
+ def test_cache_key_with_non_ascii_tzname(self):
+ # Regression test for #17476
+ class CustomTzName(timezone.UTC):
+ name = ''
+ def tzname(self, dt):
+ return self.name
+
+ request = self._get_request()
+ response = HttpResponse()
+ with timezone.override(CustomTzName()):
+ CustomTzName.name = 'Hora estándar de Argentina' # UTF-8 string
+ sanitized_name = 'Hora_estndar_de_Argentina'
+ self.assertIn(sanitized_name, learn_cache_key(request, response),
+ "Cache keys should include the time zone name when time zones are active")
+
+ CustomTzName.name = u'Hora estándar de Argentina' # unicode
+ sanitized_name = 'Hora_estndar_de_Argentina'
+ self.assertIn(sanitized_name, learn_cache_key(request, response),
+ "Cache keys should include the time zone name when time zones are active")
+
+
@override_settings(
CACHE_MIDDLEWARE_KEY_PREFIX="test",
CACHE_MIDDLEWARE_SECONDS=60,