How can I set the value for request.authenticated_userid in pyramid framework of python
<p>I am getting an error when I try to set the attribute for authenticated_userid as a request parameter. Its actually a nosetest I am using to mock up the request and see the response.</p>

<pre><code>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></pre>

<p>Code is as below</p>

<pre><code>@attr(can_split=False)
class logSuspiciousRequestAndRaiseHTTPError(IntegrationTestCase):
    def setUp(self):
        super(logSuspiciousRequestAndRaiseHTTPError, self).setUp()
        from pyramid.request import Request
        from 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 to 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

        with self.assertRaises(exception.HTTPBadRequest):
            from pulse.wapi.wapiUtilities import logSuspiciousRequestAndRaiseHTTPError
            logSuspiciousRequestAndRaiseHTTPError()
            self.assertTrue(securityLog.called)
            self.assertTrue(securityLog.return_value.info.called)
</code></pre>

<p>I am creating a dummy request and I am adding attributes to request.</p>

<p>When this method <code>logSuspiciousRequestAndRaiseHTTPError()</code> is called the request is parsed by the method to get user account.</p>

<pre><code>userAccountID=authenticated_userid(self.request)
</code></pre>

<p>This returns <code>None</code> since the request doesn't have an attribute <code>self.request.authenticated_userid</code></p>

<p>Please let me know if you need any additional information.</p>

<p><code>authenticated_userid</code> is reified attribute set by authentication framework.</p>

<p>See <a href="http://docs.pylonsproject.org/projects/pyramid/en/latest/quick_tutorial/authentication.html" rel="nofollow">Logins with authentication for basic information</a>.</p>

<p>Please include more code how you set up your request, as in its current form the question does not have details to give accurate answer.</p>

python pyramid