Anonymous committed 4e034db

added a test for configure_from_config

Comments (0)

Files changed (3)


                     (key[prefix_len:], config_dict[key]) 
                     for key in config_dict 
-                    if key.startwith(prefix)
+                    if key.startswith(prefix)


         return self.configure(
-            config_dict["%s.backend" % prefix],
+            config_dict["%sbackend" % prefix],
             expiration_time = config_dict.get(
-                                "%s.expiration_time" % prefix, None),
+                                "%sexpiration_time" % prefix, None),
-            _config_prefix="%s.arguments" % prefix
+            _config_prefix="%sarguments." % prefix


 from unittest import TestCase
 from dogpile.cache.api import CacheBackend, CachedValue, NO_VALUE
-from dogpile.cache import register_backend, CacheRegion
+from dogpile.cache import make_region, register_backend, CacheRegion
 from tests import eq_, assert_raises_message
 import time
 import itertools
         reg.configure(backend, **config_args)
         return reg
+    def test_instance_from_dict(self):
+        my_conf = { 
+            'cache.example.backend': 'mock',
+            'cache.example.expiration_time': 600,
+            'cache.example.arguments.url': ''
+            } 
+        my_region = make_region()
+        my_region.configure_from_config(my_conf, 'cache.example.')
+        eq_(my_region.expiration_time, 600)
+        assert isinstance(my_region.backend, MockBackend) is True
+        eq_(my_region.backend.arguments, {'url': ''})
     def test_key_mangler_argument(self):
         reg = self._region(init_args={"key_mangler":key_mangler})
         assert reg.key_mangler is key_mangler
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.