Show
Ignore:
Timestamp:
03/27/08 16:59:44 (8 months ago)
Author:
JensDiemer
Message:

add a experimental new cache middleware
-merge pagestats into cache middleware
-add unitest for the cache
-move setup_debug() from the views into the common middleware
-update other tests

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pylucid/PyLucid/install/tests.py

    r1302 r1510  
    44""" 
    55 
     6import os, cgi, sys, time 
     7 
     8from django.conf import settings 
     9 
     10from django import newforms as forms 
     11from django.core import management 
     12from django.core.cache import cache 
     13 
    614from PyLucid.install.BaseInstall import BaseInstall 
    715from PyLucid.system.response import SimpleStringIO 
    8  
    9 from django.core import management 
    10 from django import newforms as forms 
    11  
    12 import os, cgi, sys, time 
    1316 
    1417 
     
    2225        print txt 
    2326        print "-"*80 
     27 
     28    def _test_cache(self): 
     29        """ 
     30        Test the cache backend. 
     31        """ 
     32        if settings.CACHE_BACKEND.startswith("dummy"): 
     33            return 
     34        self._print_infoline( 
     35            "Test cache backend '%s':" % settings.CACHE_BACKEND 
     36        ) 
     37        cache_key = "cache test" 
     38        content = "A cache test content..." 
     39        cache_timeout = 50 
     40        print "Save into cache with key '%s'." % cache_key 
     41        cache.set(cache_key, content, cache_timeout) 
     42        print "Try to get the saved content from the cache." 
     43        cached_content = cache.get(cache_key) 
     44        if cached_content == None: 
     45            print " * Get None back. Cache didn't work!" 
     46            return 
     47        elif cached_content==content: 
     48            print " * Cache works fine ;)" 
     49        else: 
     50            # Should never appears 
     51            print " * Error! Cache content not the same!" 
     52 
     53        print "Try to delete the cache entry." 
     54        cache.delete(cache_key) 
     55        cached_content = cache.get(cache_key) 
     56        if cached_content == None: 
     57            print "OK, entry deleted." 
     58        else: 
     59            print "Error: entry not deleted!" 
     60 
    2461 
    2562    def _verbose_try_import(self, module_name): 
     
    109146 
    110147    def print_info(self): 
     148        self._test_cache() 
     149 
    111150        self._print_infoline("Tests for the memcache backend:") 
    112151        self._verbose_try_import("cmemcache")