如何注册仅在功能测试中可用的视图

时间:2013-04-14 09:30:08

标签: plone

我正在为一个框架化的Plone插件创建功能测试,该插件通过视图(BrowserViews)与其他插件交互。

如何注册仅在功能测试中用于测试目的的视图?我想模拟集成点,看看它是否提供了良好的视图查找和调用。

2 个答案:

答案 0 :(得分:2)

我这样做了以下:

def setUp(self):
        self.app = self.layer['app']
        self.portal = self.layer['portal']

        # Register view directly by pushing it to zope.component multi-adapter registry

        zope.component.provideAdapter(
            # Our class
            factory=TestingRedirectHandler,
            # (context, request) layers for multiadapter lookup
            # We provide None as layers are not used
            adapts=(None, None),
            # All views are registered as IBrowserView interface
            provides=zope.publisher.interfaces.browser.IBrowserView,
            # View name
            name='redirect_handler')

        browser = Browser(self.portal)
        browser.handleErrors = False
        browser.raiseHttpErrors = False
        self.browser = browser

    def tearDown(self):
        """
        """
        # Dynamically unregister a view
        gsm = zope.component.getGlobalSiteManager()
        gsm.unregisterAdapter(factory=TestingRedirectHandler,
                              required=(None, None),
                              provided=zope.publisher.interfaces.browser.IBrowserView,
                              name="redirect_handler")

答案 1 :(得分:0)

如果你有一个测试文件夹,你可以在那里创建一个configure.zcml文件并在那里注册一个视图(python文件应该在那里保持一致性),应该是它。