add test for the frontend cache signal handler

pull/1218/head
Matt Westcott 2015-04-20 19:37:10 +01:00
rodzic 0e926e8399
commit e4f2d9e669
1 zmienionych plików z 36 dodań i 1 usunięć

Wyświetl plik

@ -1,8 +1,10 @@
from django.test import TestCase
from django.test.utils import override_settings
from wagtail.tests.testapp.models import EventIndex
from wagtail.contrib.wagtailfrontendcache.utils import get_backends
from wagtail.contrib.wagtailfrontendcache.backends import HTTPBackend, CloudflareBackend
from wagtail.contrib.wagtailfrontendcache.backends import HTTPBackend, CloudflareBackend, BaseBackend
class TestBackendConfiguration(TestCase):
@ -76,3 +78,36 @@ class TestBackendConfiguration(TestCase):
self.assertEqual(set(backends.keys()), set(['default']))
self.assertIsInstance(backends['default'], HTTPBackend)
self.assertEqual(backends['default'].cache_location, 'http://localhost:8000')
PURGED_URLS = []
class MockBackend(BaseBackend):
def __init__(self, config):
pass
def purge(self, url):
PURGED_URLS.append(url)
@override_settings(WAGTAILFRONTENDCACHE={
'varnish': {
'BACKEND': 'wagtail.contrib.wagtailfrontendcache.tests.MockBackend',
},
})
class TestCachePurging(TestCase):
fixtures = ['test.json']
def test_purge_on_publish(self):
PURGED_URLS[:] = [] # reset PURGED_URLS to the empty list
page = EventIndex.objects.get(url_path='/home/events/')
page.save_revision().publish()
self.assertEqual(PURGED_URLS, ['http://localhost/events/'])
def test_purge_on_unpublish(self):
PURGED_URLS[:] = [] # reset PURGED_URLS to the empty list
page = EventIndex.objects.get(url_path='/home/events/')
page.unpublish()
self.assertEqual(PURGED_URLS, ['http://localhost/events/'])