def test_overriding_with_allowed_urls(self): self.middleware = EscapedFragmentMiddleware() self.request.GET = {"_escaped_fragment_": None} # In the white list, not in black list -> "Test" self.request.path = '/bar/' self.assertEqual(self.middleware.process_request(self.request).content, "Test") # In the white list and black list -> None self.request.path = '/bar/1234/' self.assertEqual(self.middleware.process_request(self.request), None) self.request.path = '/bar/foo/5678/' self.assertEqual(self.middleware.process_request(self.request).content, "Test") self.request.path = '/test/abc/1234/' self.assertEqual(self.middleware.process_request(self.request).content, "Test") self.request.path = '/test/ab/1234/' self.assertEqual(self.middleware.process_request(self.request), None) self.request.path = '/foo/' self.assertEqual(self.middleware.process_request(self.request).content, "Test") self.request.path = '/foo/1234/' self.assertEqual(self.middleware.process_request(self.request), None)
def test_overriding_skips_custom_overrides_gifs_by_default(self): self.middleware = EscapedFragmentMiddleware() self.request.path = "/foo.gif" self.request.GET = {"_escaped_fragment_": None} self.assertEqual(self.middleware.process_request(self.request).content, b"Test") self.request.path = "/foo.html" self.assertEqual(self.middleware.process_request(self.request), None) self.request.path = "/bar/ibbity.txt" self.assertEqual(self.middleware.process_request(self.request), None)
def test_overriding_skips_gifs_by_default(self): self.middleware = EscapedFragmentMiddleware() self.request.path = "/sitemap.xml" self.request.GET = {"_escaped_fragment_": None} self.assertEqual(self.middleware.process_request(self.request), None)
def test_has_escaped_fragment_skips_if_service_is_down(self): self.middleware = EscapedFragmentMiddleware() self.request.GET = {"_escaped_fragment_": None} self.assertEqual(self.middleware.process_request(self.request), None)
def test_has_escaped_fragment_skips_if_disabled_via_enabled(self): self.middleware = EscapedFragmentMiddleware() self.request.GET = {} self.assertEqual(self.middleware.process_request(self.request), None)
def setUp(self): super(EscapedFragmentMiddlewareTest, self).setUp() self.middleware = EscapedFragmentMiddleware() self.request = Mock() self.request.path = "/" self.request.GET = {}
class EscapedFragmentMiddlewareTest(TestCase): @override_settings(BACKEND='django_seo_js.backends.TestBackend') def setUp(self): super(EscapedFragmentMiddlewareTest, self).setUp() self.middleware = EscapedFragmentMiddleware() self.request = Mock() self.request.path = "/" self.request.GET = {} def test_has_escaped_fragment(self): self.request.GET = {"_escaped_fragment_": None} self.assertEqual(self.middleware.process_request(self.request).content, b"Test") def test_does_not_have_escaped_fragment(self): self.request.GET = {} self.assertEqual(self.middleware.process_request(self.request), None) @override_settings(BACKEND='django_seo_js.backends.TestBackend', ENABLED=False) def test_has_escaped_fragment_skips_if_disabled_via_enabled(self): self.middleware = EscapedFragmentMiddleware() self.request.GET = {} self.assertEqual(self.middleware.process_request(self.request), None) @override_settings(BACKEND='django_seo_js.backends.TestServiceDownBackend') def test_has_escaped_fragment_skips_if_service_is_down(self): self.middleware = EscapedFragmentMiddleware() self.request.GET = {"_escaped_fragment_": None} self.assertEqual(self.middleware.process_request(self.request), None) @override_settings(BACKEND='django_seo_js.backends.TestBackend') def test_overriding_skips_sitemap_xml_by_default(self): self.middleware = EscapedFragmentMiddleware() self.request.path = "/sitemap.xml" self.request.GET = {"_escaped_fragment_": None} self.assertEqual(self.middleware.process_request(self.request), None) @override_settings( BACKEND='django_seo_js.backends.TestBackend', IGNORE_URLS=["/foo.html", "/bar/ibbity.html", ], IGNORE_EXTENSIONS=[], ) def test_overriding_skips_custom_overrides_xml_by_default(self): self.middleware = EscapedFragmentMiddleware() self.request.path = "/sitemap.xml" self.request.GET = {"_escaped_fragment_": None} self.assertEqual(self.middleware.process_request(self.request).content, b"Test") self.request.path = "/foo.html" self.assertEqual(self.middleware.process_request(self.request), None) self.request.path = "/bar/ibbity.html" self.assertEqual(self.middleware.process_request(self.request), None) @override_settings(BACKEND='django_seo_js.backends.TestBackend') def test_overriding_skips_gifs_by_default(self): self.middleware = EscapedFragmentMiddleware() self.request.path = "/sitemap.xml" self.request.GET = {"_escaped_fragment_": None} self.assertEqual(self.middleware.process_request(self.request), None) @override_settings( BACKEND='django_seo_js.backends.TestBackend', IGNORE_EXTENSIONS=[".html", ".txt", ] ) def test_overriding_skips_custom_overrides_gifs_by_default(self): self.middleware = EscapedFragmentMiddleware() self.request.path = "/foo.gif" self.request.GET = {"_escaped_fragment_": None} self.assertEqual(self.middleware.process_request(self.request).content, b"Test") self.request.path = "/foo.html" self.assertEqual(self.middleware.process_request(self.request), None) self.request.path = "/bar/ibbity.txt" self.assertEqual(self.middleware.process_request(self.request), None)
class EscapedFragmentMiddlewareTest(TestCase): @override_settings(BACKEND='django_seo_js.backends.TestBackend') def setUp(self): super(EscapedFragmentMiddlewareTest, self).setUp() self.middleware = EscapedFragmentMiddleware() self.request = Mock() self.request.path = "/" self.request.GET = {} def test_has_escaped_fragment(self): self.request.GET = {"_escaped_fragment_": None} self.assertEqual(self.middleware.process_request(self.request).content, "Test") def test_does_not_have_escaped_fragment(self): self.request.GET = {} self.assertEqual(self.middleware.process_request(self.request), None) @override_settings(BACKEND='django_seo_js.backends.TestBackend', ENABLED=False) def test_has_escaped_fragment_skips_if_disabled_via_enabled(self): self.middleware = EscapedFragmentMiddleware() self.request.GET = {} self.assertEqual(self.middleware.process_request(self.request), None) @override_settings(BACKEND='django_seo_js.backends.TestServiceDownBackend') def test_has_escaped_fragment_skips_if_service_is_down(self): self.middleware = EscapedFragmentMiddleware() self.request.GET = {"_escaped_fragment_": None} self.assertEqual(self.middleware.process_request(self.request), None) @override_settings(BACKEND='django_seo_js.backends.TestBackend') def test_overriding_skips_sitemap_xml_by_default(self): self.middleware = EscapedFragmentMiddleware() self.request.path = "/sitemap.xml" self.request.GET = {"_escaped_fragment_": None} self.assertEqual(self.middleware.process_request(self.request), None) @override_settings( BACKEND='django_seo_js.backends.TestBackend', IGNORE_URLS=["/foo.html", "/bar/ibbity.html", ], IGNORE_EXTENSIONS=[], ) def test_overriding_skips_custom_overrides_xml_by_default(self): self.middleware = EscapedFragmentMiddleware() self.request.path = "/sitemap.xml" self.request.GET = {"_escaped_fragment_": None} self.assertEqual(self.middleware.process_request(self.request).content, "Test") self.request.path = "/foo.html" self.assertEqual(self.middleware.process_request(self.request), None) self.request.path = "/bar/ibbity.html" self.assertEqual(self.middleware.process_request(self.request), None) @override_settings(BACKEND='django_seo_js.backends.TestBackend') def test_overriding_skips_gifs_by_default(self): self.middleware = EscapedFragmentMiddleware() self.request.path = "/sitemap.xml" self.request.GET = {"_escaped_fragment_": None} self.assertEqual(self.middleware.process_request(self.request), None) @override_settings( BACKEND='django_seo_js.backends.TestBackend', IGNORE_EXTENSIONS=[".html", ".txt", ] ) def test_overriding_skips_custom_overrides_gifs_by_default(self): self.middleware = EscapedFragmentMiddleware() self.request.path = "/foo.gif" self.request.GET = {"_escaped_fragment_": None} self.assertEqual(self.middleware.process_request(self.request).content, "Test") self.request.path = "/foo.html" self.assertEqual(self.middleware.process_request(self.request), None) self.request.path = "/bar/ibbity.txt" self.assertEqual(self.middleware.process_request(self.request), None) @override_settings( BACKEND='django_seo_js.backends.TestBackend', ALLOWED_URLS=['/bar/*', '/test/abc/*', '/foo/'], IGNORE_URLS=['/bar/1234/'], IGNORE_EXTENSIONS=[], ) def test_overriding_with_allowed_urls(self): self.middleware = EscapedFragmentMiddleware() self.request.GET = {"_escaped_fragment_": None} # In the white list, not in black list -> "Test" self.request.path = '/bar/' self.assertEqual(self.middleware.process_request(self.request).content, "Test") # In the white list and black list -> None self.request.path = '/bar/1234/' self.assertEqual(self.middleware.process_request(self.request), None) self.request.path = '/bar/foo/5678/' self.assertEqual(self.middleware.process_request(self.request).content, "Test") self.request.path = '/test/abc/1234/' self.assertEqual(self.middleware.process_request(self.request).content, "Test") self.request.path = '/test/ab/1234/' self.assertEqual(self.middleware.process_request(self.request), None) self.request.path = '/foo/' self.assertEqual(self.middleware.process_request(self.request).content, "Test") self.request.path = '/foo/1234/' self.assertEqual(self.middleware.process_request(self.request), None)
def test_update_the_render_cache(self): from django_seo_js.helpers import update_cache_for_url self.middleware = EscapedFragmentMiddleware() self.assertEqual(update_cache_for_url("http://example.com"), True)
def test_update_skips_if_disabled(self): from django_seo_js.helpers import update_cache_for_url self.middleware = EscapedFragmentMiddleware() self.assertEqual(update_cache_for_url("http://example.com"), False)