def test_parse_dummy_url(self):
     self.assertEqual(
         django_cache_url("dummy://"),
         {
             "BACKEND": "django.core.cache.backends.dummy.DummyCache",
         },
     )
 def test_parse_location_locmem_url(self):
     self.assertEqual(
         django_cache_url("locmem://snowflake?key_prefix=stuff"),
         {
             "BACKEND": "django.core.cache.backends.locmem.LocMemCache",
             "LOCATION": "snowflake",
             "KEY_PREFIX": "stuff",
         },
     )
 def test_parse_locmem_url(self):
     self.assertEqual(
         django_cache_url("locmem://"),
         {
             "BACKEND": "django.core.cache.backends.locmem.LocMemCache",
             "LOCATION": "",
             "KEY_PREFIX": "",
         },
     )
Example #4
0
def patch_django_cache_url():
    if "django_cache_url" in sys.modules:
        return

    m = ModuleType("django_cache_url")
    m.config = lambda name="CACHE_URL": django_cache_url(
        env(name, default="locmem://", warn=True))
    m.parse = django_cache_url
    sys.modules["django_cache_url"] = m
 def test_parse_no_db_cache_url(self):
     url = "redis://127.0.0.1:6379/?key_prefix=example_com"
     self.assertEqual(
         django_cache_url(url),
         {
             "BACKEND": "django.core.cache.backends.redis.RedisCache",
             "LOCATION": "redis://127.0.0.1:6379",
             "KEY_PREFIX": "example_com",
             "OPTIONS": {},
         },
     )
 def test_parse_cache_url(self):
     url = "hiredis://localhost:6379/1/?key_prefix=example_com"
     self.assertEqual(
         django_cache_url(url),
         {
             "BACKEND": "django.core.cache.backends.redis.RedisCache",
             "LOCATION": "redis://localhost:6379",
             "KEY_PREFIX": "example_com",
             "OPTIONS": {
                 "db": "1"
             },
         },
     )
 def test_parse_unknown(self):
     with self.assertRaises(KeyError):
         django_cache_url("unknown://")