Ticket #15704: cache-tests-backend-name.patch

File cache-tests-backend-name.patch, 8.7 KB (added by Jonas H., 14 years ago)
  • tests/regressiontests/cache/tests.py

    diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py
    index 2f46c0b..c5349d5 100644
    a b class C:  
    3434class DummyCacheTests(unittest.TestCase):
    3535    # The Dummy cache backend doesn't really behave like a test backend,
    3636    # so it has different test requirements.
     37    backend_name = 'django.core.cache.backends.dummy.DummyCache'
     38
    3739    def setUp(self):
    38         self.cache = get_cache('django.core.cache.backends.dummy.DummyCache')
     40        self.cache = get_cache(self.backend_name)
    3941
    4042    def test_simple(self):
    4143        "Dummy cache backend ignores cache set calls"
    def custom_key_func(key, key_prefix, version):  
    727729    return 'CUSTOM-' + '-'.join([key_prefix, str(version), key])
    728730
    729731class DBCacheTests(unittest.TestCase, BaseCacheTests):
     732    backend_name = 'django.core.cache.backends.db.DatabaseCache'
     733
    730734    def setUp(self):
    731735        # Spaces are used in the table name to ensure quoting/escaping is working
    732736        self._table_name = 'test cache table'
    733737        management.call_command('createcachetable', self._table_name, verbosity=0, interactive=False)
    734         self.cache = get_cache('django.core.cache.backends.db.DatabaseCache', LOCATION=self._table_name, OPTIONS={'MAX_ENTRIES': 30})
    735         self.prefix_cache = get_cache('django.core.cache.backends.db.DatabaseCache', LOCATION=self._table_name, KEY_PREFIX='cacheprefix')
    736         self.v2_cache = get_cache('django.core.cache.backends.db.DatabaseCache', LOCATION=self._table_name, VERSION=2)
    737         self.custom_key_cache = get_cache('django.core.cache.backends.db.DatabaseCache', LOCATION=self._table_name, KEY_FUNCTION=custom_key_func)
    738         self.custom_key_cache2 = get_cache('django.core.cache.backends.db.DatabaseCache', LOCATION=self._table_name, KEY_FUNCTION='regressiontests.cache.tests.custom_key_func')
     738        self.cache = get_cache(self.backend_name, LOCATION=self._table_name, OPTIONS={'MAX_ENTRIES': 30})
     739        self.prefix_cache = get_cache(self.backend_name, LOCATION=self._table_name, KEY_PREFIX='cacheprefix')
     740        self.v2_cache = get_cache(self.backend_name, LOCATION=self._table_name, VERSION=2)
     741        self.custom_key_cache = get_cache(self.backend_name, LOCATION=self._table_name, KEY_FUNCTION=custom_key_func)
     742        self.custom_key_cache2 = get_cache(self.backend_name, LOCATION=self._table_name, KEY_FUNCTION='regressiontests.cache.tests.custom_key_func')
    739743
    740744    def tearDown(self):
    741745        from django.db import connection
    class DBCacheTests(unittest.TestCase, BaseCacheTests):  
    746750        self.perform_cull_test(50, 29)
    747751
    748752    def test_zero_cull(self):
    749         self.cache = get_cache('django.core.cache.backends.db.DatabaseCache', LOCATION=self._table_name, OPTIONS={'MAX_ENTRIES': 30, 'CULL_FREQUENCY': 0})
     753        self.cache = get_cache(self.backend_name, LOCATION=self._table_name, OPTIONS={'MAX_ENTRIES': 30, 'CULL_FREQUENCY': 0})
    750754        self.perform_cull_test(50, 18)
    751755
    752756    def test_old_initialization(self):
    class DBCacheTests(unittest.TestCase, BaseCacheTests):  
    754758        self.perform_cull_test(50, 18)
    755759
    756760class LocMemCacheTests(unittest.TestCase, BaseCacheTests):
     761    backend_name = 'django.core.cache.backends.locmem.LocMemCache'
     762
    757763    def setUp(self):
    758         self.cache = get_cache('django.core.cache.backends.locmem.LocMemCache', OPTIONS={'MAX_ENTRIES': 30})
    759         self.prefix_cache = get_cache('django.core.cache.backends.locmem.LocMemCache', KEY_PREFIX='cacheprefix')
    760         self.v2_cache = get_cache('django.core.cache.backends.locmem.LocMemCache', VERSION=2)
    761         self.custom_key_cache = get_cache('django.core.cache.backends.locmem.LocMemCache', OPTIONS={'MAX_ENTRIES': 30}, KEY_FUNCTION=custom_key_func)
    762         self.custom_key_cache2 = get_cache('django.core.cache.backends.locmem.LocMemCache', OPTIONS={'MAX_ENTRIES': 30}, KEY_FUNCTION='regressiontests.cache.tests.custom_key_func')
     764        self.cache = get_cache(self.backend_name, OPTIONS={'MAX_ENTRIES': 30})
     765        self.prefix_cache = get_cache(self.backend_name, KEY_PREFIX='cacheprefix')
     766        self.v2_cache = get_cache(self.backend_name, VERSION=2)
     767        self.custom_key_cache = get_cache(self.backend_name, OPTIONS={'MAX_ENTRIES': 30}, KEY_FUNCTION=custom_key_func)
     768        self.custom_key_cache2 = get_cache(self.backend_name, OPTIONS={'MAX_ENTRIES': 30}, KEY_FUNCTION='regressiontests.cache.tests.custom_key_func')
    763769
    764770        # LocMem requires a hack to make the other caches
    765771        # share a data store with the 'normal' cache.
    class LocMemCacheTests(unittest.TestCase, BaseCacheTests):  
    782788        self.perform_cull_test(50, 29)
    783789
    784790    def test_zero_cull(self):
    785         self.cache = get_cache('django.core.cache.backends.locmem.LocMemCache', OPTIONS={'MAX_ENTRIES': 30, 'CULL_FREQUENCY': 0})
     791        self.cache = get_cache(self.backend_name, OPTIONS={'MAX_ENTRIES': 30, 'CULL_FREQUENCY': 0})
    786792        self.perform_cull_test(50, 19)
    787793
    788794    def test_old_initialization(self):
    class LocMemCacheTests(unittest.TestCase, BaseCacheTests):  
    791797
    792798    def test_multiple_caches(self):
    793799        "Check that multiple locmem caches are isolated"
    794         mirror_cache = get_cache('django.core.cache.backends.locmem.LocMemCache')
    795         other_cache = get_cache('django.core.cache.backends.locmem.LocMemCache', LOCATION='other')
     800        mirror_cache = get_cache(self.backend_name)
     801        other_cache = get_cache(self.backend_name, LOCATION='other')
    796802
    797803        self.cache.set('value1', 42)
    798804        self.assertEqual(mirror_cache.get('value1'), 42)
    class LocMemCacheTests(unittest.TestCase, BaseCacheTests):  
    803809# need to contain a cache backend setting that points at
    804810# your memcache server.
    805811class MemcachedCacheTests(unittest.TestCase, BaseCacheTests):
     812    backend_name = 'django.core.cache.backends.memcached.MemcachedCache'
     813
    806814    def setUp(self):
    807815        name = settings.CACHES[DEFAULT_CACHE_ALIAS]['LOCATION']
    808         self.cache = get_cache('django.core.cache.backends.memcached.MemcachedCache', LOCATION=name)
    809         self.prefix_cache = get_cache('django.core.cache.backends.memcached.MemcachedCache', LOCATION=name, KEY_PREFIX='cacheprefix')
    810         self.v2_cache = get_cache('django.core.cache.backends.memcached.MemcachedCache', LOCATION=name, VERSION=2)
    811         self.custom_key_cache = get_cache('django.core.cache.backends.memcached.MemcachedCache', LOCATION=name, KEY_FUNCTION=custom_key_func)
    812         self.custom_key_cache2 = get_cache('django.core.cache.backends.memcached.MemcachedCache', LOCATION=name, KEY_FUNCTION='regressiontests.cache.tests.custom_key_func')
     816        self.cache = get_cache(self.backend_name, LOCATION=name)
     817        self.prefix_cache = get_cache(self.backend_name, LOCATION=name, KEY_PREFIX='cacheprefix')
     818        self.v2_cache = get_cache(self.backend_name, LOCATION=name, VERSION=2)
     819        self.custom_key_cache = get_cache(self.backend_name, LOCATION=name, KEY_FUNCTION=custom_key_func)
     820        self.custom_key_cache2 = get_cache(self.backend_name, LOCATION=name, KEY_FUNCTION='regressiontests.cache.tests.custom_key_func')
    813821
    814822    def tearDown(self):
    815823        self.cache.clear()
    class FileBasedCacheTests(unittest.TestCase, BaseCacheTests):  
    835843    """
    836844    Specific test cases for the file-based cache.
    837845    """
     846    backend_name = 'django.core.cache.backends.filebased.FileBasedCache'
     847
    838848    def setUp(self):
    839849        self.dirname = tempfile.mkdtemp()
    840         self.cache = get_cache('django.core.cache.backends.filebased.FileBasedCache', LOCATION=self.dirname, OPTIONS={'MAX_ENTRIES': 30})
    841         self.prefix_cache = get_cache('django.core.cache.backends.filebased.FileBasedCache', LOCATION=self.dirname, KEY_PREFIX='cacheprefix')
    842         self.v2_cache = get_cache('django.core.cache.backends.filebased.FileBasedCache', LOCATION=self.dirname, VERSION=2)
    843         self.custom_key_cache = get_cache('django.core.cache.backends.filebased.FileBasedCache', LOCATION=self.dirname, KEY_FUNCTION=custom_key_func)
    844         self.custom_key_cache2 = get_cache('django.core.cache.backends.filebased.FileBasedCache', LOCATION=self.dirname, KEY_FUNCTION='regressiontests.cache.tests.custom_key_func')
     850        self.cache = get_cache(self.backend_name, LOCATION=self.dirname, OPTIONS={'MAX_ENTRIES': 30})
     851        self.prefix_cache = get_cache(self.backend_name, LOCATION=self.dirname, KEY_PREFIX='cacheprefix')
     852        self.v2_cache = get_cache(self.backend_name, LOCATION=self.dirname, VERSION=2)
     853        self.custom_key_cache = get_cache(self.backend_name, LOCATION=self.dirname, KEY_FUNCTION=custom_key_func)
     854        self.custom_key_cache2 = get_cache(self.backend_name, LOCATION=self.dirname, KEY_FUNCTION='regressiontests.cache.tests.custom_key_func')
    845855
    846856    def tearDown(self):
    847857        self.cache.clear()
Back to Top