diff wiki/tests.py @ 629:f4c043cf55ac

Wiki integration. Requests don't always have sessions. In particular this occurs when a request is made without a trailing slash. The Common middleware redirects when this happens, and the middleware process_request() processing stops before a session can get added. So just set an attribute on the request object for each operation. This seemed weird to me at first, but there are plenty of examples of this in the Django code base already.
author Brian Neal <bgneal@gmail.com>
date Tue, 13 Nov 2012 13:50:06 -0600
parents a4300639c6e7
children
line wrap: on
line diff
--- a/wiki/tests.py	Mon Nov 12 16:40:54 2012 -0600
+++ b/wiki/tests.py	Tue Nov 13 13:50:06 2012 -0600
@@ -13,7 +13,7 @@
 
 from core.services import get_redis_connection
 from wiki.middleware import WikiMiddleware
-from wiki.constants import SESSION_SET_FLAG, SESSION_SET_MEMBER
+from wiki.constants import SESSION_SET_MEMBER
 
 
 class MiddleWareTestCase(TestCase):
@@ -28,18 +28,20 @@
     def tearDown(self):
         self.conn.delete(settings.WIKI_REDIS_SET)
 
-    def test_middleware(self):
-
+    def create_request(self):
         request = self.factory.get('/contact/')
         request.session = {}
         request.user = self.user
+        return request
+
+    def test_middleware(self):
+
+        request = self.create_request()
         response = HttpResponse()
 
-        request.session[SESSION_SET_FLAG] = True
+        request.wiki_set_cookie = True
         response = self.mw.process_response(request, response)
 
-        self.assertIsNone(request.session.get('wiki_set_cookie'))
-
         cookie = response.cookies.get(settings.WIKI_COOKIE_NAME)
         cookie_val = ''
         self.assertIsNotNone(cookie)
@@ -74,6 +76,7 @@
 
         # test the destroy session logic
 
+        request = self.create_request()
         request.wiki_delete_cookie = member
         response = self.mw.process_response(request, response)