My previous post used a wrong constant for logging in as the test user.
I wrote a small TestUtils helper class (I'm still a Plone beginner, so use this
at your own risk.) that appears to log in correctly.
from plone.app.testing import TEST_USER_ID, TEST_USER_NAME, TEST_USER_PASSWORD
from plone.app.testing import setRoles
from plone.testing.z2 import Browser
from Products.CMFCore.utils import getToolByName
class TestUtils:
def __init__(self, context):
self.context = context
self.portal = context.layer['portal']
self.portal_workflow = getToolByName(self.portal, 'portal_workflow')
app = context.layer['app']
self.browser = Browser(app)
self.browser.handleErrors = False
def setManagerRole(self):
setRoles(self.portal, TEST_USER_ID, ('Manager',))
def invokeFactory(self, parent, type, name, title):
parent.invokeFactory(type, name, title=title)
return parent[name]
def setState(self, instance, state):
self.portal_workflow.doActionFor(instance, state)
def logInTestUserThroughForm(self):
self.browser.open(self.portal.absolute_url())
self.browser.getLink('Log in').click()
self.browser.getControl(name='__ac_name').value = TEST_USER_NAME
self.browser.getControl(name='__ac_password').value = TEST_USER_PASSWORD
self.browser.getControl(name='submit').click()
self.assertTrue("You are now logged in" in browser.contents)
def logInTestUser(self):
"""
Uses a HTML header to authorize (taken from the Professional Plone 4
Development book)
"""
self.browser.addHeader('Authorization', 'Basic %s:%s' %
(TEST_USER_NAME,
TEST_USER_PASSWORD,))
def commit(self):
import transaction; transaction.commit()
_______________________________________________
Product-Developers mailing list
[email protected]
https://lists.plone.org/mailman/listinfo/plone-product-developers