web/test/unittest_application.py
changeset 7876 df15d194a134
parent 7791 31bb51ea5485
child 8311 76a44a0d7f4b
equal deleted inserted replaced
7875:65e460690139 7876:df15d194a134
    29 from cubicweb import AuthenticationError, Unauthorized
    29 from cubicweb import AuthenticationError, Unauthorized
    30 from cubicweb.devtools.testlib import CubicWebTC
    30 from cubicweb.devtools.testlib import CubicWebTC
    31 from cubicweb.devtools.fake import FakeRequest
    31 from cubicweb.devtools.fake import FakeRequest
    32 from cubicweb.web import LogOut, Redirect, INTERNAL_FIELD_VALUE
    32 from cubicweb.web import LogOut, Redirect, INTERNAL_FIELD_VALUE
    33 from cubicweb.web.views.basecontrollers import ViewController
    33 from cubicweb.web.views.basecontrollers import ViewController
       
    34 from cubicweb.web.application import anonymized_request
    34 
    35 
    35 class FakeMapping:
    36 class FakeMapping:
    36     """emulates a mapping module"""
    37     """emulates a mapping module"""
    37     def __init__(self):
    38     def __init__(self):
    38         self.ENTITIES_MAP = {}
    39         self.ENTITIES_MAP = {}
   422         req.form['__password'] = self.admpassword
   423         req.form['__password'] = self.admpassword
   423         self.assertAuthSuccess(req, origsession)
   424         self.assertAuthSuccess(req, origsession)
   424         self.assertRaises(LogOut, self.app_publish, req, 'logout')
   425         self.assertRaises(LogOut, self.app_publish, req, 'logout')
   425         self.assertEqual(len(self.open_sessions), 0)
   426         self.assertEqual(len(self.open_sessions), 0)
   426 
   427 
       
   428     def test_anonymized_request(self):
       
   429         req = self.request()
       
   430         self.assertEqual(req.session.login, self.admlogin)
       
   431         # admin should see anon + admin
       
   432         self.assertEqual(len(list(req.find_entities('CWUser'))), 2)
       
   433         with anonymized_request(req):
       
   434             self.assertEqual(req.session.login, 'anon')
       
   435             # anon should only see anon user
       
   436             self.assertEqual(len(list(req.find_entities('CWUser'))), 1)
       
   437         self.assertEqual(req.session.login, self.admlogin)
       
   438         self.assertEqual(len(list(req.find_entities('CWUser'))), 2)
       
   439 
   427     def test_non_regr_optional_first_var(self):
   440     def test_non_regr_optional_first_var(self):
   428         req = self.request()
   441         req = self.request()
   429         # expect a rset with None in [0][0]
   442         # expect a rset with None in [0][0]
   430         req.form['rql'] = 'rql:Any OV1, X WHERE X custom_workflow OV1?'
   443         req.form['rql'] = 'rql:Any OV1, X WHERE X custom_workflow OV1?'
   431         self.app_publish(req)
   444         self.app_publish(req)