Broken (Arche-)Type Installation in Tests

Posted on February 23, 2012
Tags:

I’ve recently run into this issue, migrating some of the Plone 3 product code to Plone 4. Installing some of the old types in my tests ended in a

File “/projects/plone3/my.product/my/product/tests/test_users.py”, line 19, in test_mycontent self.portal.invokeFactory(‘GalleryFolder’, ‘spam’, title=‘eggs’) […] File “/home/roman/.buildout/eggs/Products.CMFCore-2.2.4-py2.6.egg/Products/CMFCore/TypesTool.py”, line 311, in constructInstance raise AccessControl_Unauthorized(‘Cannot create %s’ % self.getId()) Unauthorized: Cannot create GalleryFolder

Digging deeper I found out, that all of the product factories were gone. Any debugging finding the cause of this ended up in a nowhere, until I stumbled over some odd behavior. All my imports in the testing.py are sorted, e.g.:

from Products.CMFPlone.tests.utils import MockMailHost from Products.MailHost.interfaces import IMailHost from Products.SiteErrorLog.SiteErrorLog import SiteErrorLog […] import zope.component

What I now found out by accident is, if you move the import of the MockMailHost to the end of the import block, your Archetypes types are installable again:

from Products.MailHost.interfaces import IMailHost from Products.SiteErrorLog.SiteErrorLog import SiteErrorLog […] import zope.component from Products.CMFPlone.tests.utils import MockMailHost

I currently don’t know why, but if anyone had the time to check, I’d be happy to know.