web/test/unittest_application.py
changeset 7876 df15d194a134
parent 7791 31bb51ea5485
child 8311 76a44a0d7f4b
--- a/web/test/unittest_application.py	Tue Sep 27 18:46:36 2011 +0200
+++ b/web/test/unittest_application.py	Tue Sep 27 18:47:11 2011 +0200
@@ -31,6 +31,7 @@
 from cubicweb.devtools.fake import FakeRequest
 from cubicweb.web import LogOut, Redirect, INTERNAL_FIELD_VALUE
 from cubicweb.web.views.basecontrollers import ViewController
+from cubicweb.web.application import anonymized_request
 
 class FakeMapping:
     """emulates a mapping module"""
@@ -424,6 +425,18 @@
         self.assertRaises(LogOut, self.app_publish, req, 'logout')
         self.assertEqual(len(self.open_sessions), 0)
 
+    def test_anonymized_request(self):
+        req = self.request()
+        self.assertEqual(req.session.login, self.admlogin)
+        # admin should see anon + admin
+        self.assertEqual(len(list(req.find_entities('CWUser'))), 2)
+        with anonymized_request(req):
+            self.assertEqual(req.session.login, 'anon')
+            # anon should only see anon user
+            self.assertEqual(len(list(req.find_entities('CWUser'))), 1)
+        self.assertEqual(req.session.login, self.admlogin)
+        self.assertEqual(len(list(req.find_entities('CWUser'))), 2)
+
     def test_non_regr_optional_first_var(self):
         req = self.request()
         # expect a rset with None in [0][0]