Commits

Gael Pasgrimaud  committed 9d6e627

fix tests

  • Participants
  • Parent commits b491983

Comments (0)

Files changed (3)

File antistress/cache.py

     code to purge some cache values
     """
 
-    defaults = {'url': 'localhost:11211'}
+    defaults = {'url': '127.0.0.1:11211'}
 
     def __init__(self, app, paths=[], images_paths=[],
                        max_size=0, cache_qs=False, vary_cookies=[], debug=False,
         """Purge a request from cache. If the backend does not support keys
         matching then purge the whole cache
         """
+        log.debug('purge("%s-%s", **%s) <-', namespace, key, opts)
         cache = self.manager.get_cache(namespace, **opts)
         values = []
+        if key in cache:
+            del cache[key]
+            log.debug('purge("%s-%s", **%s) -> OK', namespace, key, opts)
+            values.append(key)
         try:
             keys = cache.namespace.keys()
         except Exception, e:
-            log.debug('purge("%s", **%s) -> OK', namespace, opts)
+            log.debug('purge("%s", **%s) -> %r', namespace, opts, e)
             cache.clear()
             values.append(namespace)
         else:
+            log.debug('purge("%s", **%s) keys %s', namespace, opts, keys)
             if keys:
                 path_info = req.path_info
                 for k in keys:
     paths = [deserialize_path(p.strip()) for p in paths.split('\n') if p.strip()]
     prefix = local_conf.get('images_prefix', '')
     if 'images_dir' in local_conf:
+        defaults = {'type': local_conf.get('images_type', 'file')}
         if 'images_paths' in local_conf:
             images_paths = local_conf.pop('images_paths')
         else:
             images_paths = DEFAULT_SIZES
-        images_paths = [deserialize_path(prefix+p.strip()) for p in images_paths.split('\n') if p.strip()]
+        images_paths = [deserialize_path(prefix+p.strip(), defaults) for p in images_paths.split('\n') if p.strip()]
     return CacheMiddleware(app, paths=paths, images_paths=images_paths, **local_conf)
 
 def make_image(global_conf, images_dir=None, **local_conf):

File antistress/tests.py

     resp2 = app.get('/cache')
     assert resp1.body != resp2.body, (resp1.body, resp2.body)
 
-@with_app(paths=['/cache expire:1'])
+@with_app(paths=['/cache expire:1'], type='memory')
 def test_cache_memory(app):
     _test_cache(app)
 
 def test_cache_memcached(app):
     _test_cache(app)
 
-@with_app()
+@with_app(type='memory')
 def test_purge_memory(app):
     for i in range(3):
         resp = app.get('/cache/%i' % i)
     resp = app.get('/cache/0')
     assert check.body != resp.body
 
-@with_app()
+@with_app(type='memory')
 def test_purge_http(app):
     for i in range(3):
         app.get('/cache/%i' % i)

File antistress/utils.py

     image.save(dst)
     return dst
 
-def deserialize_path(line):
+def deserialize_path(line, defaults={}):
     """Deserialize a path config value:
 
     .. sourcecode:: py
         path = (namespace, match, re.compile(path))
     else:
         path = (namespace, match, re.compile(fnmatch.translate(path)))
-    cache_opts = {}
+    cache_opts = defaults.copy()
     for v in values:
         k, v = v.split(':', 1)
         if k in ('expire', 'size'):
             if not v.isdigit():
-                raise ValueError('%s must be integer. got %s' % (k, line))
+                raise ValueError('%s must be integer. Got %s' % (k, line))
             v = int(v)
         if k in ('size',):
             v = (v, v)
         cache_opts[k] = v
-    if 'size' in cache_opts and 'type' not in cache_opts:
-        cache_opts['type'] = 'file'
     return [path, cache_opts]