如何在测试用例中访问使用特定 [plone.]browserlayer 定义的视图

发布于 2024-10-31 15:59:12 字数 1154 浏览 4 评论 0 原文

我是测试新手,我第一次尝试为我的 Plone 产品创建测试。 我在 Plone 3.3 上。

基本测试套件有效,我可以毫无错误地执行它。 我遵循了此文档: http://plone.org/documentation/kb/testing ...除了我在 Python 类而不是文档测试中编写测试之外。

我的问题是我似乎无法访问我的应用程序中定义的视图(我收到 ComponentLookupError)。

问题似乎出在我的应用程序定义的“浏览器层”上。 当我从configure.zcml 中删除layer="..." 属性时,测试可以毫无问题地访问视图。但是,如果我将其添加回去,则不起作用。 我想这是因为浏览器层接口没有应用于请求。

我发现的对此问题的唯一参考是在 googlesitemap 的测试中: http://dev.plone.org/collective/browser/googlesitemap/googlesitemap.common/trunk/googlesitemap/common/tests?rev=

作者似乎制作了一个自定义的 ZCML 文件对于测试,其中 layer="..." 属性已被删除。 (这可以工作,但必须为测试维护一个单独的 zcml 文件似乎非常糟糕)

在我的测试中,我包含了以下内容(取自 googlesitemap 测试),它通过了:

from jambette.site.interfaces import IJambetteLayer # this is my browserlayer
from plone.browserlayer.utils import registered_layers
self.assertTrue(IJambetteLayer in registered_layers())

所以我认为我的皮肤和 browserlayer 已正确注册。

我需要做什么才能将浏览器层应用于请求?

I'm new to testing and I'm trying to create a test for my Plone product for the first time.
I'm on Plone 3.3.

The basic test suite works, I can execute it without errors.
I followed this documentation : http://plone.org/documentation/kb/testing
...except that I'm writing my tests in Python classes instead of doctests.

My problem is that I cannot seem to access the views defined in my app (I get ComponentLookupError).

The problem seems to be with the "browserlayer" defined by my applications.
When I remove the layer="..." attribute from my configure.zcml, the test can access the views without problem. However, if I add it back, it doesn't work.
I guess that's because de browserlayer interface doesn't get applied to the request.

The only reference to this problem I found is in the tests for googlesitemap : http://dev.plone.org/collective/browser/googlesitemap/googlesitemap.common/trunk/googlesitemap/common/tests?rev=

The author seems to have made a custom ZCML file for the test, in which the layer="..." attribute has been removed. (which would work but it seems very bad having to maintain a separate zcml file for the tests)

In my test, I have included the following (taken from the googlesitemap tests), which passes :

from jambette.site.interfaces import IJambetteLayer # this is my browserlayer
from plone.browserlayer.utils import registered_layers
self.assertTrue(IJambetteLayer in registered_layers())

So I think my skin and browserlayer are registered correctly.

Is there anything I need to do so that the browserlayer will be applied to the request?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沫雨熙 2024-11-07 15:59:12

浏览器层接口只是通过directlyProvides“绘制”到请求上。只需在查看视图之前在测试设置中执行此操作即可:

from zope import interface
from jambette.site.interfaces import IJambetteLayer

...

    directlyProvides(request, IJambetteLayer)

Browser layer interfaces are simply 'painted' onto the request with directlyProvides. Simply do so in your test setup before you look up the view:

from zope import interface
from jambette.site.interfaces import IJambetteLayer

...

    directlyProvides(request, IJambetteLayer)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文