我是测试新手,我第一次尝试为我的 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?
发布评论
评论(1)
浏览器层接口只是通过
directlyProvides
“绘制”到请求上。只需在查看视图之前在测试设置中执行此操作即可:Browser layer interfaces are simply 'painted' onto the request with
directlyProvides
. Simply do so in your test setup before you look up the view: