Plone.api's adopt_user in functional tests

I have been using plone.api.env.adopt_user in integration tests to great success. However it does not seem to be working in functional tests where I want to actually load a browser page as some user.

    file_data = 'egg salad sandwich'
    with api.env.adopt_user('siteadmin'): + '/page1')

A debug breakpoint on that content type's view method shows plone.api.user.get_current().getId() to be 'admin'. I don't have this problem with integration tests, just functional. Is there something particular about the functional test layer that would make this not work? I am using standard functional and integration layers and fixtures created through bobtemplate.

1 Like

Of course it is obvious now after I post this. In functional testing we do the authorization in the browser header. My base class's setUp method has already set the header for this but it can be updated

self.browser.addHeader('Authorization', 'Basic siteadmin:12345')

I don't think there is actually a need for adopt_user here we can just change the authorization header to simulate different test users.