2

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

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

4

2 回答 2

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")
于 2013-04-14T13:53:07.700 回答
0

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

于 2013-04-14T10:41:42.157 回答