summaryrefslogtreecommitdiff
path: root/tests/regressiontests/cache
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-03-30 09:08:29 +0000
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-03-30 09:08:29 +0000
commiteb163f37cb62268443d592f8ce08bd8a0ab9631d (patch)
treea373546137a3833d476b207d6490bd39c1e51a81 /tests/regressiontests/cache
parent9383a2761c67d588378f3679cc6c8ea3651a73c8 (diff)
Use the class decorator syntax available in Python >= 2.6. Refs #17965.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17829 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/cache')
-rw-r--r--tests/regressiontests/cache/tests.py118
1 files changed, 61 insertions, 57 deletions
diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py
index 6dbc03db32..00ccda6102 100644
--- a/tests/regressiontests/cache/tests.py
+++ b/tests/regressiontests/cache/tests.py
@@ -824,7 +824,9 @@ class DBCacheTests(BaseCacheTests, TransactionTestCase):
self.assertTrue("Cache table 'test cache table' could not be created" in err.getvalue())
-DBCacheWithTimeZoneTests = override_settings(USE_TZ=True)(DBCacheTests)
+@override_settings(USE_TZ=True)
+class DBCacheWithTimeZoneTests(DBCacheTests):
+ pass
class DBCacheRouter(object):
@@ -927,6 +929,9 @@ class LocMemCacheTests(unittest.TestCase, BaseCacheTests):
# To check the memcached backend, the test settings file will
# need to contain a cache backend setting that points at
# your memcache server.
+@unittest.skipUnless(
+ settings.CACHES[DEFAULT_CACHE_ALIAS]['BACKEND'].startswith('django.core.cache.backends.memcached.'),
+ "memcached not available")
class MemcachedCacheTests(unittest.TestCase, BaseCacheTests):
backend_name = 'django.core.cache.backends.memcached.MemcachedCache'
@@ -956,8 +961,6 @@ class MemcachedCacheTests(unittest.TestCase, BaseCacheTests):
# memcached limits key length to 250
self.assertRaises(Exception, self.cache.set, 'a' * 251, 'value')
-MemcachedCacheTests = unittest.skipUnless(settings.CACHES[DEFAULT_CACHE_ALIAS]['BACKEND'].startswith('django.core.cache.backends.memcached.'), "memcached not available")(MemcachedCacheTests)
-
class FileBasedCacheTests(unittest.TestCase, BaseCacheTests):
"""
@@ -1048,6 +1051,16 @@ class GetCacheTests(unittest.TestCase):
self.assertTrue(cache.closed)
+@override_settings(
+ CACHE_MIDDLEWARE_KEY_PREFIX='settingsprefix',
+ CACHE_MIDDLEWARE_SECONDS=1,
+ CACHES={
+ 'default': {
+ 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
+ },
+ },
+ USE_I18N=False,
+)
class CacheUtils(TestCase):
"""TestCase for django.utils.cache functions."""
@@ -1144,27 +1157,28 @@ class CacheUtils(TestCase):
parts = set(cc_delim_re.split(response['Cache-Control']))
self.assertEqual(parts, expected_cc)
-CacheUtils = override_settings(
- CACHE_MIDDLEWARE_KEY_PREFIX='settingsprefix',
- CACHE_MIDDLEWARE_SECONDS=1,
+
+@override_settings(
CACHES={
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
+ 'KEY_PREFIX': 'cacheprefix',
},
},
- USE_I18N=False,
-)(CacheUtils)
+)
+class PrefixedCacheUtils(CacheUtils):
+ pass
+
-PrefixedCacheUtils = override_settings(
+@override_settings(
+ CACHE_MIDDLEWARE_SECONDS=60,
+ CACHE_MIDDLEWARE_KEY_PREFIX='test',
CACHES={
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
- 'KEY_PREFIX': 'cacheprefix',
},
},
-)(CacheUtils)
-
-
+)
class CacheHEADTest(TestCase):
def setUp(self):
@@ -1216,17 +1230,19 @@ class CacheHEADTest(TestCase):
self.assertNotEqual(get_cache_data, None)
self.assertEqual(test_content, get_cache_data.content)
-CacheHEADTest = override_settings(
- CACHE_MIDDLEWARE_SECONDS=60,
- CACHE_MIDDLEWARE_KEY_PREFIX='test',
+
+@override_settings(
+ CACHE_MIDDLEWARE_KEY_PREFIX='settingsprefix',
CACHES={
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
},
},
-)(CacheHEADTest)
-
-
+ LANGUAGES=(
+ ('en', 'English'),
+ ('es', 'Spanish'),
+ ),
+)
class CacheI18nTest(TestCase):
def setUp(self):
@@ -1391,33 +1407,39 @@ class CacheI18nTest(TestCase):
# reset the language
translation.deactivate()
-CacheI18nTest = override_settings(
- CACHE_MIDDLEWARE_KEY_PREFIX='settingsprefix',
- CACHES={
- 'default': {
- 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
- },
- },
- LANGUAGES=(
- ('en', 'English'),
- ('es', 'Spanish'),
- ),
-)(CacheI18nTest)
-PrefixedCacheI18nTest = override_settings(
+@override_settings(
CACHES={
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'KEY_PREFIX': 'cacheprefix'
},
},
-)(CacheI18nTest)
+)
+class PrefixedCacheI18nTest(CacheI18nTest):
+ pass
def hello_world_view(request, value):
return HttpResponse('Hello World %s' % value)
+@override_settings(
+ CACHE_MIDDLEWARE_ALIAS='other',
+ CACHE_MIDDLEWARE_KEY_PREFIX='middlewareprefix',
+ CACHE_MIDDLEWARE_SECONDS=30,
+ CACHE_MIDDLEWARE_ANONYMOUS_ONLY=False,
+ CACHES={
+ 'default': {
+ 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
+ },
+ 'other': {
+ 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
+ 'LOCATION': 'other',
+ 'TIMEOUT': '1',
+ },
+ },
+)
class CacheMiddlewareTest(TestCase):
def setUp(self):
@@ -1635,24 +1657,17 @@ class CacheMiddlewareTest(TestCase):
response = other_with_timeout_view(request, '18')
self.assertEqual(response.content, 'Hello World 18')
-CacheMiddlewareTest = override_settings(
- CACHE_MIDDLEWARE_ALIAS='other',
- CACHE_MIDDLEWARE_KEY_PREFIX='middlewareprefix',
- CACHE_MIDDLEWARE_SECONDS=30,
- CACHE_MIDDLEWARE_ANONYMOUS_ONLY=False,
+
+@override_settings(
+ CACHE_MIDDLEWARE_KEY_PREFIX='settingsprefix',
+ CACHE_MIDDLEWARE_SECONDS=1,
CACHES={
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
},
- 'other': {
- 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
- 'LOCATION': 'other',
- 'TIMEOUT': '1',
- },
},
-)(CacheMiddlewareTest)
-
-
+ USE_I18N=False,
+)
class TestWithTemplateResponse(TestCase):
"""
Tests various headers w/ TemplateResponse.
@@ -1740,17 +1755,6 @@ class TestWithTemplateResponse(TestCase):
response = response.render()
self.assertTrue(response.has_header('ETag'))
-TestWithTemplateResponse = override_settings(
- CACHE_MIDDLEWARE_KEY_PREFIX='settingsprefix',
- CACHE_MIDDLEWARE_SECONDS=1,
- CACHES={
- 'default': {
- 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
- },
- },
- USE_I18N=False,
-)(TestWithTemplateResponse)
-
class TestEtagWithAdmin(TestCase):
# See https://code.djangoproject.com/ticket/16003