Exemple #1
0
    def test_cache_installed(self):

        test_contexts = [
            (False,
             ['mezzanine.core.middleware.FetchFromCacheMiddleware']),
            (True,
             ['mezzanine.core.middleware.UpdateCacheMiddleware',
              'mezzanine.core.tests.SubclassMiddleware']),
            (True,
             ['mezzanine.core.middleware.UpdateCacheMiddleware',
              'mezzanine.core.tests.FetchFromCacheMiddleware',
              'mezzanine.core.tests.function_middleware']),
            (True,
             ['mezzanine.core.middleware.UpdateCacheMiddleware',
              'mezzanine.core.middleware.FetchFromCacheMiddleware']),
        ]

        with self.settings(TESTING=False):  # Well, this is silly
            for expected_result, middlewares in test_contexts:
                kwargs = {get_middleware_setting_name(): middlewares}
                with self.settings(**kwargs):
                    cache_installed.cache_clear()
                    self.assertEqual(cache_installed(), expected_result)

        cache_installed.cache_clear()
Exemple #2
0
    def test_csrf_cookie_with_nevercache(self):
        """
        Test that the CSRF cookie is properly set when using nevercache.
        """

        # Clear the cached value for cache_installed and initialize nevercache
        cache_installed.cache_clear()
        initialize_nevercache()

        # Test uses an authenticated user as the middleware behavior differs
        self.client.login(username=self._username, password=self._password)
        response = self.client.get("/nevercache_view/")

        # CSRF token is expected to be rendered
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "csrfmiddlewaretoken")

        # The CSRF cookie should be present
        csrf_cookie = response.cookies.get(settings.CSRF_COOKIE_NAME, False)
        self.assertNotEqual(csrf_cookie, False)
Exemple #3
0
    def test_cache_installed(self):

        test_contexts = [
            (False,
             ['mezzanine.core.middleware.FetchFromCacheMiddleware']),
            (True,
             ['mezzanine.core.middleware.UpdateCacheMiddleware',
              'mezzanine.core.tests.SubclassMiddleware']),
            (True,
             ['mezzanine.core.middleware.UpdateCacheMiddleware',
              'mezzanine.core.middleware.FetchFromCacheMiddleware']),
        ]

        with self.settings(TESTING=False):  # Well, this is silly
            for expected_result, middleware_classes in test_contexts:
                with self.settings(MIDDLEWARE_CLASSES=middleware_classes):
                    cache_installed.cache_clear()
                    self.assertEqual(cache_installed(), expected_result)

        cache_installed.cache_clear()
Exemple #4
0
 def tearDownClass(cls):
     # Initialize nevercache again now that @override_settings is finished
     cache_installed.cache_clear()
     initialize_nevercache()