Ticket #16605: test-client-session-detection.patch

File test-client-session-detection.patch, 1.1 KB (added by btimby, 12 years ago)

Test Client now checks for middleware that DERIVES from SessionMiddleware.

  • django/test/client.py

     
    497497        not available.
    498498        """
    499499        user = authenticate(**credentials)
    500         if user and user.is_active \
    501                 and 'django.contrib.sessions.middleware.SessionMiddleware' in settings.MIDDLEWARE_CLASSES:
     500        sessions_enabled = False
     501        if user and user.is_active:
     502            from django.contrib.sessions.middleware import SessionMiddleware
     503            for middleware in settings.MIDDLEWARE_CLASSES:
     504                try:
     505                    mod, dot, klass_name = middleware.rpartition('.')
     506                    mod = import_module(mod)
     507                    if issubclass(getattr(mod, klass_name, None), SessionMiddleware):
     508                        sessions_enabled = True
     509                        break
     510                except ImportError:
     511                    continue
     512        if sessions_enabled:
    502513            engine = import_module(settings.SESSION_ENGINE)
    503514
    504515            # Create a fake request to store login details.
Back to Top