Ticket #11673 (confirmed Bug)
plone.app.testing does not setup browserlayer
Reported by: | ldr | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 4.x |
Component: | General | Version: | 4.1 |
Keywords: | Cc: | optilude, keul, saily, gbastien |
Description
Accessing views registered for a browser layer require that the request is marked with that browser layer. This normally happens on traversal of the site, when the CMFCore before_publishing_traversal hook is called, which is responsible for calling self.setupCurrentSkin(REQUEST) and notify(BeforeTraverseEvent(self, REQUEST)). While plone.app.testing calls setupCurrentSkin, it does not notify the event which triggers the plone.browserlayer subscriber to setup the browser layers.
Where it calls clear clearCurrentSkin ideally it should also tear down the browser layers, but may get away with just setting request._plonebrowserlayer_ = False
Change History
comment:6 Changed 4 years ago by saily
As a workaround you can setup the browserlayer by notifying the BeforeTraverseEvent in your setUp method of your TestCase.
import unittest2 from zope.event import notify from zope.traversing.interfaces import BeforeTraverseEvent class YourTestCase(unittest2.TestCase): ... def setUp(self): self.app = self.layer['app'] self.portal = self.layer['portal'] self.request = self.layer['request'] # setup manually the correct browserlayer, see: # https://dev.plone.org/ticket/11673 notify(BeforeTraverseEvent(self.portal, self.request)) ...