Example #1
0
 def test_cloudfront_validate_distribution_id(self):
     with self.assertRaises(ImproperlyConfigured):
         get_backends(backend_settings={
             'cloudfront': {
                 'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.CloudfrontBackend',
             },
         })
Example #2
0
 def test_cloudfront_validate_distribution_id(self):
     with self.assertRaises(ImproperlyConfigured):
         get_backends(backend_settings={
             'cloudfront': {
                 'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.CloudfrontBackend',
             },
         })
Example #3
0
    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")
Example #4
0
    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')
Example #5
0
    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')
Example #6
0
    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')
Example #7
0
    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')
Example #8
0
    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')
Example #9
0
    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/'])
Example #10
0
    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')
Example #11
0
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)
Example #12
0
    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/')
Example #13
0
    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/")
Example #14
0
    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')
Example #15
0
    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']))
Example #16
0
    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")
Example #17
0
    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']))
Example #18
0
    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')
Example #19
0
    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")
Example #20
0
    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")
Example #21
0
    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"]))
Example #22
0
    def test_default(self):
        backends = get_backends()

        self.assertEqual(len(backends), 0)
Example #23
0
    def test_default(self):
        backends = get_backends()

        self.assertEqual(len(backends), 0)