Ticket #9172: django-trunk-remove-csrf-in-test-client.patch

File django-trunk-remove-csrf-in-test-client.patch, 916 bytes (added by Markus Bertheau, 16 years ago)

Remove csrf middleware for tests automatically

  • django/test/client.py

     
    5757
    5858        # Set up middleware if needed. We couldn't do this earlier, because
    5959        # settings weren't available.
     60
     61        # remove csrf middleware because the test client doesn't, and doesn't
     62        # need to, emulate a browser to the extent necessary to pass the csrf
     63        # test.
     64        if 'django.contrib.csrf.middleware.CsrfMiddleware' \
     65                in settings.MIDDLEWARE_CLASSES:
     66            middleware_classes = list(settings.MIDDLEWARE_CLASSES)
     67            middleware_classes.remove('django.contrib.csrf.middleware.CsrfMiddleware')
     68            settings.MIDDLEWARE_CLASSES = tuple(middleware_classes)
     69
    6070        if self._request_middleware is None:
    6171            self.load_middleware()
    6272
Back to Top