How can I set the value for request.authenticated_userid in pyramid framework of python -


i getting error when try set attribute authenticated_userid request parameter. nosetest using mock request , see response.

traceback (most recent call last):   file "/web/core/pulse/wapi/tests/testwapiutilities_integration.py", line 652, in setup     setattr(self.request, 'authenticated_userid', self.data['user'].id) attributeerror: can't set attribute 

code below

@attr(can_split=false) class logsuspiciousrequestandraisehttperror(integrationtestcase):     def setup(self):         super(logsuspiciousrequestandraisehttperror, self).setup()         pyramid.request import request         pyramid.threadlocal import get_current_registry         request = request({             'server_protocol': 'testprotocol',             'server_name': 'test server name',             'server_port': '80',         })         request.context = testcontext()         request.root = request.context         request.subpath = ['path']         request.traversed = ['traversed']         request.view_name = 'test view name'         request.path_info = 'test info'         request.scheme = 'https'         request.host = 'test.com'         request.registry = get_current_registry()         self.request = request         self.data = {}         self.createdefaultdata()         self.request.useraccount = self.data['user'].useraccount      # @unittest.skip('pre-demo skip. need mock useraccountmodel')     @mock.patch('pulse.wapi.wapiutilities.pyramid.threadlocal.get_current_request')     @mock.patch('pulse.wapi.wapiutilities.securitylog')     def testhasrequest_raises400andlogserror(             self, securitylog, get_current_request):         # arrange         get_current_request.return_value = self.request          self.assertraises(exception.httpbadrequest):             pulse.wapi.wapiutilities import logsuspiciousrequestandraisehttperror             logsuspiciousrequestandraisehttperror()             self.asserttrue(securitylog.called)             self.asserttrue(securitylog.return_value.info.called) 

i creating dummy request , adding attributes request.

when method logsuspiciousrequestandraisehttperror() called request parsed method user account.

useraccountid=authenticated_userid(self.request) 

this returns none since request doesn't have attribute self.request.authenticated_userid

please let me know if need additional information.

finally got solution.

i added self.config = testing.setup()

self.config.testing_securitypolicy(     userid=self.data['user'].useraccount.id, permissive=true ) 

added useraccountid mock value testing security policy.

@attr(can_split=false) class logsuspiciousrequestandraisehttperror(integrationtestcase):     def setup(self):         super(logsuspiciousrequestandraisehttperror, self).setup()         pyramid.request import request         pyramid.threadlocal import get_current_registry         self.config = testing.setup()         request = request({             'server_protocol': 'testprotocol',             'server_name': 'test server name',             'server_port': '80',         })         request.context = testcontext()         request.root = request.context         request.subpath = ['path']         request.traversed = ['traversed']         request.view_name = 'test view name'         request.path_info = 'test info'         request.scheme = 'https'         request.host = 'test.com'         request.registry = get_current_registry()         self.request = request         self.data = {}         self.createdefaultdata()         self.request.useraccount = self.data['user'].useraccount      @mock.patch('pulse.wapi.wapiutilities.pyramid.threadlocal.get_current_request')     @mock.patch('pulse.wapi.wapiutilities.securitylog')     def testhasrequest_raises400andlogserror(             self, securitylog, get_current_request):         # arrange         get_current_request.return_value = self.request         self.loggedinuser = self.data['user']         self.config.testing_securitypolicy(             userid=self.data['user'].useraccount.id, permissive=true         )          self.assertraises(exception.httpbadrequest):             pulse.wapi.wapiutilities import logsuspiciousrequestandraisehttperror             logsuspiciousrequestandraisehttperror()             self.asserttrue(securitylog.called)             self.asserttrue(securitylog.return_value.info.called) 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -