#33798 closed Uncategorized (invalid)

@cache_control test fails after upgrade to 4.0.5

Reported by: Matt Hegarty Owned by: nobody
Component: Uncategorized Version: 4.0
Severity: Normal Keywords: cache_control decorator
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


This worked ok in 3.2.13 - fails after upgrade to 4.0.5


class FaviconTests(SimpleTestCase):
    def test_get(self):
        response = self.client.get("/favicon.ico")
        self.assertEqual(response.status_code, HTTPStatus.OK)
        self.assertEqual(response["Cache-Control"], "max-age=86400, immutable, public")
        self.assertEqual(response["Content-Type"], "image/png")
        content = b"".join(response.streaming_content)
        self.assertGreater(len(content), 0)


from django.conf import settings
from django.http import FileResponse
from django.views.decorators.cache import cache_control
from django.views.generic.base import View

class FaviconView(View):
    @cache_control(max_age=60 * 60 * 24, immutable=True, public=True)
    def get(self, request, *args, **kwargs):
        file = (
            settings.BASE_DIR / settings.STATIC_ROOT / "img" / "favicon-32x32.png"
        return FileResponse(file)


TypeError: cache_control didn't receive an HttpRequest. If you are decorating a classmethod, be sure to use @method_decorator.

Change History (4)

comment:1 Changed 18 months ago by Matt Hegarty

comment:3 Changed 18 months ago by Matt Hegarty

OK, silly me. I should have paid more attention to the message. This fixes it:

@method_decorator(cache_control(max_age=60 * 60 * 24, immutable=True, public=True), name='dispatch')

comment:4 Changed 18 months ago by Matt Hegarty

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top