Show
Ignore:
Timestamp:
03/28/08 08:51:04 (8 months ago)
Author:
JensDiemer
Message:

Updating the cache middleware:

  • Splitting pagestats from cache is a good idea, after all ;)
  • add a debug information in the response
  • verify the shortcut from the url
  • update unittests
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pylucid/tests/cache.py

    r1510 r1511  
    135135            must_not_contain=("Traceback",) 
    136136        ) 
    137  
    138         from_cache = response.get("from_cache", None) 
    139         self.failUnlessEqual(from_cache, None, msg) 
     137        self.failUnlessEqual(response["from_cache"], "no", msg) 
    140138 
    141139    def failIfNotFromCache(self, response, msg=None): 
     
    157155            raise AssertionError("Wrong url?") 
    158156 
    159         from_cache = response["from_cache"] 
    160         self.failUnlessEqual(from_cache, "yes", msg) 
     157        self.failUnlessEqual(response["from_cache"], "yes", msg) 
    161158 
    162159    #-------------------------------------------------------------------------- 
     
    314311        self._check_cache_after(test_func) 
    315312 
     313    #-------------------------------------------------------------------------- 
     314     
     315    def test_wrong_url(self): 
     316        """ 
     317        Test if the cache middleware checks bad characters in the url. 
     318        Normaly the urls-re doesn't match on bad urls. But the process_request 
     319        method of a middleware called before this. 
     320        """ 
     321        content = "Should never comes from the cache!" 
     322        shortcut = "bad$char&here" 
     323        url = "/%s/" % shortcut 
     324        cache_key = settings.PAGE_CACHE_PREFIX + shortcut 
     325         
     326        # Insert a cache entry, so the cache middleware can found the cached 
     327        # page and will be response the cached content, if the shortcut will 
     328        # not be veryfied. 
     329        response = HttpResponse(content) 
     330        cache.set(cache_key, response, 9999) 
     331         
     332        # Request the cached page and check the response. It should not resonse 
     333        # the cached content. It should be apperar a 404 page not found. 
     334        response = self.client.get(url) 
     335        #debug_response(response) 
     336        self.failUnlessEqual(response.status_code, 404) 
     337        self.assertResponse(response, must_not_contain=(content,)) 
     338 
    316339 
    317340if __name__ == "__main__":