def test_cloudfront_validate_distribution_id(self): with self.assertRaises(ImproperlyConfigured): get_backends(backend_settings={ 'cloudfront': { 'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.CloudfrontBackend', }, })
def test_backwards_compatibility(self): backends = get_backends() self.assertEqual(set(backends.keys()), set(["default"])) self.assertIsInstance(backends["default"], HTTPBackend) self.assertEqual(backends["default"].cache_scheme, "http") self.assertEqual(backends["default"].cache_netloc, "localhost:8000")
def test_backwards_compatibility(self): backends = get_backends() self.assertEqual(set(backends.keys()), set(['default'])) self.assertIsInstance(backends['default'], HTTPBackend) self.assertEqual(backends['default'].cache_scheme, 'http') self.assertEqual(backends['default'].cache_netloc, 'localhost:8000')
def test_cloudfront(self): backends = get_backends(backend_settings={ 'cloudfront': { 'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.CloudfrontBackend', 'DISTRIBUTION_ID': 'frontend', }, }) self.assertEqual(set(backends.keys()), set(['cloudfront'])) self.assertIsInstance(backends['cloudfront'], CloudfrontBackend) self.assertEqual(backends['cloudfront'].cloudfront_distribution_id, 'frontend')
def test_varnish(self): backends = get_backends(backend_settings={ 'varnish': { 'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.HTTPBackend', 'LOCATION': 'http://localhost:8000', }, }) self.assertEqual(set(backends.keys()), set(['varnish'])) self.assertIsInstance(backends['varnish'], HTTPBackend) self.assertEqual(backends['varnish'].cache_location, 'http://localhost:8000')
def test_cloudfront_distribution_id_mapping(self, _create_invalidation): backends = get_backends(backend_settings={ 'cloudfront': { 'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.CloudfrontBackend', 'DISTRIBUTION_ID': { 'www.wagtail.io': 'frontend', } }, }) backends.get('cloudfront').purge('http://www.wagtail.io/home/events/christmas/') backends.get('cloudfront').purge('http://torchbox.com/blog/') _create_invalidation.assert_called_once_with('frontend', ['/home/events/christmas/'])
def test_varnish(self): backends = get_backends(backend_settings={ 'varnish': { 'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.HTTPBackend', 'LOCATION': 'http://localhost:8000', }, }) self.assertEqual(set(backends.keys()), set(['varnish'])) self.assertIsInstance(backends['varnish'], HTTPBackend) self.assertEqual(backends['varnish'].cache_scheme, 'http') self.assertEqual(backends['varnish'].cache_netloc, 'localhost:8000')
def purge_all_from_cache(backend_settings=None, backends=None): """Utility method to purge all from cache, based on wagtail.contrib.wagtailfrontendcache.utils""" for backend_name, backend in get_backends( backend_settings=backend_settings, backends=backends).items(): """Check that backend has purge_all implemented""" try: logger.info("[%s] Purging All", backend_name) backend.purge_all() except AttributeError: logger.error("[%s] Backend does not support purge_all.", backend_name)
def test_cloudfront_distribution_id_mapping(self, _create_invalidation): backends = get_backends(backend_settings={ 'cloudfront': { 'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.CloudfrontBackend', 'DISTRIBUTION_ID': { 'www.wagtail.io': 'frontend', } }, }) backends.get('cloudfront').purge('http://www.wagtail.io/home/events/christmas/') backends.get('cloudfront').purge('http://torchbox.com/blog/') _create_invalidation.assert_called_once_with('frontend', '/home/events/christmas/')
def test_cloudfront_distribution_id_mapping(self, _create_invalidation): backends = get_backends( backend_settings={ "cloudfront": { "BACKEND": "wagtail.contrib.wagtailfrontendcache.backends.CloudfrontBackend", "DISTRIBUTION_ID": {"www.wagtail.io": "frontend"}, } } ) backends.get("cloudfront").purge("http://www.wagtail.io/home/events/christmas/") backends.get("cloudfront").purge("http://torchbox.com/blog/") _create_invalidation.assert_called_once_with("frontend", "/home/events/christmas/")
def test_cloudflare(self): backends = get_backends(backend_settings={ 'cloudflare': { 'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.CloudflareBackend', 'EMAIL': '*****@*****.**', 'TOKEN': 'this is the token', }, }) self.assertEqual(set(backends.keys()), set(['cloudflare'])) self.assertIsInstance(backends['cloudflare'], CloudflareBackend) self.assertEqual(backends['cloudflare'].cloudflare_email, '*****@*****.**') self.assertEqual(backends['cloudflare'].cloudflare_token, 'this is the token')
def test_filter(self): backends = get_backends(backend_settings={ 'varnish': { 'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.HTTPBackend', 'LOCATION': 'http://*****:*****@test.com', 'TOKEN': 'this is the token', } }, backends=['cloudflare']) self.assertEqual(set(backends.keys()), set(['cloudflare']))
def test_cloudfront(self): backends = get_backends( backend_settings={ "cloudfront": { "BACKEND": "wagtail.contrib.wagtailfrontendcache.backends.CloudfrontBackend", "DISTRIBUTION_ID": "frontend", } } ) self.assertEqual(set(backends.keys()), set(["cloudfront"])) self.assertIsInstance(backends["cloudfront"], CloudfrontBackend) self.assertEqual(backends["cloudfront"].cloudfront_distribution_id, "frontend")
def test_multiple(self): backends = get_backends(backend_settings={ 'varnish': { 'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.HTTPBackend', 'LOCATION': 'http://*****:*****@test.com', 'TOKEN': 'this is the token', } }) self.assertEqual(set(backends.keys()), set(['varnish', 'cloudflare']))
def test_varnish(self): backends = get_backends( backend_settings={ "varnish": { "BACKEND": "wagtail.contrib.wagtailfrontendcache.backends.HTTPBackend", "LOCATION": "http://localhost:8000", } } ) self.assertEqual(set(backends.keys()), set(["varnish"])) self.assertIsInstance(backends["varnish"], HTTPBackend) self.assertEqual(backends["varnish"].cache_scheme, "http") self.assertEqual(backends["varnish"].cache_netloc, "localhost:8000")
def test_cloudflare(self): backends = get_backends( backend_settings={ "cloudflare": { "BACKEND": "wagtail.contrib.wagtailfrontendcache.backends.CloudflareBackend", "EMAIL": "*****@*****.**", "TOKEN": "this is the token", } } ) self.assertEqual(set(backends.keys()), set(["cloudflare"])) self.assertIsInstance(backends["cloudflare"], CloudflareBackend) self.assertEqual(backends["cloudflare"].cloudflare_email, "*****@*****.**") self.assertEqual(backends["cloudflare"].cloudflare_token, "this is the token")
def test_multiple(self): backends = get_backends( backend_settings={ "varnish": { "BACKEND": "wagtail.contrib.wagtailfrontendcache.backends.HTTPBackend", "LOCATION": "http://*****:*****@test.com", "TOKEN": "this is the token", }, } ) self.assertEqual(set(backends.keys()), set(["varnish", "cloudflare"]))
def test_default(self): backends = get_backends() self.assertEqual(len(backends), 0)