上下文:在我當前的項目中,我嘗試使用plone.app.testing設置測試環境。 代碼可以在GitHub:https://github.com/collective/collective.rcse如何使用Products.membrane插件設置plone測試
我想添加一些成員的設置,但它會引發以下異常:
Traceback (most recent call last):
File "/Uses/toutpt/myproject/buildout-cache/eggs/zope.testing-3.9.7-py2.7.egg/zope/testing/testrunner/runner.py", line 366, in run_layer
setup_layer(options, layer, setup_layers)
File "/Uses/toutpt/myproject/buildout-cache/eggs/zope.testing-3.9.7-py2.7.egg/zope/testing/testrunner/runner.py", line 628, in setup_layer
setup_layer(options, base, setup_layers)
File "/Uses/toutpt/myproject/buildout-cache/eggs/zope.testing-3.9.7-py2.7.egg/zope/testing/testrunner/runner.py", line 633, in setup_layer
layer.setUp()
File "/Uses/toutpt/myproject/buildout-cache/eggs/plone.app.testing-4.2.2-py2.7.egg/plone/app/testing/helpers.py", line 343, in setUp
self.setUpPloneSite(portal)
File "/Uses/toutpt/myproject/src/collective.rcse/collective/rcse/testing.py", line 71, in setUpPloneSite
self.create_user(portal, "simplemember1")
File "/Uses/toutpt/myproject/src/collective.rcse/collective/rcse/testing.py", line 82, in create_user
regtool.addMember(username, username)
File "<string>", line 10, in addMember
File "/Uses/toutpt/myproject/buildout-cache/eggs/plone.protect-2.0.2-py2.7.egg/plone/protect/utils.py", line 46, in _curried
return callable(*args, **kw)
File "<string>", line 10, in addMember
File "/Uses/toutpt/myproject/buildout-cache/eggs/AccessControl-3.0.8-py2.7-macosx-10.6-x86_64.egg/AccessControl/requestmethod.py", line 70, in _curried
return callable(*args, **kw)
File "/Uses/toutpt/myproject/buildout-cache/eggs/Products.CMFCore-2.2.7-py2.7.egg/Products/CMFCore/RegistrationTool.py", line 160, in addMember
membership.addMember(id, password, roles, domains, properties)
File "/Uses/toutpt/myproject/buildout-cache/eggs/Products.PlonePAS-4.1.1-py2.7.egg/Products/PlonePAS/tools/membership.py", line 136, in addMember
acl_users._doAddUser(id, password, roles, domains)
File "/Uses/toutpt/myproject/buildout-cache/eggs/Products.PlonePAS-4.1.1-py2.7.egg/Products/PlonePAS/pas.py", line 42, in _doAddUser
retval = _old_doAddUser(self, login, password, roles, domains)
File "/Uses/toutpt/myproject/buildout-cache/eggs/Products.PluggableAuthService-1.10.0-py2.7.egg/Products/PluggableAuthService/PluggableAuthService.py", line 1004, in _doAddUser
if useradder.doAddUser(login, password):
File "/Uses/toutpt/myproject/buildout-cache/eggs/Products.membrane-2.1.9-py2.7.egg/Products/membrane/plugins/usermanager.py", line 283, in doAddUser
adder = getCurrentUserAdder(self)
File "/Uses/toutpt/myproject/buildout-cache/eggs/Products.membrane-2.1.9-py2.7.egg/Products/membrane/utils.py", line 46, in getCurrentUserAdder
name, adder = adders.next()
File "/Uses/toutpt/myproject/buildout-cache/eggs/zope.component-3.9.5-py2.7.egg/zope/component/registry.py", line 172, in getUtilitiesFor
for name, utility in self.utilities.lookupAll((), interface):
File "/Uses/toutpt/myproject/buildout-cache/eggs/five.localsitemanager-2.0.5-py2.7.egg/five/localsitemanager/registry.py", line 77, in _uncached_lookupAll
tmp_result[k] = _wrap(v, registry)
File "/Uses/toutpt/myproject/buildout-cache/eggs/five.localsitemanager-2.0.5-py2.7.egg/five/localsitemanager/registry.py", line 143, in _wrap
registry_site = registry_site.__parent__
AttributeError: 'BaseGlobalComponents' object has no attribute '__parent__'
此跟蹤顯示膜被稱爲添加成員,但是當它試圖找到IUserAdder組件,該組件註冊表提高在下面的代碼的異常:
def _wrap(comp, registry):
"""Return an aq wrapped component with the site as the parent but
only if the comp has an aq wrapper to begin with.
"""
# If component is stored as a ComponentPathWrapper, we traverse to
# the component using the stored path:
if isinstance(comp, ComponentPathWrapper):
comp = getSite().unrestrictedTraverse(comp.path)
if IAcquirer.providedBy(comp):
return _rewrap(comp)
else:
return comp
# BBB: The primary reason for doing this sort of wrapping of
# returned utilities is to support CMF tool-like functionality where
# a tool expects its aq_parent to be the portal object. New code
# (ie new utilities) should not rely on this predictability to
# get the portal object and should search out an alternate means
# (possibly retrieve the ISiteRoot utility). Although in most
# cases getting at the portal object shouldn't be the required pattern
# but instead looking up required functionality via other (possibly
# local) components.
if registry.__bases__ and IAcquirer.providedBy(comp):
current_site = getSite()
registry_site = Acquisition.aq_base(registry.__parent__)
if not ISite.providedBy(registry_site):
registry_site = registry_site.__parent__
...
而且在測試過程中,registry_site沒有父。這裏是我嘗試使用PDB:
(Pdb) registry_site
<BaseGlobalComponents test-stack-3>
(Pdb) ISite.providedBy(registry_site)
False
(Pdb) registry
<zope.component.globalregistry.GlobalAdapterRegistry object at 0x105499990>
(Pdb) getSite()
<PloneSite at /plone>
(Pdb) Acquisition.aq_base(registry.__parent__)
<BaseGlobalComponents test-stack-3>
(Pdb) registry.__bases__
(<zope.component.globalregistry.GlobalAdapterRegistry object at 0x1049238d0>,)
(Pdb) registry
<zope.component.globalregistry.GlobalAdapterRegistry object at 0x105499990>
因此,因爲它只發生在測試過程中,這意味着我必須在測試設置中添加一些東西。
您確定這是與膜有關嗎?該錯誤看起來更像是它在testing.py中的相關:this https://github.com/collective/collective.rcse/blob/master/collective/rcse/testing.py#L44 –
我寫這是因爲一些全局請求使用。我推出了一種解決方法,不必這樣做,但問題保持不變。 – toutpt
奇怪。我們有一些靈巧的功能測試,沒有這些問題,但我們只在測試期間創建用戶。 –