Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #7836 -- Modified strategy used by the test client to check for…

… session functionality so it is useful in environments where the DB-based session backend isn't being used. Thanks trevor for the report.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16386 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 84c71148e37235396436fa4b03de137766a15c02 1 parent 050e119
Ramiro Morales authored June 12, 2011
4  django/test/client.py
@@ -356,7 +356,7 @@ def _session(self):
356 356
         """
357 357
         Obtains the current session variables.
358 358
         """
359  
-        if 'django.contrib.sessions' in settings.INSTALLED_APPS:
  359
+        if 'django.contrib.sessions.middleware.SessionMiddleware' in settings.MIDDLEWARE_CLASSES:
360 360
             engine = import_module(settings.SESSION_ENGINE)
361 361
             cookie = self.cookies.get(settings.SESSION_COOKIE_NAME, None)
362 362
             if cookie:
@@ -504,7 +504,7 @@ def login(self, **credentials):
504 504
         """
505 505
         user = authenticate(**credentials)
506 506
         if user and user.is_active \
507  
-                and 'django.contrib.sessions' in settings.INSTALLED_APPS:
  507
+                and 'django.contrib.sessions.middleware.SessionMiddleware' in settings.MIDDLEWARE_CLASSES:
508 508
             engine = import_module(settings.SESSION_ENGINE)
509 509
 
510 510
             # Create a fake request to store login details.
15  tests/regressiontests/test_client_regress/models.py
@@ -13,7 +13,7 @@
13 13
 import django.template.context
14 14
 from django.test import Client, TestCase
15 15
 from django.test.client import encode_file, RequestFactory
16  
-from django.test.utils import ContextList
  16
+from django.test.utils import ContextList, override_settings
17 17
 
18 18
 
19 19
 class AssertContainsTests(TestCase):
@@ -518,6 +518,19 @@ def test_login(self):
518 518
         self.assertEqual(response.status_code, 200)
519 519
         self.assertEqual(response.context['user'].username, 'testclient')
520 520
 
  521
+
  522
+# Remove the 'session' contrib app from INSTALLED_APPS
  523
+@override_settings(INSTALLED_APPS=tuple(filter(lambda a: a!='django.contrib.sessions', settings.INSTALLED_APPS)))
  524
+class NoSessionsAppInstalled(SessionEngineTests):
  525
+    """#7836 - Test client can exercise sessions even when 'django.contrib.sessions' isn't installed."""
  526
+
  527
+    def test_session(self):
  528
+        # This request sets a session variable.
  529
+        response = self.client.get('/test_client_regress/set_session/')
  530
+        self.assertEqual(response.status_code, 200)
  531
+        self.assertEqual(self.client.session['session_var'], 'YES')
  532
+
  533
+
521 534
 class URLEscapingTests(TestCase):
522 535
     def test_simple_argument_get(self):
523 536
         "Get a view that has a simple string argument"
4  tests/regressiontests/test_client_regress/session.py
@@ -2,7 +2,7 @@
2 2
 
3 3
 class SessionStore(SessionBase):
4 4
     """
5  
-    A simple cookie-based session storage implemenation.
  5
+    A simple cookie-based session storage implementation.
6 6
 
7 7
     The session key is actually the session data, pickled and encoded.
8 8
     This means that saving the session will change the session key.
@@ -27,4 +27,4 @@ def load(self):
27 27
             return self.decode(self.session_key)
28 28
         except:
29 29
             self.modified = True
30  
-            return {}
  30
+            return {}

0 notes on commit 84c7114

Please sign in to comment.
Something went wrong with that request. Please try again.