Ticket #11673 (confirmed Bug)

Opened 5 years ago

Last modified 3 years ago

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:1 Changed 4 years ago by kleist

  • Component changed from Unknown to Infrastructure

comment:2 Changed 4 years ago by davisagli

  • Component changed from Infrastructure to General

comment:3 Changed 4 years ago by kleist

  • Status changed from new to confirmed
  • Version set to 4.1

comment:4 Changed 4 years ago by keul

  • Cc keul added

comment:5 Changed 4 years ago by saily

  • Cc saily added

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))
    ...

comment:7 Changed 3 years ago by gbastien

  • Cc gbastien added

comment:8 Changed 3 years ago by do3cc

I've provided a pull request. I tested it with the currently failing tests in plone.app.contenttypes. The browserlayers are automatically gone between each test.

 https://github.com/plone/plone.app.testing/pull/3

Note: See TracTickets for help on using tickets.