]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Allow handlers to assign to self.current_user
authorBen Darnell <ben@bendarnell.com>
Mon, 13 May 2013 00:02:54 +0000 (20:02 -0400)
committerBen Darnell <ben@bendarnell.com>
Mon, 13 May 2013 00:02:54 +0000 (20:02 -0400)
tornado/test/web_test.py
tornado/web.py

index 5e813e5d0ab0b320522b28b1395469117e53431c..a1df2eb83f39202c6229a406bb4cadfbb72858ab 100644 (file)
@@ -1278,3 +1278,18 @@ class MultipleExceptionTest(SimpleHandlerTestCase):
         # seen at least three of them by now (the fourth may still be
         # in the queue).
         self.assertGreater(MultipleExceptionTest.Handler.exc_count, 2)
+
+
+class SetCurrentUserTest(SimpleHandlerTestCase):
+    class Handler(RequestHandler):
+        def prepare(self):
+            self.current_user = 'Ben'
+
+        def get(self):
+            self.write('Hello %s' % self.current_user)
+
+    def test_set_current_user(self):
+        # Ensure that current_user can be assigned to normally for apps
+        # that want to forgo the lazy get_current_user property
+        response = self.fetch('/')
+        self.assertEqual(response.body, b'Hello Ben')
index 686d8de39c9ca5c2571ce7cd7659642f38cd8598..bc97766eb96efb26b3ee2796f734cf5caea41edc 100644 (file)
@@ -900,6 +900,10 @@ class RequestHandler(object):
             self._current_user = self.get_current_user()
         return self._current_user
 
+    @current_user.setter
+    def current_user(self, value):
+        self._current_user = value
+
     def get_current_user(self):
         """Override to determine the current user from, e.g., a cookie."""
         return None