WAGTAILFRONTENDCACHE_LOCATION compatibility

pull/505/head
Karl Hobley 2014-10-08 10:45:13 +01:00
rodzic a343403c6a
commit 703ddbbb94
2 zmienionych plików z 31 dodań i 4 usunięć

Wyświetl plik

@ -1,22 +1,27 @@
from django.test import TestCase
from django.test import TestCase, override_settings
from wagtail.contrib.wagtailfrontendcache.utils import get_backends
from wagtail.contrib.wagtailfrontendcache.backends import HTTPBackend, CloudflareBackend
class TestBackendConfiguration(TestCase):
def test_default(self):
backends = get_backends()
self.assertEqual(len(backends), 0)
def test_varnish(self):
backends = get_backends(backend_settings={
'varnish': {
'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.HTTPBackend',
'LOCATION': 'http://localhost:8000/',
'LOCATION': 'http://localhost:8000',
},
})
self.assertEqual(len(backends), 1)
self.assertIsInstance(backends[0], HTTPBackend)
self.assertEqual(backends[0].cache_location, 'http://localhost:8000/')
self.assertEqual(backends[0].cache_location, 'http://localhost:8000')
def test_cloudflare(self):
backends = get_backends(backend_settings={
@ -33,7 +38,7 @@ class TestBackendConfiguration(TestCase):
self.assertEqual(backends[0].cloudflare_email, 'test@test.com')
self.assertEqual(backends[0].cloudflare_token, 'this is the token')
def test_both(self):
def test_multiple(self):
backends = get_backends(backend_settings={
'varnish': {
'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.HTTPBackend',
@ -63,3 +68,11 @@ class TestBackendConfiguration(TestCase):
self.assertEqual(len(backends), 1)
self.assertIsInstance(backends[0], CloudflareBackend)
@override_settings(WAGTAILFRONTENDCACHE_LOCATION='http://localhost:8000')
def test_backwards_compatibility(self):
backends = get_backends()
self.assertEqual(len(backends), 1)
self.assertIsInstance(backends[0], HTTPBackend)
self.assertEqual(backends[0].cache_location, 'http://localhost:8000')

Wyświetl plik

@ -45,9 +45,23 @@ def import_string(dotted_path):
def get_backends(backend_settings=None, backends=None):
# Get backend settings from WAGTAILFRONTENDCACHE setting
if backend_settings is None:
backend_settings = getattr(settings, 'WAGTAILFRONTENDCACHE', None)
# Fallback to using WAGTAILFRONTENDCACHE_LOCATION setting (backwards compatibility)
if backend_settings is None:
cache_location = getattr(settings, 'WAGTAILFRONTENDCACHE_LOCATION', None)
if cache_location is not None:
backend_settings = {
'default': {
'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.HTTPBackend',
'LOCATION': cache_location,
},
}
# No settings found, return empty list
if backend_settings is None:
return []